Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

documented transforming at key paths with the example

  • Loading branch information...
commit 7214dc8d2af046395fac26ca1804d782aa81b290 1 parent 36aae88
@substack authored
Showing with 29 additions and 9 deletions.
  1. +29 −9 README.markdown
View
38 README.markdown
@@ -66,23 +66,38 @@ $ echo '[{"a":3},{"b":5},{"a":10,"b":3},{"b":55,"c":6}]' | node example/async.js
]
```
-custom parsing and stringification
-----------------------------------
+transforming at key paths
+-------------------------
-see [JSONStream](https://github.com/dominictarr/JSONStream) for more details
+``` js
+var transfuse = require('transfuse');
+var tr = transfuse(['rows', /./, 'c'], function (doc, map) {
+ doc.pizza = "tacos"
+ map(doc);
+});
+tr.pipe(process.stdout);
-transfuse(['rows', /./, 'doc'], function(doc, map) {
- doc.pizza = "tacos"
- map(doc)
-}, JSONStream.stringify("{\"docs\":[\n", "\n,\n", "\n]}\n"));
+var stream = new(require('net').Stream);
+stream.pipe(tr);
+
+stream.emit('data', JSON.stringify({
+ rows : [
+ { a : 3, c : {} },
+ { a : 4, c : { cats : 'dogs' } },
+ { a : 2, c : { beep : 'boop' } },
+ ],
+ bling : 'blong',
+}));
+stream.emit('end');
+```
methods
=======
var transfuse = require('transfuse');
-transfuse(fn)
--------------
+transfuse(keyPath=[/./], fn)
+----------------------
Return a readable/writable stream transforming an incoming JSON stream of "data"
events into an outgoing stream of "data" events with `fn`.
@@ -92,6 +107,11 @@ If `fn.length === 1` use `transfuse.sync`. Otherwise use `transfuse.async`.
If `fn` is a string then it should contain a function body which will be run
with `vm.runInNewContext`.
+The optional `keyPath` argument can be used to transform a specific nested
+section of the document.
+See [JSONStream](https://github.com/dominictarr/JSONStream) for how key path
+Arrays work.
+
transfuse.sync(fn)
------------------
Please sign in to comment.
Something went wrong with that request. Please try again.