Skip to content

hackclub/transcript

parchment

manage your project strings, hackily

how it works

you use a transcript.yml, where you declare key-value yaml pairs of strings. you can use js expressions - as strings are evaled - this means you can use ${templates}, JS expressions, or just getting other strings using t(). then, just call t('key', context) and get your string! context is passed down to eval

quirks:

  • transcript.yml needs to be located in src/lib/transcript.yml (for now)
  • ??? may be buggy - will be rewritten shortly!

In the wild

Examples

Hello World!
# transcript.yml
greeting: Hello, world!
const { transcript } = require('transcript')
transcript('greeting')
// => Hello, world!
Randomness

Just cause you're saying the same thing doesn't mean you need to use the same words every time...

bark:
  - bark
  - bork
  - wh${'o'.repeat(3 + Math.ceil(Math.random()*8))}f
const speak = () => transcript('bark') + '!'

// speak boy!
speak() // => bark!
speak() // => whooof!
speak() // => bork!
// good boy!
Recursion

transcript() is available within itself as this.t() so you can spice up your lines with more random flavor text.

# hackclub/toriel transcript.yml
greeting: oh hello! i have tea and a fresh ${this.t('type-of-pie')} pie cooling off... please come over and have some!

type-of-pie:
  - cinnamon
  - butterscotch
  - cinnamon and butterscotch
  - snail # apparently a favorite of hers in Undertale
const { transcript } = require('@hackclub/transcript')
transcript('greeting')
// => oh hello! i have tea and a fresh butterscotch pie cooling off... please come over and have some!
transcript('greeting')
// => oh hello! i have tea and a fresh snail pie cooling off... please come over and have some!
Nested Values

Values are nested in yaml, so you can group your lines by type.

errors:
    notFound: the dog sniffs around, but doesn't look like it found what it's looking for
    missingPermission: what typa kibble ya try'n ta feed me? you can't do that!
    general: something went wrong!
try {
    // ... some code
} catch(e) {
    let type = 'general'
    if (e instanceof NotFoundError) type = 'notFound'
    if (e instanceof MissingPermError) type = 'missingPermission'

    transcript(`errors.${type}`)
    // this will give different messages, depending on how your code failed!
}

About

Give your bots more flavorful dialogue

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published