-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
example.js
50 lines (40 loc) · 1.88 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const split = require('./');
console.log(split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] }));
//=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ]
console.log(split('a.b."c.d.e.f.g".h.i'));
//=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ]
console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"']}));
//=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ]
let keep = (value, state) => {
return value !== '\\' && (value !== '"' || state.prev() === '\\');
};
console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'], keep }));
//=> [ 'a', 'b', '"c', 'd', 'e.f.g', 'h', 'i' ]
// console.log(split('a.[{a.b}].e', { brackets: { '[': ']' } }));
// console.log(split('a.[a.c.{d.e}].b', { brackets: { '[': ']' } }));
// console.log(split('a\\.[a.c.{d.e}].b', { brackets: { '[': ']' } }));
// console.log(split('...a.[a.c.{d.e}].b.s.s.s.s.s.', { brackets: { '[': ']' } }));
//=> [ 'a', '{a', '[{b.c}]', 'd}', 'e' ]
// console.log(split('a.{b.c}.[d.e].f', { brackets: true }));
// //=> [ 'a', '{b.c}', '[d', 'e]', 'f' ]
// console.log(split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩' } }));
// //=> [ '«a.b»', '⟨c.d⟩' ]
// const arr = split('a.b.c.a.d.e', state => {
// console.log(state)
// return state.prev() === 'a';
// });
// console.log(arr)
// // => [ 'a', 'b.c.a', 'd.e' ]
// console.log(split('a.{a.{b.c.d}.c}', { brackets: true }));
// //=> [ 'a', '{a.{b.c.d}.c}' ]
// const stash1 = split('a.b.c', state => state.prev() !== 'a');
// console.log(stash1);
// //=> ['a.b', 'c']
// console.log(split('zzz.{a.{b.{c.{d}.e}.f}.g}.xxx'));
// console.log(split('a.{b.c}|{d.e}', { separator: '|' }));
// console.log(split('a.{b.c}|{d.e}'));
// console.log(split('a.{b.c}.{d.e}'));
// console.log(split('a.{b.c}.{d.e}', { brackets: false }));
// console.log(split('a.{b.c}\\.{d.e}'));
// console.log(split('a.{b.c.[a-b]}.{d.e}'));
// console.log(split('a."a.b.c"\\.{d.e}', { quotes: ['"'], keep: () => true }));