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-lite

v0.0.82

Published

CSV Reader/Writer (Supported Multibyte encodings)

Downloads

125

Readme

node-csv-lite

CSV Reader/Writer for Node.js

When you use browser, you can use csv-lite-js.

Install

$ npm install csv-lite

Usage

Simple static method:

var CSV = require('csv-lite');

// parse CSV string
var txt = "1,2,3\n11,22,33\n111,222,333";
var a = CSV.parse(txt);
console.log(a[0][0]); // 1
console.log(a[1][1]); // 22

// load from file
var a = CSV.readFileSync("test.csv", "Shift_JIS");
// save to file
CSV.writeFileSync("test.csv", a, "Shift_JIS");

OOP method:

var CSVObject = require('csv-lite').CSVObject;

var csv = new CSVObject();
csv.parse("name,age\r\nAki,14\r\nHuyu,20");
console.log(csv.getCell(1,0)); // Aki
console.log(csv.getCell(2,0)); // Huyu

// save
csv.writeFileSync("test.csv", "Shift_JIS")

// load
csv.readFileSync("test.csv", "Shift_JIS");
console.log(csv.getCell(1,0)); // Aki

Parse and Stringify

method:

  • CSV.parse()
  • CSV.stringify()

Parse CSV from text

var csv = "a,b,c\nd,e,f";
var a = CSV.parse(csv);
console.log(a[0][0]); // a
console.log(a[0][1]): // b
console.log(a[1][0]); // d
console.log(a[1][1]): // e

Stringify Array to CSV

var a = [[1,2,3],[4,5,6]]
var c = CSV.stringify(a);
console.log(c); // 1,2,3\n4,5,6

Load from file

  • CSV.readFileSync(filename, encoding)
  • CSV.readFile(filename, encoding, callback)

Save to file

  • CSV.writeFileSync(filename, data_ary, encoding)
  • CSV.writeFile(filename, encoding, callback)

TSV (Tab separated value)

// set tsv option
CSV.options.delimiter = "\t";
// load
var a = CSV.readFileSync(fname);

OOP method

  • CSVObject.toString()
  • CSVObject.parse(csv_str, delimiter)
  • CSVObject.getCell(row, col)
  • CSVObject.setCell(row, col, value)
  • CSVObject.setArray( array )
  • CSVObject.getArray()
  • CSVObject.find(colNo, keyword, offset)
  • CSVObject.findAll(colNo, keyword)
  • CSVObject.findAll(colNo, keyword, offset, limit)
  • CSVObject.filter(colNo, callback)
  • CSVObject.sort(colNo, isAsc)
  • CSVObject.sortNumber(colNo, isAsc)
  • CSVObject.insertRow(rowNo, rowArray)
  • CSVObject.insertCol(colNo, values)
  • CSVObject.deleteRow(rowNo)
  • CSVObject.deleteCol(colNo)
  • CSVObject.add(rowArray)
  • CSVObject.length
  • CSVObject.useHeader

Test module

$ mocha test/simple.js