Skip to content

A library for reading in and writing out data (plus some useful filesystem functions) in Node.js.

License

Notifications You must be signed in to change notification settings

mhkeller/indian-ocean

Repository files navigation

Indian Ocean

Travis (.org) branch npm version npm js-standard-style

A Node.js library for reading in and writing out data plus some other useful filesystem functions.

Documentation

See the full API docs.

Currently supports:

  • csv
  • tsv
  • psv
  • text
  • json
  • dbf
  • aml - ArchieML
  • Custom delimeters

Plus a number of file system convenience functions.

Installation

npm install --save indian-ocean

Usage

var io = require('indian-ocean')

var json_data = io.readDataSync('path/to/data.csv')

console.log(json_data)

/*
[
  {
    "name": "Gerald",
    "city": "Los Angeles"
  },
  {
    "name": "Marcy",
    "city": "Tuscaloosa"
  }
]
*/

io.writeDataSync('path/to/save/output.json', json_data, { indent: 2 })

Or, combine methods to read in a directory of csvs as json:

var io = require('indian-ocean')

// Let's say this directory contains two csvs, each with two rows like the above example
var csvs = io.readdirFilterSync('csvs-folder', { include: 'csv', fullPath: true }).map(io.readDataSync)

console.log(csvs)

/*
[
  [
    {
      "name": "Gerald",
      "city": "Los Angeles"
    },
    {
      "name": "Marcy",
      "city": "Tuscaloosa"
    }
  ],
  [
    {
      "name": "Liza",
      "city": "Minneapolis"
    },
    {
      "name": "Eileen",
      "city": "Mobile"
    }
  ]
]
*/

// Concatenate them into one file with Javascript's Array.flat() method and write out one combined csv
io.writeDataSync('single-file.csv', csvs.flat())

/*
name,city
Gerald,Los Angeles
Marcy,Tuscaloosa
Liza,Minneapolis
Eileen,Mobile
*/

License

MIT