# nv-data-tree-csp-jconvert

> nv-data-tree-csp-jconvert ================= - nv-data-tree-csp-jconvert - convert serveral speical json-format(used in nvlang) to a tree

Latest version **1.0.8** (published 2022-01-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install nv-data-tree-csp-jconvert
pnpm add nv-data-tree-csp-jconvert
yarn add nv-data-tree-csp-jconvert
bun add nv-data-tree-csp-jconvert
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2022-01-21 |
| First published | 2021-10-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 42.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ihgazni2 |

## Links

- npm: https://www.npmjs.com/package/nv-data-tree-csp-jconvert
- npm.io page: https://npm.io/package/nv-data-tree-csp-jconvert

## Dependencies (4)

- [nv-facutil-basic](https://npm.io/package/nv-facutil-basic.md) ^1.0.88
- [nv-data-tree-csp-node](https://npm.io/package/nv-data-tree-csp-node.md) ^1.0.16
- [nv-array-pop-with-value](https://npm.io/package/nv-array-pop-with-value.md) ^1.0.2
- [nv-data-tree-csp-forest](https://npm.io/package/nv-data-tree-csp-forest.md) ^1.0.21

## Recent versions

- 1.0.8 (latest) — 2022-01-21
- 1.0.5 — 2021-12-30
- 1.0.4 — 2021-11-27
- 1.0.3 — 2021-11-25
- 1.0.2 — 2021-11-25
- 1.0.1 — 2021-10-05

## README

nv-data-tree-csp-jconvert
=================
- nv-data-tree-csp-jconvert
- convert serveral speical json-format(used in nvlang) to a tree


install
=======
- npm install nv-data-tree-csp-jconvert

usage
=====

sexpr
------
- shape S =  [tag:String,attrib:Object,child:Array<S>]

###

    const {
        dfs_eng,
        dfs_sexpr,
    }  = require("nv-data-tree-csp-jconvert")


    //type S [tag:String,attrib:Object,child:Array<S>]

    var S0 = [
        'html',{}, [
            [
                'head',{}, [
                     ['meta', {name:'viewport'},[]],
                     ['meta', {},[]]
                ],
            ],
            [
                'body',{}, [
                    ['div',{id:"top_nav"},[]],
                    ['div',{},[]]
                ]
            ]
        ]
    ]

    var [rt,forest] = dfs_sexpr.tree_lize(S0)

    > dfs_sexpr.show(rt)
    html
        head
            meta
                -name viewport
            meta
        body
            div
                -id top_nav
            div


    > console.dir(dfs_sexpr.jsonize(rt),{depth:null})
    [
      'html',
      {},
      [
        [
          'head',
          {},
          [ [ 'meta', { name: 'viewport' }, [] ], [ 'meta', {}, [] ] ]
        ],
        [
          'body',
          {},
          [ [ 'div', { id: 'top_nav' }, [] ], [ 'div', {}, [] ] ]
        ]
      ]
    ]


tac
---
- T@optional : String,     if-skipped, it will be a index     
- A@optional : Object
- C@optional : Array<...S>
- S          : [T?,A?,C?]


### valid-ptrn

     [T],[A],[C],
     [T,A],[T,C],[A,C],
     [T,A,C]

###

    const {
        wfs_eng,
        wfs_tac,
    }  = require("nv-data-tree-csp-jconvert")
    

     var TAC0 = [
          'html',[
               'head',[
                     'meta',{charset:"utf8"},
               ],
               'body',{id:"app"},[
                    'div',['',{_text:'xxxx'}],
                    'br',
                    'div',['',{_text:'xxxx'}],
                    'br'
               ]
          ]
     ]


     var [rt,forest] = wfs_tac.tree_lize(TAC0);
     wfs_tac.show(rt)
     >
     @root@
        html
            head
                meta
                    -charset utf8
            body
                -id app
                div
    
                        -_text xxxx
                br
                div
    
                        -_text xxxx
                br

     console.dir(wfs_tac.jsonize(rt),{depth:null});
      
        [
          'html',
          [
            'head',
            [ 'meta', { charset: 'utf8' } ],
            'body',
            { id: 'app' },
            [
              'div',
              [ '', { _text: 'xxxx' } ],
              'br',
              'div',
              [ '', { _text: 'xxxx' } ],
              'br'
            ]
          ]
        ]


         var TAC1 = [
              'html',[
                   'head',[
                         'meta',{charset:"utf8"},
                   ],
                   'body',{id:"app"},[
                        'div',[{_text:'xxxx'}],
                        'br',
                        'div',[{_text:'xxxx'}],
                        'br'
                   ]
              ]
         ]
         
         var [rt,forest] = wfs_tac.tree_lize(TAC1);
         console.dir(wfs_tac.jsonize(rt),{depth:null});
         [
           'html',
           [
             'head',
             [ 'meta', { charset: 'utf8' } ],
             'body',
             { id: 'app' },
             [
               'div',
               [ 0, { _text: 'xxxx' } ],
               'br',
               'div',
               [ 0, { _text: 'xxxx' } ],
               'br'
             ]
           ]
         ]

#### missing T/A/C




        > var [rt,forest] = wfs_tac.tree_lize([{a:100},{b:200}])
        > wfs_tac.show(rt)
        @root@
            0
                -a 100
            1
                -b 200

        > console.dir(wfs_tac.jsonize(rt),{depth:null});
        [ { a: 100 }, { b: 200 } ]


        > var [rt,forest] = wfs_tac.tree_lize(['t0','t1',{a:100},{b:200}])

        > wfs_tac.show(rt)
        @root@
            t0
            t1
                -a 100
            2
                -b 200

        > console.dir(wfs_tac.jsonize(rt),{depth:null});
        [ 't0', 't1', { a: 100 }, { b: 200 } ]


        > var [rt,forest] = wfs_tac.tree_lize(['t0','t1',{a:100},'t2',{b:200}])
        undefined
        > wfs_tac.show(rt)
        @root@
            t0
            t1
                -a 100
            t2
                -b 200
        > console.dir(wfs_tac.jsonize(rt),{depth:null});
        [ 't0', 't1', { a: 100 }, 't2', { b: 200 } ]



        > var [rt,forest] = wfs_tac.tree_lize([[1,2],{a:100}])

        > wfs_tac.show(rt)
        @root@
            0
                1
                2
            1
                -a 100

        > console.dir(wfs_tac.jsonize(rt),{depth:null});
        [ [ 1, 2 ], { a: 100 } ]



cnest
-----
- E: {[k?]:any,ckey@custom-defined:Array<E> }


### wfs

    const {
        wfs_eng,
        wfs_tac,
    }  = require("nv-data-tree-csp-jconvert")

     var CNEST = 
        {
           tag:'html',
           children: [
              {
                  tag:'head',
                  children: [
                      { tag:'meta',attribs:{charset:"utf8"}}
                  ]
              },
              {
                  tag:'body',
                  attribs:{id:"app"},
                  children: [
                      { tag:'div',children:[{tag:'',attribs:{_text:'xxxx'}}]},
                      { tag:'br'},
                      { tag:'div',children:[{tag:'',attribs:{_text:'xxxx'}}]},
                      { tag:'br'},
                  ]
              },
           ]
       }
    
    
    var [rt,forest] = wfs_cnest.tree_lize(CNEST)
    wfs_cnest.show(rt)
    >
    html
        head
            meta
                -charset utf8
        body
            -id app
            div
    
                    -_text xxxx
            br
            div
    
                    -_text xxxx
            br
    
     
    console.dir(wfs_cnest.jsonize(rt),{depth:null})
    {
      tag: 'html',
      children: [
        {
          tag: 'head',
          children: [ { tag: 'meta', attribs: { charset: 'utf8' } } ]
        },
        {
          tag: 'body',
          attribs: { id: 'app' },
          children: [
            {
              tag: 'div',
              children: [ { tag: '', attribs: { _text: 'xxxx' } } ]
            },
            { tag: 'br' },
            {
              tag: 'div',
              children: [ { tag: '', attribs: { _text: 'xxxx' } } ]
            },
            { tag: 'br' }
          ]
        }
      ]
    }

### dfs

    const {
        dfs_cnest,
    }  = require("nv-data-tree-csp-jconvert")



     var CNEST = 
        {
           tag:'html',
           children: [
              {
                  tag:'head',
                  children: [
                      { tag:'meta',attribs:{charset:"utf8"}}
                  ]
              },
              {
                  tag:'body',
                  attribs:{id:"app"},
                  children: [
                      { tag:'div',children:[{tag:'',attribs:{_text:'xxxx'}}]},
                      { tag:'br'},
                      { tag:'div',children:[{tag:'',attribs:{_text:'yyyy'}}]},
                      { tag:'br'},
                  ]
              },
           ]
       }
    
    
    var [rt,forest] = dfs_cnest.tree_lize(CNEST)
    dfs_cnest.show(rt)
    html
        head
            meta
                -charset utf8
        body
            -id app
            div
    
                    -_text xxxx
            br
            div
    
                    -_text xxxx
            br

        console.dir(dfs_cnest.jsonize(rt),{depth:null})
        {
          children: [
            {
              tag: 'html',
              children: [
                {
                  tag: 'head',
                  children: [
                    { tag: 'meta', attribs: { charset: 'utf8' }, children: [] }
                  ]
                },
                {
                  tag: 'body',
                  attribs: { id: 'app' },
                  children: [
                    {
                      tag: 'div',
                      children: [ { tag: '', attribs: { _text: 'xxxx' }, children: [] } ]
                    },
                    { tag: 'br', children: [] },
                    {
                      tag: 'div',
                      children: [ { tag: '', attribs: { _text: 'yyyy' }, children: [] } ]
                    },
                    { tag: 'br', children: [] }
                  ]
                }
              ]
            }
          ]
        }

array
-----
- O = {[N:String]:Object}
- e = [op,Array<String|O>?]
- E =  [op,Array<E|e>]


###
  
    const {
        dfs_ary
    }  = require("nv-data-tree-csp-jconvert"); 


        var ary = [
           {'%program':{target:'js'}},
           ['%let','a'],                             //执行时 %let 也有返回值 {'a':{type:'notation'}}
           ['%let',{'b':{type:'%$i32'}}],
           ['%let','c'],
           ['%+','5','3'],                     //存入当前节点 可以被 %sdfs_prev% 获取
           ['%asgn','a','%sdfs_prev%'],
           ['%-',['%+','5','3']/*存入当前节点*/,['%-','5','3']/*存入当前节点*/] //存入当前节点,
           ['%def','fname',
               ['%params','A','B','C'],             //%params 会在 当前ctx.%params 上 添加 一组 notation
               ['%add','A','B','C'],
               ['%asgn','rslt','%sdfs_prev%'],
               ['%ret%','%rslt%']
           ],
           ['%call','fname',['%args','a','b','c']]
        ]

        var [rt,forest] = dfs_ary.tree_lize(ary)
        dfs_ary.show(rt)

        %program
            -target js
            %let
                a
            %let
                b
                    -type %$i32
            %let
                c
            %+
                5
                3
            %asgn
                a
                %sdfs_prev%
            %-
                %+
                    5
                    3
                %-
                    5
                    3
            %def
                fname
                %params
                    A
                    B
                    C
                %add
                    A
                    B
                    C
                %asgn
                    rslt
                    %sdfs_prev%
                %ret%
                    %rslt%
            %call
                fname
                %args
                    a
                    b
                    c


        > dfs_ary.jsonize(rt)
        [
          { '%program': { target: 'js' } },
          [ '%let', 'a' ],
          [ '%let', { b: [Object] } ],
          [ '%let', 'c' ],
          [ '%+', '5', '3' ],
          [ '%asgn', 'a', '%sdfs_prev%' ],
          [ '%-', [ '%+', '5', '3' ], [ '%-', '5', '3' ] ],
          [
            '%def',
            'fname',
            [ '%params', 'A', 'B', 'C' ],
            [ '%add', 'A', 'B', 'C' ],
            [ '%asgn', 'rslt', '%sdfs_prev%' ],
            [ '%ret%', '%rslt%' ]
          ],
          [ '%call', 'fname', [ '%args', 'a', 'b', 'c' ] ]
        ]
        >

LICENSE
=======
- ISC

---
_Source: https://npm.io/package/nv-data-tree-csp-jconvert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
