slice-arraylike-iterable

0.1.12 • Public • Published

slice-arraylike-iterable

travis ci npm version Coverage Status Dependency Status

slice-arraylike-iterable exports a class that, given an array-like iterable, builds iterables that provide slice method.

Install

$ npm install slice-arraylike-iterable --save

Usage

const SliceArrayLikeIterable = require('slice-arraylike-iterable')

const iterable = new SliceArrayLikeIterable([4, 2, 7, 8, 4, 7]) // (4 2 7 8 4 7)
    .slice(0, 5) // (4 2 7 8 7)
    .slice(2, 5) // (7 8 7)
    .slice(1, 2) // (8)

// converting to array:
[...iterable] // [8]

// traversing values:
for (const val of iterable) {
    // ...
}

// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 8, done: false}
iterator.next() // {value: undefined, done: true}

// the same with string
const string = 'abcdef'

new SliceArrayLikeIterable(string) // ('a' 'b' 'c' 'd' 'e' 'f')
    .slice(1, 4) // ('b' 'c' 'd')

// the same with typed array
const typedArray = new Uint8Array([128, 0, 0, 1])

new SliceArrayLikeIterable(naturals) // (128 0 0 1)
    .slice(0, 3) // (128 0 0)

Support

  • Node.js >=6
  • ES2015 transpilers

License

MIT

Package Sidebar

Install

npm i slice-arraylike-iterable

Weekly Downloads

3

Version

0.1.12

License

MIT

Last publish

Collaborators

  • xgbuils