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

csv-extract

v1.0.2

Published

Extract data from CSV files.

Downloads

4

Readme

csv-extract

Extract data from CSV files.

csv-extract is optimized to work with large CSV files.

Uses a readable stream to process the input file line by line.

  ____ ______     __  _____      _                  _
 / ___/ ___\ \   / / | ____|_  _| |_ _ __ __ _  ___| |_
| |   \___ \\ \ / /  |  _| \ \/ / __| '__/ _` |/ __| __|
| |___ ___) |\ V /   | |___ >  <| |_| | | (_| | (__| |_
 \____|____/  \_/    |_____/_/\_\\__|_|  \__,_|\___|\__|

Install

This is a CLI tool so you can install it globally with:

npm i -g csv-extract

Or you can just run it without installion:

npx csv-extract [options]

Usage

  Usage: csv-extract [options]

  Commands:
    help     Display help
    version  Display version

  Options:
    -c, --csv              CSV file to read (required)
    -d, --divider [value]  Data divider (defaults to ",")
    -f, --filters          JSON file with filters to apply (required)
    -F, --format [value]   Output format (json or csv) (defaults to "json")
    -h, --help             Output usage information
    -l, --maxLines <n>     Maximum number of lines to read, unlimited when unset (defaults to null)
    -r, --maxResults <n>   Maximum number of results to return, unlimited when unset (defaults to null)
    -o, --output           Output file where results will be stored
    -v, --version          Output the version number

Example

csv-extract -c large-data-sample.csv -f filters-2023.json

Filters

We use filters to find specific data inside large CSV files.

Filters are provided in JSON format, where every key belong to a CSV header and every value matches CSV data.

For example, given this CSV data:

id,name,email
1337,Awesome Dude,[email protected]
86,Someone Else,[email protected]

We can retrieve the first data item using this filter:

{
  "id": "1337"
}

By default all CSV data items are converted to strings, so keep that in mind when writing filters.

Regex

We can also use regex filters.

For example, to get the same data as before:

{
  "email": {
    "regex": "selse.*"
  }
}

Multiple filters

Just add more properties to the filters document.

Let's try with another data sample.

id,name,instrument,birthday
1,Bruce,vocals,1958-08
2,Steve,bass,1956-03
3,Adrian,guitar,1957-02
4,Dave,guitar,1956-12
5,Nicko,drums,1952-06
6,Janick,guitar,1957-01

Create a filter to find everyone who was born in 1956 and plays the bass:

{
  "instrument": "bass",
  "birthday": {
    "regex": "1956.*"
  }
}

By default you'll get a JSON document:

[
  {
    "id": "2",
    "name": "Steve",
    "instrument": "bass",
    "birthday": "1956-03"
  }
]

If you use CSV output with -F csv you'll get:

id,name,instrument,birthday
2,Steve,bass,1956-03