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

easy-csv2json

v1.2.1

Published

Easiest way to convert CSV files to JSON

Downloads

17

Readme

Easy CSV2JSON

Do you need to process CSV files like a PRO!?

This NPM provides the best way to convert from simple CSV file to JSON and giving you some valuable and useful metadata for querying the results and functions that allows modify, filter, and sort data.

Currently available

  • Modify data using custom functions colum-row pair .setVal('b4', 'hello');
  • Formulas .applyFormula('B3', function)
  • Filter data by column .filterVal('B', function)

Coming soon functionalities

  • Sort data .sort('B', 'ASC')
  • Apply formulas to row sets
  • Save csv file
  • Transform to excel datasheet

How to install?.

see package on npmjs.com

npm i easy-csv2json

Simple use of the package

EasyCSV2JSON.convert

import { EasyCSV2JSON, EasyCSV2JSONInput } from 'easy-csv2json/lib';

// ...

const fs = require('fs');
const filePath = join(documents, 'myFile.csv');
const ab = fs.readFileSync(filePath);
const eCsv = new EasyCSV2JSON();
await eCsv.init({
  file: ab,
  charSep: ',',
  headers: false,
  metadata: false,
} as EasyCSV2JSONInput);

const data = await eCsv.convert();
const filteredData: EasyCSV2JSON = await eCsv.filterFn('B', (value) =>
  new RegExp(/onion/i).test(value),
);

console.log(data);
console.log(await filteredData.convert());

Result json

[
  ["id", "name", "price", "stock"],
  [0, "YAM 1000g", 1.22, 1],
  [2, "GARLIC MESH 500g", 0.97, 1],
  [3, "BROCOLI 1000 g", 1.64, 1],
  [4, "SWEET POTATO 1000g", 1.47, 1],
  [5, "WHITE ONION 1000g", 1.16, 1],
  [6, "RED ONION 1000g", 3.01, 1],
  [7, "GINGER 1000g", 3.81, 1],
  [8, "CUCUMBER 1000 g", 0.49, 1]
]

More output samples here

📤 See more to samples here

Parameter options

| Parameter | type | description | | --------- | ----------- | -------------------------------------- | | file | ArrayBuffer | CSV file BufferArray | | charSep | string | Char separator | | headers | boolean | The file contains headers true / false | | metadata | boolean | Show metadata in the output JSON |

⚠️ IMPORTANT!

When you use headers, if a header name is repeated the second one is renamed using a numeric postfix. Eg: if there are two columns called price the second one becomes into price1

Metadata provided.

| Meta | Type | value | | ------ | ---------------------- | ----------------------------------------- | | value | string, number or date | Typed value of the cell | | type | string | Type of the value, string, number or date | | column | string | Excel styled columns, eg: A, B, C | | row | number | Reference to the number of row, eg: 1,2,3 |

Methods

See methods documentation here

EasyCSV2JSON used as a instanced class provide the following methods.

const eCsv = new EasyCSV2JSON();
await eCsv.init(options):
await eCsv.getTable();
await eCsv.convert();
await eCsv.val('B8');
await eCsv.setVal('b4', 'hello');
await eCsv.cell('a1');
await eCsv.applyFormula('B3', fn: (value: any, $this: EasyCSV2JSON) => Promise<any>)
await eCsv.filterVal('B', 'BROCOLI 1000 g', <options>)
await eCsv.filterFn('B', value => new RegExp(/A/i).test(value), <options>),

Status

Project: in progress Thank you for using this NPM

Stay in touch

License

This software is licensed under MIT License

November 2020