modestcsv
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

modestcsv

Minimalist objects to csv string composer -> one liner

Description

In memory minimalist CSV parser. It maps all properties from the given object to CSV columns

Install

npm i modestcsv yarn add modestcsv

Usage

toCSV

import csv from "modestcsv";

const item = {
  a: "b",
  c: "d",
};

const expectedResult = `a,c
b,d`;

const result = csv.toCSV(item);

expect(result).toEqual(expectedResult);

fromCSV

import csv from "modestcsv";

const input = `a,c
b,d`;

const expectedResult = [
  {
    a: "b",
    c: "d",
  },
];

const result = csv.fromCSV(input);

expect(result).toEqual(expectedResult);

API

modestcsv - CSV parser

Module exports:

const modestcsv: {
  toCSV: (input: any, options?: ObjCsvOptions | undefined) => string;
  fromCSV: (input: string, options?: ObjCsvOptions | undefined) => {};
};

Signature: toCSV(input[, options])

@input: JS object / Array.

@output: string

Signature: fromCSV(input[, options])

@input: JS string.

@output: object

The methods allow custom options:

type ObjCsvOptions = {
  delimiter?: string;
  includeHeaders?: boolean;
};

Default values are

property description default
delimiter the delimiter between the CSV columns ,
includeHeaders boolean indicating whether the column headers should be included or not true

Package Sidebar

Install

npm i modestcsv

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

8.75 kB

Total Files

9

Last publish

Collaborators

  • andreilucaci