uiterator

1.0.5 • Public • Published

μiterator

Really tiny iterator for arrays and objects.

Usage

Require iterate function into your module.

const { iterate } = require('uiterator');

Now you can iterate over:

  • key/value pairs — iterate(value);
  • keys only — iterate(value).keys();
  • values only — iterate(value).values().

Array examples

const test_array = [ 'foo', 'bar', 123 ];
for (const [ index, value ] of iterate(test_array)) {
  // 0, 'foo'
  // 1, 'bar'
  // 2, 123
}
for (const index of iterate(test_array).keys()) {
  // 0
  // 1
  // 2
}

(There is no need to iterate array values using uiterator.)

Object examples

const test_object = {
  foo: 'bar',
  baz: 123,
};
for (const [ key, value ] of iterate(test_object)) {
  // 'foo', 'bar'
  // 'baz', 123
}
for (const key of iterate(test_object).keys()) {
  // 'foo'
  // 'baz'
}
for (const value of iterate(test_object).values()) {
  // 'bar'
  // 123
}

Dependents (0)

Package Sidebar

Install

npm i uiterator

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

9.41 kB

Total Files

8

Last publish

Collaborators

  • kirick