npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nv-facutil-multi-key

v1.0.2

Published

nv-facutil-multi-key ======================== - nv-facutil-multi-key is a simple util for multi-key dict

Downloads

7

Readme

nv-facutil-multi-key

  • nv-facutil-multi-key is a simple util for multi-key dict

install

  • npm install nv-facutil-multi-key

usage

const {MultiKey,empty,ERROR_DICT} = require("nv-facutil-multi-key");

example

for test

var area = {
    succ$0: 'success',
    province$1: 'province-not-valid',
    city$2: 'city-not-valid',
    county$3: 'county-not-valid',
    length$4: 'length-must-be-6'
}

var birth = {
    succ$0:"success",
    length$1:"length-must-be-8",
    year$2:"must-be-human",
    month$3:"month-must-between-01-12",
    day$4:"day-must-between-01-28,29,30,31"
}

var sex = {
    succ$0:"success",
    length$1:"length-must-be-1",
    value$2:"value-must-be-1,3,5,7,9(man)-or-0,2,4,6,8(woman)"
}

var police = {
    succ$0:"success",
    length$1:"length-must-be-2",
    value$2:"value-must-be-^[0-9]{2}$"
}


var parity = {
    succ$0:"success",
    length$1:"length-must-be-1",
    value$2:"value-must-be-^[0-9X]$",
    parity$3:"parity-error"
}


var parent_err ={
    succ$0:"success",
    area$1:area,
    birth$2:birth,
    sex$3:sex,
    police$4:police,
    parity$5:parity
}

MultiKey

//

var serr = new MultiKey(parent_err,'$')

/*
> serr
{
  'succ$0': 'success',
  'area$1': {
    'succ$0': 'success',
    'province$1': 'province-not-valid',
    'city$2': 'city-not-valid',
    'county$3': 'county-not-valid',
    'length$4': 'length-must-be-6'
  },
  'birth$2': {
    'succ$0': 'success',
    'length$1': 'length-must-be-8',
    'year$2': 'must-be-human',
    'month$3': 'month-must-between-01-12',
    'day$4': 'day-must-between-01-28,29,30,31'
  },
  'sex$3': {
    'succ$0': 'success',
    'length$1': 'length-must-be-1',
    'value$2': 'value-must-be-1,3,5,7,9(man)-or-0,2,4,6,8(woman)'
  },
  'police$4': {
    'succ$0': 'success',
    'length$1': 'length-must-be-2',
    'value$2': 'value-must-be-^[0-9]{2}$'
  },
  'parity$5': {
    'succ$0': 'success',
    'length$1': 'length-must-be-1',
    'value$2': 'value-must-be-^[0-9X]$',
    'parity$3': 'parity-error'
  }
}
> serr.$is_root()
true
>
*/

get

//multi-key
serr.area
serr[1]
serr[1] === serr.area
/*
> serr.area
{
  'succ$0': 'success',
  'province$1': 'province-not-valid',
  'city$2': 'city-not-valid',
  'county$3': 'county-not-valid',
  'length$4': 'length-must-be-6'
}
> serr[1]
{
  'succ$0': 'success',
  'province$1': 'province-not-valid',
  'city$2': 'city-not-valid',
  'county$3': 'county-not-valid',
  'length$4': 'length-must-be-6'
}
> serr[1] === serr.area
true
>

*/

serr.area.city
serr.area[2]
serr[1][2]
serr[1].city

serr.area.city === serr.area[2]
serr.area.city === serr[1][2]
serr.area.city === serr[1].city

/*
> serr.area.city
city-not-valid
> serr.area[2]
city-not-valid
> serr[1][2]
city-not-valid
> serr[1].city
city-not-valid
>
> serr.area.city === serr.area[2]
true
> serr.area.city === serr[1][2]
true
> serr.area.city === serr[1].city
true
>

*/

//use .$json() to get the real-value
serr.area.city.$json()

/*
> serr.area.city.$json()
'city-not-valid'
>

*/

relation

//relation
serr.area.city
serr.area.city.$parent
serr.area.$children
serr.area.city.$is_child_of(serr.area)
serr.area.city.$is_des_of(serr)
serr.area.city.$pl
serr.area.city.$ances
/*
> serr.area.city
city-not-valid
> serr.area.city.$parent
{
  'succ$0': 'success',
  'province$1': 'province-not-valid',
  'city$2': 'city-not-valid',
  'county$3': 'county-not-valid',
  'length$4': 'length-must-be-6'
}
> serr.area.$children
[
  success,
  province-not-valid,
  city-not-valid,
  county-not-valid,
  length-must-be-6
]
> serr.area.city.$is_child_of(serr.area)
true
> serr.area.city.$is_des_of(serr)
true
> serr.area.city.$pl
[ 'area$1', 'city$2' ]

> serr.area.city.$ances.map(nd=>nd.$pkey)
[ Symbol(empty), 'area$1' ]
>
serr.area.city.$ances[0].$is_root()
>true


*/


serr.$deses.filter(nd=>nd.$is_leaf())
/*
[
  success,
  success,
  province-not-valid,
  city-not-valid,
  county-not-valid,
  length-must-be-6,
  success,
  length-must-be-8,
  must-be-human,
  month-must-between-01-12,
  day-must-between-01-28,29,30,31,
  success,
  length-must-be-1,
  value-must-be-1,3,5,7,9(man)-or-0,2,4,6,8(woman),
  success,
  length-must-be-2,
  value-must-be-^[0-9]{2}$,
  success,
  length-must-be-1,
  value-must-be-^[0-9X]$,
  parity-error
]

*/

pathlist get set

serr.$plget([1,2])
serr.$plget(['area','city'])
/*
> serr.$plget([1,2])
city-not-valid
> serr.$plget(['area','city'])
city-not-valid
>

*/

> serr.$chkeys
[ 'succ$0', 'area$1', 'birth$2', 'sex$3', 'police$4', 'parity$5' ]
>
>
> serr.area.$get_full_chkey(1)
'province$1'
>

add delete

 > serr.$del('parity')
 {
   'succ$0': 'success',
   'length$1': 'length-must-be-1',
   'value$2': 'value-must-be-^[0-9X]$',
   'parity$3': 'parity-error'
 }
 >


 serr.$add(parity,'parity$0043')
 /*
 {
   'succ$0': 'success',
   'area$1': {
     'succ$0': 'success',
     'province$1': 'province-not-valid',
     'city$2': 'city-not-valid',
     'county$3': 'county-not-valid',
     'length$4': 'length-must-be-6'
   },
   'birth$2': {
     'succ$0': 'success',
     'length$1': 'length-must-be-8',
     'year$2': 'must-be-human',
     'month$3': 'month-must-between-01-12',
     'day$4': 'day-must-between-01-28,29,30,31'
   },
   'sex$3': {
     'succ$0': 'success',
     'length$1': 'length-must-be-1',
     'value$2': 'value-must-be-1,3,5,7,9(man)-or-0,2,4,6,8(woman)'
   },
   'police$4': {
     'succ$0': 'success',
     'length$1': 'length-must-be-2',
     'value$2': 'value-must-be-^[0-9]{2}$'
   },
   'parity$0043': {
     'succ$0': 'success',
     'length$1': 'length-must-be-1',
     'value$2': 'value-must-be-^[0-9X]$',
     'parity$3': 'parity-error'
   }
 }

 */

 serr.$del('0043')
 serr.$plset(['parity$5'],parity)
 /*
 > serr
 {
   'succ$0': 'success',
   'area$1': {
     'succ$0': 'success',
     'province$1': 'province-not-valid',
     'city$2': 'city-not-valid',
     'county$3': 'county-not-valid',
     'length$4': 'length-must-be-6'
   },
   'birth$2': {
     'succ$0': 'success',
     'length$1': 'length-must-be-8',
     'year$2': 'must-be-human',
     'month$3': 'month-must-between-01-12',
     'day$4': 'day-must-between-01-28,29,30,31'
   },
   'sex$3': {
     'succ$0': 'success',
     'length$1': 'length-must-be-1',
     'value$2': 'value-must-be-1,3,5,7,9(man)-or-0,2,4,6,8(woman)'
   },
   'police$4': {
     'succ$0': 'success',
     'length$1': 'length-must-be-2',
     'value$2': 'value-must-be-^[0-9]{2}$'
   },
   'parity$5': {
     'succ$0': 'success',
     'length$1': 'length-must-be-1',
     'value$2': 'value-must-be-^[0-9X]$',
     'parity$3': 'parity-error'
   }
 }
 >
 */

change key

serr.$add_key('parity','verify$validate')

/*
> serr
{
  ......
  'parity$5$verify$validate': {
    'succ$0': 'success',
    'length$1': 'length-must-be-1',
    'value$2': 'value-must-be-^[0-9X]$',
    'parity$3': 'parity-error'
  }
}
>

*/

serr.$del_key('parity','verify$validate')
/*
....
  'parity$5': {
    'succ$0': 'success',
    'length$1': 'length-must-be-1',
    'value$2': 'value-must-be-^[0-9X]$',
    'parity$3': 'parity-error'
  }
}

*/

METHODS

LICENSE

  • ISC