nv-cli-abject
- nv-cli-abject
- cli tool, generate a special-class for small-array of fixed-size AND named-index
install
- npm install nv-cli-abject -g
usage
Usage: nv_abject [options]
Options:
-c, --clsname clsname
-p, --prop_names property names splited by spaces
-h, --help usage
example
nv_abject -c 'Cls' -p id name value ___local___
class Cls {
#values = [undefined,undefined,undefined,undefined]
////
i2n(i) {return(Cls.cnl[i])}
n2i(n) {return(Cls.cnl.indexOf(n))}
////
get indexes_() {return(Cls.cnl.map((r,i)=>i))}
get keys_() {return(Cls.cnl.slice(0))}
get values_() {return(this.#values.slice(0))}
////
get oentries_() {return(Cls.cnl.map((k,i)=>[k,this.#values[i]]))}
get dict_() {return(Object.fromEntries(this.oentries_))}
get aentries_() {return(Cls.cnl.map((k,i)=>[i,this.#values[i]]))}
get oary_() {return(Object.fromEntries(this.aentries_))}
get entries_() {return(Cls.cnl.map((k,i)=>[i,k,this.#values[i]]))}
////
* iv_iter() {
for(let i=0;i<Cls.cnl.length;i++) {
yield([i,this.#values[i]])
}
}
* kv_iter() {
for(let i=0;i<Cls.cnl.length;i++) {
yield([Cls.cnl[i],this.#values[i]])
}
}
////
[Symbol.iterator]() {
let _gen = function *() {
for(let i=0;i<Cls.cnl.length;i++) {
yield([this.#values[i],Cls.cnl[i],i])
}
}
return(_gen())
}
////
get id() {return(this.#values[0])}
set id(v) {this.#values[0]=v}
get [0]() {return(this.#values[0])}
set [0](v) {this.#values[0]=v}
get name() {return(this.#values[1])}
set name(v) {this.#values[1]=v}
get [1]() {return(this.#values[1])}
set [1](v) {this.#values[1]=v}
get value() {return(this.#values[2])}
set value(v) {this.#values[2]=v}
get [2]() {return(this.#values[2])}
set [2](v) {this.#values[2]=v}
get ___local___() {return(this.#values[3])}
set ___local___(v) {this.#values[3]=v}
get [3]() {return(this.#values[3])}
set [3](v) {this.#values[3]=v}
////
}
Cls.cnl = ['id','name','value','___local___']
LICENSE