@hackclub/transcript
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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 evaled - 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

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!
}

Readme

Keywords

none

Package Sidebar

Install

npm i @hackclub/transcript

Weekly Downloads

10

Version

0.1.0

License

none

Unpacked Size

11.2 kB

Total Files

6

Last publish

Collaborators

  • recursiveforte
  • merlin04
  • josias_aurel_wing
  • jianmin-chen
  • archmaster
  • cfanoulis
  • lachlanjc
  • maxwofford
  • matthewstanciu
  • uanirudhx
  • sampoder