1.0.12 • Published 3 years ago

nv-cli-cls v1.0.12

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

nv-cli-cls

  • nv-cli-cls
  • cli tool, quickly generate class template

install

  • npm install nv-cli-cls -g

usage

extends

APPS# nv_cls_ext -h
Usage: nv_cls_ext [options]
Options:
    -n, --name          root class name,default 'Cls'
    -i, --input         input json cfg file,default stdin
    -o, --output        output js file,default stdout
    -h, --help          usage

APPS#


APPS# nv_cls_ext -n Root

//----paste a dict here

{
    A:{
        C:{},
        "@xyz":{}
    },
    B:{
        C:{},
        D:{E:null}
    }
}

//----press ctrl+D

const INVALID_NAME = {
    "_64_120_121_122": "@xyz"
}

class Root {}

class A extends Root {}

class C extends A {}

class _64_120_121_122 extends A {}

class B extends Root {}

class C$1_0 extends B {}

class D extends B {}

class E extends D {}


APPS#

template

APPS# nv_cls_tem -h
Usage: nv_cls_tem [options]
Options:
    -n, --name            class name default 'Cls'
    -p, --property        property,getter,setter
        -m, --method          methods
        -h, --help            usage
    
    ---------------------
    
        begin with # : private,                           such as #priv0 ;
        @cls         : static,                            such as prop@cls, #prop@cls;
        @sym         : treat as symbol,                   such as prop@sym ;
        @com         : computed, will be enclosed by [ ], such as Symbol.toStringTag@com;
        @get         : getter ,                           such as prop_@get;
        @set         : setter ,                           such as prop_@set;
    
    APPS#

1

nv_cls_tem -n MyCls -p "#priv0" pub0 P@cls -m "#pf0" f0 F@cls


class MyCls {

    //static public property:
    static P = undefined;

    //static public method:
    static F(/*...args*/) {/*...*/}

    //instance private prop:
    #priv0 = undefined;

    constructor(/*...args*/) {

        //instance public property:
        this.pub0 = undefined;


    }

    //instance private method:
    #pf0(/*...args*/) {/*...*/}

    //instance public method:
    f0(/*...args*/) {/*...*/};


}

2

nv_cls_tem -n MyCls -p length@get max_length@set@get  -m x y

class MyCls {

    //instance private prop:
    #length = undefined;
    #max_length = undefined;


    constructor(/*...args*/) {

    }


    //instance public getter:
    get length (){return(this.#length)}
    get max_length (){return(this.#max_length)}


    //instance public setter:
    set max_length (v){this.#max_length=v};


    //instance public method:
    x(/*...args*/) {/*...*/};
    y(/*...args*/) {/*...*/};


}

3

nv_cls_tem -n MyCls -p sym_get@sym@get P@cls -m func0  func1


//symbol-dict:
const SYM_DICT = {
    "sym_get":Symbol("sym_get")
}



class MyCls {

    //static public property:
    static P = undefined;


    //instance private prop:
    #sym_get = undefined;


    constructor(/*...args*/) {

    }


    //instance public getter:
    get [MyCls.SYM_DICT["sym_get"]]() {return(this.#sym_get)}


    //instance public method:
    func0(/*...args*/) {/*...*/};
    func1(/*...args*/) {/*...*/};


}


//add SYM_DICT to class:
MyCls.SYM_DICT=SYM_DICT;



### 4
nv_cls_tem -n MyCls -p "#priv0" "#priv1" pub0 pub1 -m "#pf0" "#pf1" f0 f1


class MyCls {

    //instance private prop:
    #priv0 = undefined;
    #priv1 = undefined;


    constructor(/*...args*/) {

        //instance public property:
        this.pub0 = undefined;
        this.pub1 = undefined;


    }


    //instance private method:
    #pf0(/*...args*/) {/*...*/}
    #pf1(/*...args*/) {/*...*/}


    //instance public method:
    f0(/*...args*/) {/*...*/};
    f1(/*...args*/) {/*...*/};


}

4

nv_cls_tem -n MyCls -p  pub0@com pub1@sym  -m f0@com f1@com

//symbol-dict:
const SYM_DICT = {
    "pub1":Symbol("pub1")
}



class MyCls {

    constructor(/*...args*/) {

        //instance public property:
        this[pub0] = undefined;
        this[MyCls.SYM_DICT["pub1"]] = undefined;


    }


    //instance public method:
    [f0](/*...args*/) {/*...*/};
    [f1](/*...args*/) {/*...*/};


}


//add SYM_DICT to class:
MyCls.SYM_DICT=SYM_DICT;

LICENSE

  • ISC