1.0.0 • Published 2 years ago

nv-string-iter v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-string-iter

  • nv-string-iter
  • string iter with char/code/code-point
  • match_by , chunk_by

install

  • npm install nv-string-iter

usage

 const x = require("nv-string-iter")

example

    > 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 }
    >

match_by

    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 }
    >

    */

chunk_by

  • 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 }
    >

API

    {
      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]
    }

LICENSE

  • ISC