-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2cd4084
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var through = require('through') | ||
var split = require('split') | ||
var EOL = require('os').EOL | ||
|
||
module.exports = parse | ||
module.exports.serialize = serialize | ||
module.exports.parse = parse | ||
|
||
function parse() { | ||
return split(function(row) { | ||
if (row) return JSON.parse(row) | ||
}) | ||
} | ||
|
||
function serialize() { | ||
return through(function(obj) { | ||
this.queue(JSON.stringify(obj) + EOL) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "ldjson", | ||
"version": "0.0.1", | ||
"description": "streaming line delimited json parser + serializer", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"author": "max ogden", | ||
"license": "BSD", | ||
"dependencies": { | ||
"split": "~0.2.10", | ||
"through": "~2.3.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ldjson | ||
|
||
#### streaming line delimited json parser + serializer | ||
|
||
[![NPM](https://nodei.co/npm/ldjson.png)](https://nodei.co/npm/ldjson/) | ||
|
||
## usage | ||
|
||
#### ldjson.parse() | ||
|
||
returns a transform stream that accepts newline delimited json and emits objects | ||
|
||
example newline delimited json: | ||
|
||
`data.txt`: | ||
|
||
``` | ||
{"foo": "bar"} | ||
{"hello": "world"} | ||
``` | ||
|
||
usage: | ||
|
||
```js | ||
fs.createReadStream('data.txt') | ||
.pipe(require('ldjson').parse()) | ||
.on('data', function(obj) { | ||
// obj is a javascript object | ||
}) | ||
``` | ||
|
||
#### ldjson.serialize() | ||
|
||
returns a transform stream that accepts json objects and emits newline delimited json | ||
|
||
example usage: | ||
|
||
```js | ||
var serialize = require('ldjson').serialize() | ||
serialize.on('data', function(line) { | ||
// line is a line of stringified JSON with a newline delimiter at the end | ||
}) | ||
serialize.write({"foo": "bar"}) | ||
serialize.end() | ||
``` | ||
|
||
### license | ||
|
||
BSD |