1.0.0 • Published 5 years ago

to-generator v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

to-generator

Transforms an Array | Object into a Generator object.

usage

const toGenerator = require('to-generator');

[
  [1, 2, 33, 44],
  { foo: 'bar', baz: 22, boom: 34, fofofo: [2, 3, 4] }
].forEach(source => {
  console.log('current item: ', source);
  console.log('---');

  for (const item of toGenerator(source)) {
    console.log('>', item);
  }

  console.log('---------------');
});

// outputs:
/*
current item:  [ 1, 2, 33, 44 ]
---
> 1
> 2
> 33
> 44
---------------
current item:  { foo: 'bar', baz: 22, boom: 34, fofofo: [ 2, 3, 4 ] }
---
> { key: 'foo', value: 'bar' }
> { key: 'baz', value: 22 }
> { key: 'boom', value: 34 }
> { key: 'fofofo', value: [ 2, 3, 4 ] }
---------------
*/

license

MIT

1.0.0

5 years ago