1.0.0 • Published 3 years ago
nv-tail-backslash v1.0.0
nv-tail-backslash
- nv-tail-backslash is very simple util,
- it will parse-quote
- and then convert CRLF,CR to LF
- and then remove BACKSLASH+LF
- and then split-the-input-string
- self-defined quotes
- self-defined nls
- self-defined backslash
install
- npm install nv-tail-backslash
usage
const nvquote = require("nv-quote");
const nvnl = require("nv-newline");
const nvtail = require("nv-tail-backslash");
{
TAIL_BACKSLASHS: [ '\\' ],
TAIL: '\\',
tokenize: [Function: tokenize],
split: [Function: split]
}
example
var s = `\n""a'bc'c\\\n'''hij'''\\\r\nk"""lmnopq"""\r\nr\n`
> console.log(s)
""a'bc'c\
'''hij'''\
k"""lmnopq"""
r
undefined
>
var toks = nvquote.tokenize(s,quotes=nvquote.JSPY_QUOTES)
toks = nvnl.tokenize(toks,nls=nvnl.NLS)
toks = nvtail.tokenize(toks,tail_backslashes=nvtail.tail_backslashes)
[
Tok {
str: '\n',
type: 'newline',
raw: '\n',
state: 'finished',
extra: 1
},
Tok {
str: '',
type: 'quoted-str',
raw: '""',
state: 'finished',
extra: 3
},
Tok {
str: 'a',
type: 'raw',
raw: 'a',
state: undefined,
extra: undefined
},
Tok {
str: 'bc',
type: 'quoted-str',
raw: "'bc'",
state: 'finished',
extra: 2
},
Tok {
str: 'c',
type: 'raw',
raw: 'c',
state: undefined,
extra: undefined
},
Tok {
str: 'hij',
type: 'quoted-str',
raw: "'''hij'''",
state: 'finished',
extra: 1
},
Tok {
str: 'k',
type: 'raw',
raw: 'k',
state: undefined,
extra: undefined
},
Tok {
str: 'lmnopq',
type: 'quoted-str',
raw: '"""lmnopq"""',
state: 'finished',
extra: 0
},
Tok {
str: '\n',
type: 'newline',
raw: '\r\n',
state: 'finished',
extra: 0
},
Tok {
str: 'r',
type: 'raw',
raw: 'r',
state: undefined,
extra: undefined
},
Tok {
str: '\n',
type: 'newline',
raw: '\n',
state: 'finished',
extra: 1
}
]
nvtail.split(s,cfg={quotes:nvquote.JSPY_QUOTES})
[
'\n', '""',
'a', "'bc'",
'c', "'''hij'''",
'k', '"""lmnopq"""',
'\r\n', 'r',
'\n'
]
>
API
- nvtail.BACKSLASHES
- nvtail.TAIL
- nvtail.tokenize(toks,tail_backslashes=nvtail.TAIL_BACKSLASHS)
- nvtail.split(s,cfg={quotes:nvquote.JS_QUOTES,nls:nvnl.NLS,tail_backslashes:nvtail.TAIL_BACKSLASHS})
LICENSE
- ISC
1.0.0
3 years ago