Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

indian-ocean

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indian-ocean

A library for reading in and writing out data in Node.js.

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
752
increased by183.77%
Maintainers
1
Weekly downloads
 
Created
Source

Indian Ocean

A library for reading in and writing out data in Node.js, part of The TK Toolkit.

Installation

npm install indian-ocean

Usage

var io = require('indian-ocean');

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

console.log(json_data);

/*
[
  {
    "name": "Gerald",
    "occupation": "Teacher",
    "city": "Philadelphia"
  },
  {
    "name": "Marcy",
    "occupation": "Venture Capitalist",
    "city": "New York"
  }
]
/*

io.writeDataSync('path/to/save/output.json', json_data)

Methods

Reading data

Reads a variety of data file formats in as json.

.readData(filepath, [delimiter], callback)

Reads in a data file given a path ending in the file format. Callback structure is function(err, data).

Supported formats:

  • .json
  • .csv Comma-separated
  • .tsv Tab-separated
  • .psv Pipe-separated

Pass in a delimiter as the second argument to read in another format.

.readDataSync(filepath, [delimiter])

Syncronous version of .readData()

.readJson(filepath, callback)

Read in a json file. Callback structure is function(err, data).

.readJsonSync(filepath)

Read json syncronously.

.readCsv(filepath, callback)

Read in a comma-separated value file. Callback structure is function(err, data).

.readCsvSync(filepath)

Read csv syncronously.

.readTsv(filepath, callback)

Read in a tab-separated value file. Callback structure is function(err, data).

.readTsvSync(filepath)

Read tsv syncronously.

.readPsv(filepath, callback)

Read in a pipe-separated value file. Callback structure is function(err, data).

.readPsvSync(filepath)

Read psv syncronously.

Writing data

Writes json objects to the specified format.

.writeData(filepath, data, callback)

Write out the data object, inferring the file format from the file ending specified in filepath. Callback structure is function(err).

Supported formats:

  • .json
  • .csv Comma-separated
  • .tsv Tab-separated
  • .psv Pipe-separated

.writeDataSync(filepath, data)

Syncronous version of .writeData.

Helpers

.discernFormat(filepath)

Given a filepath return its file extension. Used internally by .discernPaser and .discernFileFormatter.

E.g. tk.discernFormat('path/to/data.csv') returns 'csv'

.discernParser(filepath, [delimiter])

Given a filepath, optionally a delimiter, return a parser that can read that file as json. Used internally by .readData and .readDataSync.

E.g.

var csvParser = tk.discernParser('path/to/data.csv');

var json = parser('path/to/data.csv');

.discernFileFormatter(filepath)

Returns a formatter that will format json data to file type specified by the extension in filepath. Used internally by .writeData and .writeDataSync.

E.g.

var formatter = tk.discernFileFormatter('path/to/data.tsv');
var csv = formatter(json);

TODO

  • Read/write dbf
  • tests

Keywords

FAQs

Package last updated on 12 May 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc