dsv-to-objects
convert dsv files to javascript objects
Last updated 4 years ago by nate.piche .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dsv-to-objects 
SYNC missed versions from official npm registry.

DSV to Objects

Easily convert DSV string, files, and online resources into an array of javascript objects. This will take the first line of your DSV file and use it as your new objects keys and every subsequent line will be converted to a new object.

Installation

Available through npm, just run npm install dsv-to-objects

Usage

The default delimiter will be a comma followed by NOT whitespace

var dsvToObjects = require('dsv-to-objects');

var string = 'foo,bar,baz\nlorem,ipsum,dolor';
var filePath = 'path/to/file.csv';
var url = 'http://download/file.csv';
var callback = function(body) {
  console.log(body);
}

// Call with a string
dsvToObjects.buildObjectsFromString(string);

// Call with a file path
dsvToObjects.buildObjectsFromFile(filePath);

// Call with a url, this is async and requires a callback and at least and empty options object
dsvToObjects.buildObjectsFromUrl(url, {}, callback);

#=> { "foo": "lorem", "bar": "ipsum", "baz": "dolor" }

All three methods also support an object of options

buildObjectsFromString(string, {delimiter: delimiter, toRemove: toRemove})

delimiter: whatever your chosen delimiter is, takes a string or regex

toRemove: an array of characters you want to remove from your dsv file

var dsvToObjects = require('dsv-to-objects');

var string = 'foo\tbar\tbaz\nAlorem\tAipsum\tAdolor';

// Call with string, tab delimited, and remove capital 'A' characters
dsvToObjects.buildObjectsFromString(string, {delimiter: "\t", toRemove: ["A"]);

#=> { "foo": "lorem", "bar": "ipsum", "baz": "dolor" }

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |