1.0.9 • Published 2 years ago

wrangle-csv v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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
1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago