Git Product home page Git Product logo

converter's Introduction

converter NPM version Build Status

Convert between XML, JSON and YAML, from one format to another.

Getting Started

To install the module, run the following in the command line:

npm i converter --save

Use within your application with the following line of JavaScript:

var converter = require('converter');

Calling var convert = converter(options); gives you a transform stream that will take in data and convert it based on the options passed in.

var fs = require('fs');
var converter = require('converter');

// get a file stream reader pointing to the csv file to convert
var reader = fs.createReadStream('path/to/csv/file.csv');

// get a file stream writer pointing to the json file to write to
var writer = fs.createWriteStream('path/to/output/json/file.json');

// setup the options for the data converter
var options = {
	from: 'csv',
	to: 'json'
};

// get a data converter stream using the given options
var convert = converter(options);

// pipe everything to do the conversion
reader.pipe(convert).pipe(writer);

Contributing

Find a bug? Have a feature request? Please create an Issue.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt, and build the documentation with grunt-readme.

Pull requests are also encouraged, and if you find this project useful please consider "starring" it to show your support! Thanks!

Author

Jon Schlinkert

Brian Woodward

Related

  • helpers: some great handlebars helpers that we decided not to include in the handlebars-helpers project, most likely because the code footprint was too big or the helper wasn't generic enough.

License

Copyright (c) 2014 Brian Woodward, contributors. Released under the license


This file was generated by grunt-readme on Monday, January 13, 2014.

converter's People

Contributors

chrmod avatar doowb avatar hariadi avatar jonschlinkert avatar spiralx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

converter's Issues

Use verb

Update to use verb and clean up documentation.

Conversion to YAML seems to be broken

/project/node_modules/converter/src/convert.js:233
		map[self.from][self.to](self.buffer, self.opts, function(err, data) {
		                       ^

TypeError: map[self.from][self.to] is not a function
    at Transform.Converter.self.stream._flush (/project/node_modules/converter/src/convert.js:233:26)
    at Transform.prefinish (_stream_transform.js:137:10)
    at emitNone (events.js:105:13)
    at Transform.emit (events.js:207:7)
    at prefinish (_stream_writable.js:592:14)
    at finishMaybe (_stream_writable.js:600:5)
    at endWritable (_stream_writable.js:611:3)
    at Transform.Writable.end (_stream_writable.js:562:5)
    at Stringifier.onend (_stream_readable.js:598:10)
    at Object.onceWrapper (events.js:314:30)

XML to CSV crash

/Users/philip/Desktop/node_modules/converter/src/convert.js:233
        map[self.from][self.to](self.buffer, self.opts, function(err, data) {
                               ^
TypeError: undefined is not a function
    at Transform.self.stream._flush (/Users/philip/Desktop/node_modules/converter/src/convert.js:233:26)
    at Transform.<anonymous> (_stream_transform.js:130:12)
    at Transform.g (events.js:199:16)
    at Transform.emit (events.js:104:17)
    at prefinish (_stream_writable.js:474:12)
    at finishMaybe (_stream_writable.js:482:7)
    at endWritable (_stream_writable.js:493:3)
    at Transform.Writable.end (_stream_writable.js:459:5)
    at ReadStream.onend (_stream_readable.js:505:10)
    at ReadStream.g (events.js:199:16)

refactor

@doowb I refactored this lib most of the way but I have to update unit tests etc. when I have some breathing room in the next couple of days I'll push up what I've done to a pr so we can discuss and change if necessary. feel free to remind me!

better CSV utils

Since CSV is a common format for importing data (e.g. product data, contact lists, etc), I think we need to find some solid tools for this. We might even need to use a different lib for reading vs. writing (since exporting to CSV will also be common).

JsonToCSV options ignored

Hi, i'm using this lib in order to convert all my i18n json translations files into one CSV. So, i need to use the JsonToCsv converter, using the semicolon as column separator.
I noticed that if i pass a custom options object to the lib in order to customize the column separator, this is ignored...
Going deep into the code, i noticed that the last commit 4d0f376 has introduced a bug for the JsonToCsv transformation, ignoring the options provided as input.

That commit changed the following code:

converter/src/convert.js

Lines 57 to 62 in 4d0f376

var convertJsonToCsv = function(data, options, done) {
data = JSON.parse(data);
csv.stringify(data, options.csv.stringify, function(err, output) {
done(null, output);
});
};

with the following, that ignore the input options parameter:

converter/src/convert.js

Lines 56 to 64 in e4ba9e0

var convertJsonToCsv = function(data, options, done) {
var results = '';
data = JSON.parse(data);
csv()
.from(data)
.to.string(function(results, count) {
done(null, results);
});
};

I verified that the bug could be solved simply passing the options.csv param to the .from() call, as already done in the following code:

converter/src/convert.js

Lines 47 to 54 in e4ba9e0

var convertCsvToJson = function (data, options, done) {
csv()
.from(data, options.csv)
.to.array(function(row) {
var results = JSON.stringify(row, null, options.indent);
done(null, results);
});
};

Could this fix be applied to the project?

No escaping of XML characters in PList output

When converting a JSON file to a PList, the string values in JSON aren't being escaped when they are converted to string tags in the PList. E.g. if I convert one of my package.json files with this line

"author": "James Skinner <[email protected]> (https://github.com/spiralx)",

then in the output PList it becomes

<string>James Skinner <spiralx@gmail.com> (https://github.com/spiralx)</string>

which contains < and > instead of their XML entities, and makes the whole PList an invalid document. At the very least it should escape <, > and &.

Oddly enough when I convert the same package.json to XML, the output is escaped fine:

<author>James Skinner &lt;[email protected]&gt; (https://github.com/spiralx)</author>

Better error handling.

  • Throw error on unsupported conversions
  • Provide more information when errors are captured in streams.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.