Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mixu committed Sep 29, 2014
1 parent c0a9f2e commit 2a1bb2e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
17 changes: 17 additions & 0 deletions example.js
@@ -0,0 +1,17 @@
var pi = require('./index.js');

pi.fromArray([{ a: 'a' }, { b: 'b' }, { c: 'c' }])
.pipe(pi.mapKey('foo', function(value) { return typeof value === 'undefined' ? 'bar' : 'value'; }))
.pipe(pi.forEach(function(obj) { console.log(obj); }));

pi.fromArray(['a', 'b', 'c'])
.pipe(pi.map(function(chunk) { return chunk + '!!' }))
.pipe(pi.forEach(function(obj) { console.log(obj); }));

pi.fromArray(['a', 'b', 'c'])
.pipe(pi.reduce(function(prev, chunk) { return prev + '|' + chunk; }, ''))
.pipe(pi.forEach(function(obj) { console.log(obj); }));

pi.fromArray([{ path: '/a/a' }, { path: '/a/b' }, { path: '/a/c' }])
.pipe(pi.mapKey('path', function(p) { return p.replace('/a/', '/some/'); }))
.pipe(pi.forEach(function(obj) { console.log(obj); }));
27 changes: 21 additions & 6 deletions readme.md
Expand Up @@ -2,6 +2,10 @@


Functions for iterating over object mode streams. Functions for iterating over object mode streams.


# Installation

npm install --save pipe-iterators

# API # API


The API is analoguous to the native `Array.*` iteration API (`forEach`, `map`, `filter`). All the functions return object mode streams. The API is analoguous to the native `Array.*` iteration API (`forEach`, `map`, `filter`). All the functions return object mode streams.
Expand All @@ -28,40 +32,51 @@ When calling `fork`, keep in mind that `.pipe()` returns the last stream's objec


## Examples ## Examples


Preamble:

```js
var pi = require('pipe-iterators');
```

Log every item: Log every item:


```js ```js
.pipe(forEach(function(obj) { console.log(obj); })) pi.fromArray(['a', 'b', 'c'])
.pipe(pi.forEach(function(obj) { console.log(obj); }));
``` ```


Set defaults: Set defaults:


```js ```js
.pipe(map(function(obj) { return _.defaults(obj, source); })); pi.fromArray([{ a: 'a' }, { b: 'b' }, { c: 'c' }])
.pipe(pi.map(function(obj) { return _.defaults(obj, { foo: 'bar' }); }));
``` ```


Convert to string: Convert to string:


```js ```js
.pipe(map(function(chunk) { return chunk.toString()); })); .pipe(pi.map(function(chunk) { return chunk.toString()); }));
``` ```


Append or prepend a value: Append or prepend a value:


```js ```js
.pipe(map(function(chunk) { return chunk + '!!' })) pi.fromArray(['a', 'b', 'c'])
.pipe(pi.map(function(chunk) { return chunk + '!!' }));
``` ```


Join chunks: Join chunks:


```js ```js
.pipe(reduce(function(prev, chunk) { return prev + '|' + chunk; }), ''); pi.fromArray(['a', 'b', 'c'])
.pipe(pi.reduce(function(prev, chunk) { return prev + '|' + chunk; }, ''));
``` ```


Replace the value in the `path` key: Replace the value in the `path` key:


```js ```js
.pipe(mapKey('path', function(p) { return p.replace(assetPath, outPath); })) pi.fromArray([{ path: '/a/a' }, { path: '/a/b' }, { path: '/a/c' }])
.pipe(pi.mapKey('path', function(p) { return p.replace('/a/', '/some/'); }));
``` ```


## What about asynchronous iteration? ## What about asynchronous iteration?
Expand Down

0 comments on commit 2a1bb2e

Please sign in to comment.