0.2.0 • Published 2 years ago

typed-t v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

typed-t

generate typescript declarations from json translation files

Currently supports:

install

npm i typed-t -D

use

// generate-decl.ts
import { generateTypes, Options, DialectOptions } from 'typed-t';

const dialectOpts: DialectOptions = {
  name: 'polyglot',

  /* Custom prefix for interpolations */
  // prefix: '{'

  /* Custom suffix for interpolations */
  // suffix: '}'
};
const options: Options = {
  /* Single json file or directory containing t9n files */
  entry: __dirname + '/locales',

  /* Specify target dialect and options */
  dialect: dialectOpts,

  /* Custom directory to put declaration files in (Default: same as input dir) */
  // outDir: __dirname + '/locale-declarations

  /* Custom filter to include only specific files */
  // include: (name: string, content: Buffer) => true

  /* Consider files in sub-folders? (Default: true) */
  // recursive: false

  /* Custom file system compatible with node:fs/promises */
  // fs: myCustomFileSystem

  /* Custom node:path implementation */
  // path: myCustomPath
};

generateTypes(options)
  .then(() => {
    console.log('DONE');
  })
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });

then run

node -r esbuild-register generate-decl.ts

How you incorporate the types in your app is highly dependant on your setup so this tool can not help you with that, sorry.