@kingjs/make-enumerable

Make an array enumerable by adding a 'getEnumerable' method.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@kingjs/make-enumerable
Minified + gzip package size for @kingjs/make-enumerable in KB

Readme

@kingjs/make-enumerable

Make an array enumerable by adding a getEnumerable method.

Usage

Make an array enumerable like this:

makeEnumerable = require('@kingjs/make-enumerable');
var sequence = makeEnumerable([ 1, 2 ]);

// sequence is still an array...
sequence.push(3); 

// ...that can enumerated!
var enumerator = sequence.getEnumerator();

var result = [];
while (enumerator.moveNext())
  result.push(enumerator.current);
result;

result:

[ 1, 2, 3 ]

API

declare function makeEnumerable(
  array?: Array
): Enumerable

Interfaces

  • Enumerable: See @kingjs/sequence.

    Parameters

  • array: The array to augment with function getEnumerator.

    Returns

    The array passed as array augmented with a getEnumerable function.

    Remarks

    Passing null or undefined will return an empty array that is also enumerable.

The array is frozen by the first call to getEnumerator to prevent mutating the array during enumeration.

Install

With npm installed, run

$ npm install @kingjs/make-enumerable

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.