1.0.7 • Published 4 years ago

read-csv-sync v1.0.7

Weekly downloads
71
License
ISC
Repository
github
Last release
4 years ago

read-csv-sync

Module to read .csv files synchronously

Index

Install

Basic Usage

Optional parameters

Examples

Install

$ npm install read-csv-sync

Basic Usage

Reading a file called example.csv

const  {readCSVSync}  =  require("read-csv-sync")

  

console.log(readCSVSync("./example.csv"))

You can assign the result into a variable, like this:

const  {readCSVSync}  =  require("read-csv-sync")

  
  

const data =  readCSVSync("./example.csv");

  

console.log(data)

Optional parameters

You can pass optional parameters on function call, those are "separator" (default = ',') and "encoding" (default = 'utf-8').

Syntax:

readCSVSync(path, separator, encoding)

Examples

Input:

NAME,LEG_LENGTH,DIET

Hadrosaurus,1.2,herbivore

Struthiomimus,0.92,omnivore

Velociraptor,1.0,carnivore

Triceratops,0.87,herbivore

Euoplocephalus,1.6,herbivore

Stegosaurus,1.40,herbivore

Tyrannosaurus Rex,2.5,carnivore

Output:

[

{ NAME: 'Hadrosaurus', LEG_LENGTH: '1.2', DIET: 'herbivore' },

{ NAME: 'Struthiomimus', LEG_LENGTH: '0.92', DIET: 'omnivore' },

{ NAME: 'Velociraptor', LEG_LENGTH: '1.0', DIET: 'carnivore' },

{ NAME: 'Triceratops', LEG_LENGTH: '0.87', DIET: 'herbivore' },

{ NAME: 'Euoplocephalus', LEG_LENGTH: '1.6', DIET: 'herbivore' },

{ NAME: 'Stegosaurus', LEG_LENGTH: '1.40', DIET: 'herbivore' },

{ NAME: 'Tyrannosaurus Rex', LEG_LENGTH: '2.5', DIET: 'carnivore' }

]
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago