transcript
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 eval
ed - this means you can use ${templates}
, JS expressions, or just getting other strings using tthis.recite()
.
quirks:
- ??? may be buggy - will be rewritten shortly!
In the wild
-
hackclub/toriel
transcript.yml
-
hackclub/slash-z
transcript.yml
-
hackclub/orpheus-bot
transcript.yml
-
hackclub/youtube-dl-bot
transcript.yml
-
hackclub/scrappy
transcript.yml
-
hackclub/application-viewer
transcript.yml
-
maxwofford/mail
transcript.yml
Examples
Hello World!
# transcript.yml
greeting: Hello, world!
const { TranscriptProvider } = require('@hackclub/transcript');
const transcript = new TranscriptProvider('./src/transcript.yml');
transcript.recite('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.recite('bark') + '!';
// speak boy!
speak(); // => bark!
speak(); // => whooof!
speak(); // => bork!
// good boy!
Recursion
recite()
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.recite('greeting');
// => oh hello! i have tea and a fresh butterscotch pie cooling off... please come over and have some!
transcript.recite('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.recite(`errors.${type}`);
// this will give different messages, depending on how your code failed!
}