nv-facutil-cfg

nv-facutil-cfg =============== - nv-facutil-cfg is a very simple util to let you manual-create a big default-dict only-with-key

Usage no npm install needed!

<script type="module">
  import nvFacutilCfg from 'https://cdn.skypack.dev/nv-facutil-cfg';
</script>

README

nv-facutil-cfg

  • nv-facutil-cfg is a very simple util to let you manual-create a big default-dict only-with-key
  • it make a json can save both relation-structure and data

install

  • npm install nv-facutil-cfg

usage

example

const {Cfg} = require("nv-facutil-cfg")

var cfg = new Cfg()

//no need to use =
//just $.x.y.z.u......

cfg.$.task_root.task_a.task_d.task_g.task_i
cfg.$.task_root.task_a.task_e
cfg.$.task_root.task_b.task_f.task_h
cfg.$.task_root.task_c

/*
> cfg
> cfg
{
  relation: { task_root: { task_a: [Object], task_b: [Object], task_c: {} } },
  data: {
    task_root: null,
    'task_root.task_a': null,
    'task_root.task_a.task_d': null,
    'task_root.task_a.task_d.task_g': null,
    'task_root.task_a.task_d.task_g.task_i': null,
    'task_root.task_a.task_e': null,
    'task_root.task_b': null,
    'task_root.task_b.task_f': null,
    'task_root.task_b.task_f.task_h': null,
    'task_root.task_c': null
  }
}
>

*/
var relation = cfg.relation();
/*
{
    "task_root": {
        "task_a": {
            "task_d": {
                "task_g": {
                    "task_i": {}
                }
            },
            "task_e": {}
        },
        "task_b": {
            "task_f": {
                "task_h": {}
            }
        },
        "task_c": {}
    }
}
*/

var data = cfg.data();
/*
{
  task_root: null,
  'task_root.task_a': null,
  'task_root.task_a.task_d': null,
  'task_root.task_a.task_d.task_g': null,
  'task_root.task_a.task_d.task_g.task_i': null,
  'task_root.task_a.task_e': null,
  'task_root.task_b': null,
  'task_root.task_b.task_f': null,
  'task_root.task_b.task_f.task_h': null,
  'task_root.task_c': null
}

*/

set data

cfg.$.task_root = function root(){}
cfg.$.task_root.task_a = function a() {}
cfg.$.task_root.task_b.task_f.task_h = function h() {}

> cfg
{
  relation: { task_root: { task_a: [Object], task_b: [Object], task_c: {} } },
  data: {
    task_root: [Function: root],
    'task_root.task_a': [Function: a],
    'task_root.task_a.task_d': null,
    'task_root.task_a.task_d.task_g': null,
    'task_root.task_a.task_d.task_g.task_i': null,
    'task_root.task_a.task_e': null,
    'task_root.task_b': null,
    'task_root.task_b.task_f': null,
    'task_root.task_b.task_f.task_h': [Function: h],
    'task_root.task_c': null
  }
}
>

chain

    > cfg.task_root.task_a
    {
      relation: { task_d: { task_g: [Object] }, task_e: {} },
      data: {
        task_d: null,
        'task_d.task_g': null,
        'task_d.task_g.task_i': null,
        task_e: null
      }
    }
    > cfg.task_root.task_a.task_d
    {
      relation: { task_g: { task_i: {} } },
      data: { task_g: null, 'task_g.task_i': null }
    }
    > cfg.task_root.task_a.task_d.task_g
    { relation: { task_i: {} }, data: { task_i: null } }
    >

ADVANCED

### tree
> var tree = cfg.tree()

> tree.$sdfs_repr(r=>"   ".repeat(r.$depth())+r.key+' : '+r.val.name)
   task_root : task_root
      task_a : task_a
         task_d : task_d
            task_g : task_g
               task_i : task_i
         task_e : task_e
      task_b : task_b
         task_f : task_f
            task_h : task_h
      task_c : task_c
undefined
>

###sdfs  this is dfs sequence of nodes
> cfg.sdfs()
[
  _Node { type: 'dict', key: 'task_root', val: [Function: task_root] },
  _Node { type: 'dict', key: 'task_a', val: [Function: task_a] },
  _Node { type: 'dict', key: 'task_d', val: [Function: task_d] },
  _Node { type: 'dict', key: 'task_g', val: [Function: task_g] },
  _Node { type: 'dict', key: 'task_i', val: [Function: task_i] },
  _Node { type: 'dict', key: 'task_e', val: [Function: task_e] },
  _Node { type: 'dict', key: 'task_b', val: [Function: task_b] },
  _Node { type: 'dict', key: 'task_f', val: [Function: task_f] },
  _Node { type: 'dict', key: 'task_h', val: [Function: task_h] },
  _Node { type: 'dict', key: 'task_c', val: [Function: task_c] }
]
>


### load_to_sdfs
> load_to_sdfs(cfg.json())
[
  _Node { type: 'dict', key: 'task_root', val: [Function: task_root] },
  _Node { type: 'dict', key: 'task_a', val: [Function: task_a] },
  _Node { type: 'dict', key: 'task_d', val: [Function: task_d] },
  _Node { type: 'dict', key: 'task_g', val: [Function: task_g] },
  _Node { type: 'dict', key: 'task_i', val: [Function: task_i] },
  _Node { type: 'dict', key: 'task_e', val: [Function: task_e] },
  _Node { type: 'dict', key: 'task_b', val: [Function: task_b] },
  _Node { type: 'dict', key: 'task_f', val: [Function: task_f] },
  _Node { type: 'dict', key: 'task_h', val: [Function: task_h] },
  _Node { type: 'dict', key: 'task_c', val: [Function: task_c] }
]
>

###load

> var cfg2 = load(cfg.json())
undefined
> cfg2
{
  relation: { task_root: { task_a: [Object], task_b: [Object], task_c: {} } },
  data: {
    task_root: [Function: task_root],
    'task_root.task_a': [Function: task_a],
    'task_root.task_a.task_d': [Function: task_d],
    'task_root.task_a.task_d.task_g': [Function: task_g],
    'task_root.task_a.task_d.task_g.task_i': [Function: task_i],
    'task_root.task_a.task_e': [Function: task_e],
    'task_root.task_b': [Function: task_b],
    'task_root.task_b.task_f': [Function: task_f],
    'task_root.task_b.task_f.task_h': [Function: task_h],
    'task_root.task_c': [Function: task_c]
  }
}
>

APIS

  • load(json-like)
  • load_to_sdfs(json-like)

LICENSE

  • ISC