nv-facutil-alias
v0.0.2
Published
nv-facutil-alias ======================== - nv-facutil-alias is a simple util for multi-key dict - simplified version of nv-facutil-multi-ey
Downloads
5
Readme
nv-facutil-alias
- nv-facutil-alias is a simple util for multi-key dict
- simplified version of nv-facutil-multi-ey
install
- npm install nv-facutil-alias
usage
const {Alias,AlreadyExistError,NotExistError,hole,noexist} = require("nv-facutil-alias");
var alias = new Alias(cfg);
example
new
var cfg = {
alias: {
key0:["k00","k01"],
key1:["k10","k11"],
},
defaults : {
key0:200,
}
}
var alias = new Alias(cfg);
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(3) { 'key1', 'k10', 'k11' } => Symbol(hole)
}
>
get
> alias.get('k00')
200
> alias.get('k02')
Symbol(noexist)
> alias.get('key0')
200
>
set
> alias.set("k10",9999999)
true
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(3) { 'key1', 'k10', 'k11' } => 9999999
}
> alias.set("k",77777)
false
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(3) { 'key1', 'k10', 'k11' } => 9999999
}
>
add_alias
> alias.add_alias('k10',['k@','k$','k'])
[ 'k@', 'k$', 'k' ]
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(6) { 'key1', 'k10', 'k11', 'k@', 'k$', 'k' } => 9999999
}
>
> alias.set("k",77777)
true
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(6) { 'key1', 'k10', 'k11', 'k@', 'k$', 'k' } => 77777
}
>
add
> alias.add("name",["id","n"])
[ 'name', 'id', 'n' ]
> alias
Alias(3) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(6) { 'key1', 'k10', 'k11', 'k@', 'k$', 'k' } => 77777,
Set(3) { 'name', 'id', 'n' } => Symbol(hole)
}
>
> alias.set('id',"0xabcdef")
true
> alias
Alias(3) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(6) { 'key1', 'k10', 'k11', 'k@', 'k$', 'k' } => 77777,
Set(3) { 'name', 'id', 'n' } => '0xabcdef'
}
>
del_alias
> alias.del_alias('id',['id','name'])
[ 'id', 'name' ]
> alias
Alias(3) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(6) { 'key1', 'k10', 'k11', 'k@', 'k$', 'k' } => 77777,
Set(1) { 'n' } => '0xabcdef'
}
>
delete
> alias.delete('k10')
true
> alias
Alias(2) [Map] {
Set(3) { 'key0', 'k00', 'k01' } => 200,
Set(1) { 'n' } => '0xabcdef'
}
>
METHODS
alias.get(k)
alias.set(k,value)
alias.add(key,aliases=[])
alias.del(k)
alias.add_alias(k,aliases)
alias.del_alias(k,aliases)
alias.alias_
alias.defaults_
LICENSE
- ISC