dictyper
v0.1.14
Published
Small library for creating types definitions from .json dictionaries.
Downloads
7
Maintainers
Readme
Small library for creating types map from .json dict files.
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
- [x] 1. Project init
- [x] 1.1. Init base folder and files structure
- [x] 1.2. Init git repo
- [x] 1.3. Create changelog
- [x] 2. Setup compile process via tsc
- [x] 2.4 compilation
- [x] 2.3 bundling to
dist
folder
- [x] 3. Write lib
- [x] 3.1 read from json function
- [x] 3.2 Tree, Node e.t.c
- [x] 3.3 Tree from json data
- [x] 3.4 types generator
- [x] 3.5 save <dict>.d.ts
- [x] 4. Setup webpack configuration (node package for generating dict.d.ts file and dt() typed function)
- [x] 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