1.0.8 • Published 4 years ago

ncsv v1.0.8

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
4 years ago

NCSV

Nested CSV parser. Flattens JSON into a CSV, and restores the JSON from the CSV.

What is it?

It turns this:

person.nameperson.emailperson.ageperson.birthdrinks.likes.0drinks.dislikes.0
pouyatest@example.com28.6coffee
nathalie1991-06-03chocolate milkcoffee

into this:

[
  {
    "person": {
      "age": 28.6,
      "name": "pouya",
      "email": "test@example.com"
    },
    "drinks": {
      "likes": [
        "coffee"
      ]
    }
  },
  {
    "person": {
      "name": "nathalie",
      "birth": "1991-06-03T00:00:00.000Z"
    },
    "drinks": {
      "likes": [
        "chocolate milk"
      ],
      "dislikes": [
        "coffee"
      ]
    }
  }
]

and vice versa.

Install

ncsv is hosted on npm:

npm i -g ncsv

or in case you want to use just in one project:

npm i -S ncsv

CLI

Once installed, ncsv command will be available to you.

  USAGE: ncsv -i input -o output -m mode --pretty
    mode can be json2csv or csv2json
    mode is optional, defaults to csv2json
    --pretty outputs pretty formatted json

Library

ncsv exports lexer, model, and parse. Model is a bean parser model. lexer is used for lexing input csv, parse uses bean parser to parse the lexing results.

To parse a csv into json, just do:

const { parse } = require('ncsv')
const json = parse(csv)

parse expects the csv string, not a path. This function returns an object.

To read a JSON and output CSV, do:

const { fromJSON } = require('ncsv')
const csv = fromJSON(json)

fromJSON expects the json string, not a path, not an object. This function returns a string.

License

Apache-2.0

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago