0.0.1 • Published 2 years ago
nv-facutil-simple-translate v0.0.1
nv-facutil-simple-translate
- nv-facutil-simple-translate simple translate tools
- for small table whose every column-elements are unique
- such as 1000 - 5000 rows ,NO need to use database
install
- npm install nv-facutil-simple-translate
usage
const {creat,load_from_json} = require("nv-facutil-simple-translate")
example
creat
var cnl = [ 'en', 'ch', 'es' ]
var t = creat(cnl)
var r0 = ['I','我','Yo']
var r1 = ['you',' 你','Tú']
var r2 = ['he','他','Él']
t.add(r0)
t.add(r1)
t.add(r2)
getter
/*
> t.col_en
[ 'I', 'you', 'he' ]
> t.col_ch
[ '我', ' 你', '他' ]
> t.col_es
[ 'Yo', 'Tú', 'Él' ]
>
*/
/*
> t.dict_
t.dict_ch_to_en t.dict_ch_to_es t.dict_en_to_ch t.dict_en_to_es t.dict_es_to_ch t.dict_es_to_en
> t.dict_ch_to_en
{ '我': 'I', ' 你': 'you', '他': 'he' }
> t.dict_ch_to_es
{ '我': 'Yo', ' 你': 'Tú', '他': 'Él' }
> t.dict_en_to_ch
{ I: '我', you: ' 你', he: '他' }
> t.dict_en_to_es
{ I: 'Yo', you: 'Tú', he: 'Él' }
> t.dict_es_to_ch
{ Yo: '我', 'Tú': ' 你', 'Él': '他' }
> t.dict_es_to_en
{ Yo: 'I', 'Tú': 'you', 'Él': 'he' }
> t.map_ch_to_en
Map(3) { '我' => 'I', ' 你' => 'you', '他' => 'he' }
>
*/
get AND search
/*
> t.get('我')
{ en: 'I', ch: '我', es: 'Yo' }
>
> t.slct(d=>d.en==='you')
[ { en: 'you', ch: ' 你', es: 'Tú' } ]
>
*/
add AND delete
/*
t.add({en:'she',ch:'她',es:'Ella'})
> t.map_ch_to_en
Map(4) { '我' => 'I', ' 你' => 'you', '他' => 'he', '她' => 'she' }
>
> t.del('她')
true
> t.dict_ch_to_en
{ '我': 'I', ' 你': 'you', '他': 'he' }
>
*/
dump
/*
> j = t.dump()
{
cnl: [ 'en', 'ch', 'es' ],
tbl: [ [ 'I', '我', 'Yo' ], [ 'you', ' 你', 'Tú' ], [ 'he', '他', 'Él' ] ]
}
>
> var t2 = load_from_json(j)
> t2
_T {
'#cnl': [ 'en', 'ch', 'es' ],
'#tbl': [ [ 'I', '我', 'Yo' ], [ 'you', ' 你', 'Tú' ], [ 'he', '他', 'Él' ] ]
}
>
*/
METHODS
t.add t.del t.dump
t.get t.get_all t.slct
getter
t.col_[xxx], t.col_[yyy] ....
t.dict_[xxx]_to_[yyy] , t.dict_[yyy]_to_[xxx]...
t.map_[xxx]_to_[yyy] , t.map_[yyy]_to_[xxx]...
API
- creat(cnl:Array,tbl:Array)
- load_from_json({cnl:Array,tbl:Array})
LICENSE
- ISC
0.0.1
2 years ago