npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ncsv

v1.0.8

Published

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

Downloads

13

Readme

NCSV

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

What is it?

It turns this:

|person.name|person.email |person.age|person.birth|drinks.likes.0|drinks.dislikes.0| |-----------|----------------|----------|------------|--------------|-----------------| |pouya |[email protected]|28.6 | |coffee | | |nathalie | | |1991-06-03 |chocolate milk|coffee |

into this:

[
  {
    "person": {
      "age": 28.6,
      "name": "pouya",
      "email": "[email protected]"
    },
    "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