1.0.2 • Published 4 years ago
nv-facutil-jsidize v1.0.2
nv-facutil-jsidize
- convert any string to a valid-js-identifier-name AND convet from valid-js-identifier-name to a string
- it is for converting lexical-binding-with-scope to a gloabl-var
- normally useless
rule
encode
  if '$'                          :  '$' => '$$'
  elif invalid-js-identifier-char : chars => $<eb64(chars)>$
  else                            : do-nothing
  eb64 is variant of base64install
- npm install nv-facutil-jsidize
usage
   const x = require("nv-facutil-jsidize");example
without prefix
    /*
    > _s2id('a-b.c')
    'a$LQ等等$$Lg等等$'
    >
    > let a$LQ等等$$Lg等等$ = 999
    > a$LQ等等$$Lg等等$
    999
    > _id2s('a$LQ等等$b$Lg等等$c')
    'a-b.c'
    >
    > _s2id('a     b')
    'a$ICAgICA等$b'
    >
    > let a$ICAgICA等$b =999
    > a$ICAgICA等$b
    999
    >
    > _id2s('a$ICAgICA等$b')
    'a     b'
    >
    > _s2id('a-b.c$$#')
    'a$LQ等等$b$Lg等等$c$$$$$Iw等等$'
    >
    let a$LQ等等$b$Lg等等$c$$$$$Iw等等$ = 999
    > a$LQ等等$b$Lg等等$c$$$$$Iw等等$
    999
    >
    > _id2s('a$LQ等等$b$Lg等等$c$$$$$Iw等等$')
    'a-b.c$$#'
    >
    */with prefix
    /*
    > x.s2id('1ab')
    '___1ab'
    >
    > x.s2id('1a.b')
    '___1a$Lg等等$b'
    >
    > x.s2id('1#a')
    '___1$Iw等等$a'
    >
    > x.id2s('___1ab')
    '___1ab'
    >
    > x.id2s('___1a$Lg等等$b')
    '___1a.b'
    >
    > x.id2s('___1$Iw等等$a')
    '___1#a'
    >
    >
    */API
{
  DOLLAR: '$$',
  DASH: '$LQ等等$',
  DOT: '$Lg等等$',
  HASH: '$Iw等等$',
  SPACE: '$IA等等$',
  _s2id: [Function: _s2id],   (s:String):ValidJsIdentifierNameIgnoreStartNumChar
  s2id: [Function: s2id],     (s,prefix='___'):ValidJsIdentifierName
  _id2s: [Function: _id2s],   (id:ValidJsIdentifierNameIgnoreStartNumChar):String
  id2s: [Function: id2s]      (id:ValidJsIdentifierName,prefix='___'):String
}LICENSE
- ISC