nv-array-split
v1.0.2
Published
nv-array-split ============ - nv-array-split
Downloads
18
Readme
nv-array-split
- nv-array-split
install
- npm install nv-array-split
usage
const {
all,
cond,
rng,
slc,
join,
gen,
} = require("nv-array-split")
example
var arr = Array.from("example")
var sps = [/[aieou]/,"m",(r,i)=>r==='p'||r==='l']
> slc(arr,sps)
[ [ 'e' ], [ 'x' ], [ 'a' ], [ 'm' ], [ 'p', 'l' ], [ 'e' ] ]
>
> rng(arr,sps)
[ [ 0, 1 ], [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 6 ], [ 6, 7 ] ]
>
> join(arr,sps,'-')
[ 'e', 'x', 'a', 'm', 'p-l', 'e' ]
>
> cond(arr,sps)
[
/[aieou]/,
undefined,
/[aieou]/,
'm',
[Function (anonymous)],
/[aieou]/
]
>
> cond(arr,sps)[4].toString()
"(r,i)=>r==='p'||r==='l'"
>
> all(arr,sps)
[
[ 0, 1, 0 ],
[ 1, 2, 3 ],
[ 2, 3, 0 ],
[ 3, 4, 1 ],
[ 4, 6, 2 ],
[ 6, 7, 0 ]
]
>
var is_sp = (v)=>v === null || v === true || v === false
var arr = [null,100,200,300,true,'A',false,'B','C']
var g = gen(arr,is_sp)
> Array.from(g)
[ [ 100, 200, 300 ], [ 'A' ], [ 'B', 'C' ] ]
>
var arr = [null,100,200,300,true,'A',false,'B','C']
var g = gen(arr,is_sp,true)
Array.from(g)
> [ [ null, 100, 200, 300 ], [ true, 'A' ], [ false, 'B', 'C' ] ]
var arr = [null,100,200,300,true,'A',false]
var g = gen(arr,is_sp)
> Array.from(g)
[ [ 100, 200, 300 ], [ 'A' ], [] ]
>
var arr = [100,200,300,true,'A',false]
var g = gen(arr,is_sp)
> Array.from(g)
[ [ 100, 200, 300 ], [ 'A' ], [] ]
>
var arr = [100,200,300,true,'A',false]
var g = gen(arr,is_sp,true)
> var rslts = Array.from(g)
> rslts
[ [ Symbol(), 100, 200, 300 ], [ true, 'A' ], [ false ] ]
>
> gen.is_dummy_sp(rslts[0][0])
true
>
var arr = [null,100,200,300,true,'A',false,'B','C']
var g = gen(arr,is_sp,true,(r)=>({head:r[0],body:r.slice(1)}))
> Array.from(g)
[
{ head: null, body: [ 100, 200, 300 ] },
{ head: true, body: [ 'A' ] },
{ head: false, body: [ 'B', 'C' ] }
]
>
SPS
type F = (r:any,i:number)=>boolean
type SP = string | RegExp | Set | Array<any> | F
type SPS = Array<SP>
API
- ary_sp.all(arr,sps)
- ary_sp.cond(arr,sps)
- ary_sp.slc(arr,sps)
- ary_sp.rng(arr,sps)
- ary_sp.join(arr,sps,delimeter='')
- ary_sp.gen(arr,is_sp,with_sp=false,aggf=(r)=>r)
LICENSE
- ISC