from-ndjson
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

from-ndjson

License Build Status NPM Package Code Coverage

Convert ndjson stringified data into JSON-object arrays.

Install

npm i -E from-ndjson

or:

yarn add -E from-ndjson

Usage

import fromNdjson from 'from-ndjson'

const ndjsonSample = `
  { "some": "thing" }
  { "foo": 17, "bar": false, "quux": true }
  { "may": { "include": "nested", "objects" : ["and", "arrays"] } }
`

const resultArray = fromNdjson(ndjsonSample)

console.log(resultArray[0])
// Output: { some: 'thing' }
console.log(resultArray[1])
// Output: { foo: 17, bar: false, quux: true }

API

fromNdjson(input, options?)

function fromNdjson(data: string, options: FromNdjson.Options)

Options

isStrict

Type: boolean
Default: 'false'

By default, fromNdjson() will just skip the rows that JSON.parse() can't parse. If you have an ndjson with 5 rows and 2 unparsable ones, the returned array will only contain 3 rows: the ones that could be parsed.

You can specify { isStrict: true } if you prefer an error to be thrown when a row is invalid.

Contribute

Release

npm version major|minor|patch

This will automatically create a full tagged commit with packages version bump in a version branch before pushing them to the remote repository.

Recommended IDE Settings

{
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },
  "eslint.codeActionsOnSave.mode": "all",
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  "eslint.format.enable": true,
  "eslint.packageManager": "npm",
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Package Sidebar

Install

npm i from-ndjson

Weekly Downloads

34

Version

1.0.4

License

MIT

Unpacked Size

5.67 kB

Total Files

5

Last publish

Collaborators

  • ivangabriele