Socket
Socket
Sign inDemoInstall

modestcsv

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    modestcsv

Minimalist objects to csv string composer


Version published
Maintainers
1
Install size
8.55 kB
Created

Readme

Source

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

propertydescriptiondefault
delimiterthe delimiter between the CSV columns,
includeHeadersboolean indicating whether the column headers should be included or nottrue

Keywords

FAQs

Last updated on 12 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc