indian-ocean

2019-12-03

indian-ocean是什么

什么是indian-ocean,A library for reading in and writing out data in Node.js.

indian-ocean使用教程帮助文档

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


上一篇:tktk
下一篇:party-time
相关文章

首次访问,人机识别验证

扫描下方二维码回复 1024 获取验证码,验证完毕后 永久 无须验证

操作步骤:[打开微信]->[扫描上侧二维码]->[关注 FedJavaScript 的微信] 输入 1024 获取验证码

验证码有误,请重新输入