JSPM

  • Created
  • Published
  • Downloads 20
  • Score
    100M100P100Q8647F
  • License ISC

nv-facutil-basic =============== - nv-facutil-basic

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
)

>300

forof

> var o = {a:100,b:200}
> for(let e of forof(o)) {console.log(e)}
[ 'a', 100 ]
[ 'b', 200 ]

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_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_dict(o)

  • fac_bsc.is_promise(o)

  • fac_bsc.is_proxy(o) //only work in nodejs, else return unknown

  • fac_bsc.is_sync_generator(o)

  • fac_bsc.is_async_generator(o)

  • fac_bsc.is_generator(o)

  • 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)

  • fac_bsc.is_func(o)

  • fac_bsc.is_date(o)

  • fac_bsc.is_enum_iter_leaf(o) //when array |map |set: return true if size/length === 0 //when object : return true if Object.keys(o).length === 0 //others return false

  • 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 uuid.v4

  • fac_bsc.get_abbr(id) // the first-8 of a uuid

  • fac_bsc.creat_bigint_id()

  • fac_bsc.creat_nodash_id()

  • fac_bsc.creat_4int_id_ary()

  • fac_bsc.NidPool

  • fac_bsc.jdcp(jsond) //JSON.parse(JSON.stringify(jsond))

  • fac_bsc.SimpleStack //Just Array with a lst(top) setter/getter to handle last-element //and generator from-last-to-first

  • 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}

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),

      //// 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)
    },
    
    
    DATA_TYPE_DICT: {
      undefined: Symbol(undefined),
      null: Symbol(null),
      boolean: Symbol(boolean),
      symbol: Symbol(symbol),
      number: Symbol(number),
      bigint: Symbol(bigint),
      string: Symbol(string),
      date: Symbol(data),
      regexp: Symbol(regexp),
      array: Symbol(array),
      set: Symbol(set),
      map: Symbol(map),
      dict: Symbol(dict),
      wkset: Symbol(wkset),
      wkmap: Symbol(wkmap),
      wkref: Symbol(wkref),
      class: Symbol(class),
      function: Symbol(function)
    }

LICENSE

  • ISC