wrangle-csv

1.0.9 • Public • Published

npmCodacy BadgeMaintainability

wrangle-csv

CSV wrangler to transform CSV into JSON object optimized for display in webapps, or JSON object of arrays optimized for interaction with a python/pandas/scikit/tensorflow backend via HTTP requests.

Example imports:

Traditional JavaScript

const fs = require("fs");
const wrangle = require("wrangle-csv");

const csvFile = fs.readFile("c:/path/to/your/file.csv");
const jsonArray = wrangle.csvToJsonArr(csvFile);
const jsonObject = wrangle.csvToJsonObj(csvFile);

Typescript

import * as fs from "fs";
import { csvToJsonArr, csvToJsonObj } from "wrangle-csv";

const csvFile = fs.readFile("c:/path/to/your/file.csv");
const jsonArray = csvToJsonArr(csvFile);
const jsonObject = csvToJsonObj(csvFile);

Methods

Assumes the following structure: 1st row = headers 1st column = label/indexing

CSV to JSON structured as arrays

csvToJsonArr(file, sep, newLine)

  • file: accepts string
  • sep (separator): default ,
  • newLine: default /n Returns a JSON object with each row arranged as an array

CSV to JSON object

csvToJsonObj(file, sep, newLine)

  • file: accepts string
  • sep (separator): default ,
  • newLine: default /n Returns a JSON object

TODO

  • Error handling
  • Remove duplication and refactor

Package Sidebar

Install

npm i wrangle-csv

Weekly Downloads

1

Version

1.0.9

License

MIT

Unpacked Size

8.32 kB

Total Files

5

Last publish

Collaborators

  • neonspork