1.0.1 • Published 6 years ago

@kingjs/make-enumerable v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

@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

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