1.0.1 • Published 3 years ago

nv-facutil-match v1.0.1

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

nv-facutil-match

  • nv-facutil-match simple util for simple-match
  • nest match at dfs-sequence, three modes
  • break when first-matched
  • return all-matched
  • generator

install

  • npm install nv-facutil-match

usage

const Match = require("nv-facutil-match")

example

first-match

var cmatch = new Match()
cmatch.add(r=>r>=0&&r<=4,'[0,4]')
cmatch.add(r=>r>=5&&r<=9,'[5,9]')

var match = new Match()
match.add(r=>r>=0,cmatch)
match.add(r=>r>=10,'GE10')
match.add(/^[a-zA-Z]$/,'CH')
match.add("javascript","JS")

> match
Map(4) {
  [Function (anonymous)] => Map(2) {
    [Function (anonymous)] => '[0,4]',
    [Function (anonymous)] => '[5,9]'
  },
  [Function (anonymous)] => 'GE10',
  /^[a-zA-Z]$/ => 'CH',
  'javascript' => 'JS'
}
>

match.fst(7)
match.fst(13)
match.fst('A')
match.fst('javascript')
match.fst('lisp')

> match.fst(7)
'[5,9]'
> match.fst(13)
'GE10'
> match.fst('A')
'CH'
> match.fst('javascript')
'JS'
>
> match.fst('lisp')
Symbol(empty)
>
> match.EMPTY
Symbol(empty)
> match.EMPTY === match.fst('lisp')
true
>

all-match

var cmatch = new Match()
cmatch.add(r=>r>=0&&r<=4,'[0,4]')
cmatch.add(r=>r>=5&&r<=9,'[5,9]')
var match = new Match()
match.add(r=>r>=0,cmatch)
match.add(r=>r>=3,'GE3')
match.add(r=>r>=10,'GE10')
> match.all(3)
[ '[0,4]', 'GE3' ]
>

generator

var g = match.gen(3)
> g.next()
{ value: '[0,4]', done: false }
> g.next()
{ value: 'GE3', done: false }
> g.next()
{ value: undefined, done: true }
>
>
> var g = match.gen('ssss')
> g.next()
{ value: undefined, done: true }

METHODS

match.EMPTY
match.add                   
match.all                   
match.clear                 
match.del                   
match.fst                   
match.index_of              
match.insert_after
match.insert_before
match.gen

LICENSE

  • ISC