dictyper

0.1.14 • Public • Published

Small library for creating types map from .json dict files.

Changelog

Status: Alpha

Currently is under hard development. PRs are appreciated!

Install

npm install --save-dev dictyper # or yarn add --dev dictyper  

Usage

Create a dt.js file with the following contents:

const { DictionaryParser } = require('dictyper');
const { join } = require('path');
 
// path to dict file (dict-example.json)
const d = new DictionaryParser(join(__dirname, 'dict-example.json'));
 
// path to save the resulting file with types (i18n.dict.d.ts)
d.generate(join(__dirname, './'));

Run dt.js with node

node dt.js

It creates i18n.dict.d.ts file. Now, you can use our dt function, for example:

<template>
  <h1> {{ translatedValue }} </h1>
</template>
 
<script lang="ts">
import { dt } from 'dictyper/dt';
 
export default {
  computed: {
    translatedValue() {
      return this.$t(dt('path.to.existing.key'));
    }      
  }
}
</script>

Once the file i18n.dict.d.ts is created, your IDE will prompt the current keys from the dictionary and indicate an error if the dialed key does not exist. Or you can type any other function using the generated dtFuncArgiments interface.

vscode

Webstorm

Example

Try dictyper yourself! Check this repo.

TODO

  • 1. Project init
    • 1.1. Init base folder and files structure
    • 1.2. Init git repo
    • 1.3. Create changelog
  • 2. Setup compile process via tsc
    • 2.4 compilation
    • 2.3 bundling to dist folder
  • 3. Write lib
    • 3.1 read from json function
    • 3.2 Tree, Node e.t.c
    • 3.3 Tree from json data
    • 3.4 types generator
    • 3.5 save <dict>.d.ts
  • 4. Setup webpack configuration (node package for generating dict.d.ts file and dt() typed function)
  • 5. npm-package bundling
  • 6. Unit tests
    • 6.1 setup jest env
  • 7. e2e tests (?)
  • 8. documentation

Thanks for help with tree traversal algorithm Ann Romme

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i dictyper

    Weekly Downloads

    7

    Version

    0.1.14

    License

    ISC

    Unpacked Size

    8.92 kB

    Total Files

    10

    Last publish

    Collaborators

    • tardigrada777