- nv-string-iter
- string iter with char/code/code-point
- match_by , chunk_by
- npm install nv-string-iter
const x = require("nv-string-iter")
> g=x.yield_si_with_str('A𝑒B')
Object [Generator] {}
> g.next()
{ value: 0, done: false }
> g.next()
{ value: 1, done: false }
> g.next()
{ value: 3, done: false }
> g.next()
{ value: undefined, done: true }
>
const {match_by_char_matcher,_match_by_char_matcher} = require("nv-string-iter");
var matcher = (char)=>char==='0' || char==='1';
var g = match_by_char_matcher('a00bb101c002d1E0',matcher)
/*
> g.next()
{ value: '00', done: false }
> g.next()
{ value: '101', done: false }
> g.next()
{ value: '00', done: false }
> g.next()
{ value: '1', done: false }
> g.next()
{ value: '0', done: false }
> g.next()
{ value: undefined, done: true }
>
*/
var g = _match_by_char_matcher('a00bb101c002d1E0',matcher)
//only generate start_index AND end_index, this is fast, coz without do string/slice/copy
/*
> g.next()
{ value: [ 1, 3 ], done: false }
> g.next()
{ value: [ 5, 8 ], done: false }
> g.next()
{ value: [ 9, 11 ], done: false }
> g.next()
{ value: [ 13, 14 ], done: false }
> g.next()
{ value: [ 15, 16 ], done: false }
> g.next()
{ value: undefined, done: true }
>
*/
- similiar to std::views::chunk_by
> const {_chunk_by_code_point_matcher,chunk_by_code_point_matcher} = require("nv-string-iter")
>
> var matcher = (curr_code_point,next_code_point) => curr_code_point<=next_code_point;
>
> var g = chunk_by_code_point_matcher("12230452",matcher)
> g.next()
{ value: '1223', done: false }
> g.next()
{ value: '045', done: false }
> g.next()
{ value: '2', done: false }
> g.next()
{ value: undefined, done: true }
>
> var g = _chunk_by_code_point_matcher("12230452",matcher)
> g.next()
{ value: [ 0, 4 ], done: false }
> g.next()
{ value: [ 4, 7 ], done: false }
> g.next()
{ value: [ 7, 8 ], done: false }
> g.next()
{ value: undefined, done: true }
>
{
yield_si_with_codes: [GeneratorFunction: yield_si_with_codes],
yield_si_with_str: [GeneratorFunction: yield_si_with_str],
_match_by_char_matcher: [GeneratorFunction: _match_by_char_matcher],
match_by_char_matcher: [GeneratorFunction: match_by_char_matcher],
_match_by_code_point_matcher: [GeneratorFunction: _match_by_code_point_matcher],
match_by_code_point_matcher: [GeneratorFunction: match_by_code_point_matcher],
_chunk_by_code_point_matcher: [GeneratorFunction: _chunk_by_code_point_matcher],
chunk_by_code_point_matcher: [GeneratorFunction: chunk_by_code_point_matcher]
}