1.0.0 • Published 2 years ago

nv-string-simple-shape v1.0.0

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

nv-string-simple-shape

  • nv-string-simple-shape
  • a simple syntax for partitial-replace a string
  • escape : \
  • value : quoted by '
  • white-space: \r \n \t AND space
  • var : continuous chars

install

  • npm install nv-string-simple-shape

usage

      const x = require("nv-string-simple-shape")

example

        > var code    = `'(' p0 '+' p1 '-' p2 ')'`;
        > var shape  = x(code)
        
           -- the code has 4 vals :  '(' '+' '-' ')'
           -- the code has 3 params:  p0 p1 p2 

        > shape
        Shape(7) [
          '(',
          Symbol(p0),
          '+',
          Symbol(p1),
          '-',
          Symbol(p2),
          ')',
          '#lefted': Set(3) { 1, 3, 5 }
        ]
        > shape.params_
        [ Symbol(p0), Symbol(p1), Symbol(p2) ]
        >
        > shape.fill_one("p1",'999')
        > shape.params_
        [ Symbol(p0), Symbol(p2) ]
        >
        > shape.fill_one("p2",'888')
        >
        > shape.params_
        [ Symbol(p0) ]
        >
        > shape.fill_one("p0",'777')
        >
        > shape
        Shape(7) [
          '(',
          '777',
          '+',
          '999',
          '-',
          '888',
          ')',
          '#lefted': Set(0) {}
        ]
        > shape.stringify()
        '(777+999-888)'
        >

METHODS

        shape.params_  //get unargumentized param-placeholder

        shape.fill_one(sym_desc_name,str_val)              
        shape.fill_with_dict({
            sym_desc_name0:str_val0,
            ....
            sym_desc_namen:str_valn,
        })
        shape.is_sym_at(idx)             
        shape.is_val_at(idx)             
        
        shape.push                  
        shape.stringify

LICENSE

  • ISC