Package Exports
- nv-facutil-basic
 
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nv-facutil-basic) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
nv-facutil-basic
- nv-facutil-basic
 
install
- npm install nv-facutil-basic
 
usage
example
const fac_bsc = require("nv-facutil-basic");
> fac_bsc.is_node()
true
>
> var d = {a:{b:{c:200}}}
> fac_bsc.optional_chaining(d,'a','b')
{ c: 200 }
> fac_bsc.optional_chaining(d,'a','b','e','c')
undefined
>
> fac_bsc.nullish(null,200)
200
> fac_bsc.nullish(undefined,200)
200
> fac_bsc.nullish(false,200)
false
> fac_bsc.nullish(true,200)
true
>
class Cls {
    constructor(){
        this.tag="div"
    }
}
function repr(that,stag,etag) {
    return(stag+that.tag+etag)
}
fac_bsc.add_repr(Cls,repr,'<','>')
> var o = new Cls()
undefined
> o
<div>
>
> class SomeCls {}
undefined
> fac_bsc.add_string_tag(SomeCls,that=>'kkk')
undefined
> var o = new SomeCls()
undefined
> o
SomeCls [kkk] {}
>
> fac_bsc.creat_id()
'5055a812-2b24-4c9e-ab11-87088e51203c'
> fac_bsc.get_abbr('5055a812-2b24-4c9e-ab11-87088e51203c')
'5055a812'
>
fac_bsc.creat_reserved(['EPSILON','ε'],['LAMBDA','λ'])
> EPSILON
'ε'
> LAMBDA
'λ'
> Object.getOwnPropertyDescriptors(global).EPSILON
{ value: 'ε', writable: false, enumerable: false, configurable: false }
> Object.getOwnPropertyDescriptors(global).LAMBDA
{ value: 'λ', writable: false, enumerable: false, configurable: false }
>iflet
var a = 3
var x = iflet(
    a<=1,100,
    a<=2,200,
    300
)
>300forof
> var o = {a:100,b:200}
> for(let e of forof(o)) {console.log(e)}
[ 100,'a' ]
[ 200,'b' ]API
fac_bsc.is_node() //if the runtime is nodejs
fac_bsc.add_repr(Cls,repr_func,...other_repr_func_args) //[util.inspect.custom] in nodejs , else .prototype.repr
fac_bsc.add_string_tag(Cls,repr_func,...other_repr_func_args) //get [Symbol.toStringTag]() {}
fac_bsc.optional_chaining(obj,...keys) //same as ?., for api-compatible
fac_bsc.nullish(a,b); // same as ?? ,for api-compatible
fac_bsc.nc(a,b); //same as nullish, for api-compatible
fac_bsc.is_null(o);
fac_bsc.is_undefined(o);
fac_bsc.is_nullish(o); //null or undefined
fac_bsc.is_nothing(o); //Nil None nil nullptr NULL empty, refer to CONSTS
fac_bsc.is_symbol(o)
fac_bsc.is_bool(o)
fac_bsc.is_num(o)
fac_bsc.is_float(o)
fac_bsc.is_int(o)
fac_bsc.is_nan(o)
fac_bsc.is_infinity(o)
fac_bsc.is_abnormal_num(o)
fac_bsc.is_normal_num(o)
fac_bsc.is_str(o)
fac_bsc.is_prim(o)
fac_bsc.is_bigint(o)
fac_bsc.is_ary(o)
fac_bsc.is_u8ary(o)
fac_bsc.is_buf(o) //buffer is same as u8ary
fac_bsc.is_u8cary(o) //clamped uint8-array
fac_bsc.is_u16ary(o)
fac_bsc.is_u32ary(o)
fac_bsc.is_i8ary(o)
fac_bsc.is_i16ary(o)
fac_bsc.is_i32ary(o)
fac_bsc.is_f32ary(o)
fac_bsc.is_f64ary(o)
fac_bsc.is_bu64ary(o)
fac_bsc.is_bi64ary(o)
fac_bsc.is_typed_ary(o)
fac_bsc.is_set(o)
fac_bsc.is_map(o)
fac_bsc.is_wkset(o)
fac_bsc.is_wkmap(o)
fac_bsc.is_wkref(o)
fac_bsc.is_weak(o)
fac_bsc.is_dict(o) //object NOT array|typed-array|weak|set|map|cls|func|promise|proxy| // regex|date|data-view|generator
fac_bsc.is_normal_dict(o) //dict but NOT promise| proxy | generator
fac_bsc.is_promise(o)
fac_bsc.is_proxy(o) //only work in nodejs
fac_bsc.is_sync_generator(o)
fac_bsc.is_async_generator(o)
fac_bsc.is_generator(o)
fac_bsc.is_ppg(o) //promise| proxy | generator
fac_bsc.is_regex(o)
fac_bsc.is_cls_or_func(o)
fac_bsc.is_cls(o)
fac_bsc.is_async_func(o)
fac_bsc.is_sync_gen(o)
fac_bsc.is_async_gen(o)
fac_bsc.is_gen(o) //sync_gen or async_gen
fac_bsc.is_normal_func(o) //func but NOT gen | async_func
fac_bsc.is_lambda(o) //()=>{} or async()=>{}
fac_bsc.is_func(o) //
fac_bsc.is_date(o)
fac_bsc.is_dv(o) //dataview
fac_bsc.is_arybuf(o) //array-buf
fac_bsc.is_enum_iter_leaf(o) //when typed-array |array |map |set: return true if size/length === 0 //when object : return true if Object.keys(o).length === 0 //others return false
fac_bsc.is_falsy(o) // '',0,0n,[],{},and empty Set/Map and empty typed-array
fac_bsc.is_truthy(o)
fac_get_dtype(o) //return a string of data-type //refer to CONSTS DTYPE_NUM
fac_get_dtype_num(o) //return a big-int number of data-type
fac_bsc.iflet(cond,rslt,cond,rslt,....else)
fac_bsc.forof(o) //if o has [Symbol.iterator] return o, //else try for-in and return a generator //for api-compatible and consistency
fac_bsc.creat_reserved(...kvpairs) //creat global reserved variables, similar to usage of undefined
fac_bsc.creat_id() // if nodejs call crypto.randomUUID, else using nanoid //nanoid is slightly faster than uuidv4
fac_bsc.get_abbr(id) // the first-8 of a uuid
fac_bsc.creat_bigint_id() //convert uuid to a bigint
fac_bsc.creat_nodash_id() //remove dash in uuid
fac_bsc.creat_4int_id_ary() //convert uuid to 4-int-array
fac_bsc.SNidPool //a int or bigint ID, //useful when using adj-table as data structure
//similiar with SNidPool,used in fixed-size scenario; //these are used in fixed-size array-pool ,
// useful when using sharedArrayBuffer,otherwise uselessfac_bsc.AidPool //(Array);
fac_bsc.T8AidPool //(Uint8Array);
fac_bsc.T16AidPool //(Uint16Array);
fac_bsc.T32AidPool //(Uint32Array);
fac_bsc.T64AidPool //(BigUint64Array);
fac_bsc.jdcp(jsond) //JSON.parse(JSON.stringify(jsond))
fac_bsc.unescq(s) //JSON.parse('"'+s+'"')
fac_bsc.typof(o,str);
fac_bsc.instof(o,Instance);
fac_bsc.eqany(o,...opts); // opts.includes(o) // this is used to avoid too many === // coz too-many === will make code unreadable, too long
fac_bsc.SimpleStack //Just Array with a lst(top) setter/getter to handle last-element //and generator from-last-to-first
fac_bsc/SimpleMirr
fac_bsc.ary_lst_index(ary) {return(ary.length-1)}
fac_bsc.get_ary_lst(ary) {return(ary[ary.length-1])}
fac_bsc.set_ary_lst(ary,v) {ary[ary.length-1] = v}
fac_bsc.ary_foreach_brk(arr,f,brkf=(r,i)=>false)
fac_bsc.ary_foreach_skip(arr,f,skipf=(r,i)=>false)
CONSTS
    > fac_bsc
    {
      ////the below is just for api-compatible when migrating some code from other coding language  
      
      Nil: [class Nil],
      nfunc: [Function: nfunc],
      None: None,
      nil: [Object: null prototype] {},
      nullptr: [Object: null prototype] {},
      NULL: [Object: null prototype] {},
      
      //// the 4 global symbol to avoid conflicting with undefined , just a semantic-undefined
      empty: Symbol(empty),
      unknown: Symbol(unknown),
      impossible: Symbol(impossible),
      maybe: Symbol(maybe),
      any:   Symbol(any),
      ////to avoid conflicting with null, just a semantic-null-sign
      root: Symbol(root)
      //// for add_repr or add_string_tag
      NUL: '\x00',
      NBSP: ' ',
      LS: '�',
      PS: '�',
      ZWNJ: '',
      ZWJ: '',
      BOM: '',
    }
    >
    STATE_LABEL_DICT: {
      init: Symbol(init),
      ready: Symbol(ready),
      waiting: Symbol(waiting),
      executing: Symbol(executing),
      pending:   Symbol(pending),
      paused:    Symbol(paused),
      skipped:   Symbol(skipped),
      stopped:   Symbol(stopped),
      finished: Symbol(finished),
      resolved: Symbol(resolved),
      rejected: Symbol(rejected)
      eof: Symbol(eof)
    },
    const DTYPE_NUM = {
        'undefined':                                                0b1n,
        'null':                                                    0b10n,
        'symbol':                                                 0b100n,
        'bool':                                                  0b1000n,
        'int':                                                  0b10000n,
        'float':                                               0b100000n,
        'nan':                                                0b1000000n,
        'infinity':                                          0b10000000n,
        'str':                                              0b100000000n,
        'bigint':                                          0b1000000000n,
        'u8ary':                                          0b10000000000n,
        'u8cary':                                        0b100000000000n,
        'u16ary':                                       0b1000000000000n,
        'u32ary':                                      0b10000000000000n,
        'i8ary':                                      0b100000000000000n,
        'i16ary':                                    0b1000000000000000n,
        'i32ary':                                   0b10000000000000000n,
        'f32ary':                                  0b100000000000000000n,
        'f64ary':                                 0b1000000000000000000n,
        'bu64ary':                               0b10000000000000000000n,
        'bi64ary':                              0b100000000000000000000n,
        'ary':                                 0b1000000000000000000000n,
        'set':                                0b10000000000000000000000n,
        'map':                               0b100000000000000000000000n,
        'wkset':                            0b1000000000000000000000000n,
        'wkmap':                           0b10000000000000000000000000n,
        'wkref':                          0b100000000000000000000000000n,
        'regex':                         0b1000000000000000000000000000n,
        'date':                         0b10000000000000000000000000000n,
        'dv':                          0b100000000000000000000000000000n,
        'arybuf':                     0b1000000000000000000000000000000n,
        'sarybuf':                   0b10000000000000000000000000000000n,
        'promise':                  0b100000000000000000000000000000000n,
        'proxy':                   0b1000000000000000000000000000000000n,
        'sync_generator':         0b10000000000000000000000000000000000n,
        'async_generator':       0b100000000000000000000000000000000000n,
        'normal_dict':          0b1000000000000000000000000000000000000n,
        'cls':                 0b10000000000000000000000000000000000000n,
        'sync_gen':           0b100000000000000000000000000000000000000n,
        'async_gen':         0b1000000000000000000000000000000000000000n,
        'async_func':       0b10000000000000000000000000000000000000000n,
        'normal_func':     0b100000000000000000000000000000000000000000n,
    }
    STYPE_DICT: { 
        root: -1, 
        ele: 0,     //element of array
        prop: 1,    //prop of dict
        stele: 2,   //element of set
        mpk: 3,     //key of mp-element
        mpv: 4,     //value of mp-element
        leaf: 5 
    },LICENSE
- ISC