pull-stringify
JSON.stringify as pull-stream
Last updated 12 years ago by dominictarr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pull-stringify 
SYNC missed versions from official npm registry.

pull-stringify

JSON.stringify as pull stream

example

var pull = require('pull-stream')
var stringify = require('pull-stringify')
var toPull = require('stream-to-pull-stream')

pull(
  pull.values([A, B, C]),
  stringify(),
  toPull(process.stdout)
)

usage

stringify = require('pull-stringify')

pull(
  pull.values([A, B, C]),
  stringify.lines(),
  toPull(process.stdout)
)

stringify(options)

options is an object with the following optional keys:

  • open: string to be prepended to first output string
  • prefix: string to be prepended to every non-first output string
  • suffix: string to be appended to every output string
  • close: string to be appended after stream is complete
  • indent: passed as third argument to JSON.stringify
  • stringify: custom function to use instead of JSON.stringify

stringify(options) returns a through pull-stream.

defaults options are for double newline delimited json. double newline delimiting means you can use indented json as the stream format, which is more human readable.

{
  open: '',
  prefix: '',
  suffix: '\n\n',
  close: '',
  indent: 2,
  stringify: JSON.stringify
}

stringify.ldjson(stringify)

stringify.lines(stringify)

for single newline delimited json use stringify.ldjson() or stringify.lines():

{
  suffix: '\n',
  indent: 0
}

you can pass a custom stringify as an argument.

// compatible with JSON but supports buffers.
var JSONB = require('json-buffer')

// use defaults
stringify({ stringify: JSONB.stringify })

// or
stringify.lines(JSONB.stringify)

stringify.array(stringify)

for a single json array use stringify.array()

{
  open: '[',
  separator: ',\n',
  close: ']\n',
  indent: 2
}

License

MIT

Current Tags

  • 2.0.0                                ...           latest (10 years ago)

6 Versions

  • 2.0.0                                ...           10 years ago
  • 1.2.2                                ...           11 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |