0.1.14 • Published 4 years ago

dictyper v0.1.14

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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
    1. Setup compile process via tsc
    • 2.4 compilation
    • 2.3 bundling to dist folder
    1. 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
    1. Setup webpack configuration (node package for generating dict.d.ts file and dt() typed function)
    1. npm-package bundling
    1. Unit tests
    • 6.1 setup jest env
    1. e2e tests (?)
    1. documentation

Thanks for help with tree traversal algorithm Ann Romme

0.1.14

4 years ago

0.1.13

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago