1.0.2 • Published 8 years ago

sate v1.0.2

Weekly downloads
16
License
-
Repository
github
Last release
8 years ago

Sate

Small utility for generator-based iteration stacking.

Sate allows you to iterate an array (or something linear) and stack (yield) items in a new location.

const sate = require('sate');

const foo = [1, 2, 3];
const bar = sate(foo, function* (item) {
  yield* [item, -item];
});

console.log(bar);
// => [1, -1, 2, -2, 3, -3]

Installation

$ npm install --save sate

Usage

import sate from 'sate';
// or
const sate = require('sate');
// ...

sate(arr, function* (item, iterator, self) {
  // ...
});

sate(arr, fn*)

Perform an iteration, and yield items into an output stack.

  • arr (Array): Item to iterate.
  • fn* (function*, generator): Iteration and stacking operation.

Example:

const input = ['foo', 'bar:baz:qux', 'oof:rab', 'zab'];
const output = sate(input, function* (item) {
  yield* item.split(':');
});

console.log(output);
// => ['foo', 'bar', 'baz', 'qux', 'oof', 'rab', 'zab']

Credits

jamen
Jamen Marzonie