Git Product home page Git Product logo

gulp-csvtojson's Introduction

gulp-csvtojson Build Status

gulp plugin to wrap csvtojson

Install

$ npm install --save-dev gulp-csvtojson

Usage

Here is the code snippet for general usage which generate json for you.

var gulp = require('gulp');
var csvtojson = require('gulp-csvtojson');

gulp.task('default', function () {
    return gulp.src('src/file.csv')
        .pipe(csvtojson({ toArrayString: true }))
        .pipe(gulp.dest('dist'));
});

Here is the code snippet for generating js file.

var gulp = require('gulp');
var csvtojson = require('gulp-csvtojson');
var insert = require('gulp-insert');
var ext_replace = require('gulp-ext-replace');

gulp.task('default', function () {
    return gulp.src('src/file.csv')
        .pipe(csvtojson({ toArrayString: true }))
        .pipe(insert.prepend('var anyVariable = '))
        .pipe(insert.append(';'))
        .pipe(ext_replace('.js'))
        .pipe(gulp.dest('dist'));
});

Options

Refer to this list for full options.

Note: to get a valid json file, you need set toArrayString to true.

API

Since v0.2.0, API no longer supported, to achieve the same result, please adapt your code according to the second code snippet.

License

MIT © Icer

gulp-csvtojson's People

Contributors

tjchaplin avatar wizicer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tjchaplin

gulp-csvtojson's Issues

The plugin fails with big CSV files.

I attempted to use gulp-csvtojson with a CSV file that was approximately 300MB in size. This causes gulp-csvtojson to crash. The problem seems to be that gulp-csvtojson attempts to read the entire file into a string which fails if the file size exceeds the maximum string length.

Contributor and NPM publish access to csvToJson contributors

As this plugin is specific to csvtojson. I thought it might be useful to give the csvtojson contributors rights to this project.

In addition, they can add it to the readme of csvtojson to indicate a plugin exists.

Is this something you would want to do?

Remove option to create JS file

Further reviewing the code...it seems like there are too many paths for the plugin. Ideally there should be a single purpose; i.e. stream csvtojson module using gulp. The current plugin is streaming, but also will create a js file depending on options. The creation of a JS file could(should) be done in a different plugin. Here is the gulp plugin guidelines which provides a little more detail: Gulp Plugin Guidelines

I will open up another issue to discuss further.

Here is what currently exists:

var gulp = require('gulp');
var csvtojson = require('gulp-csvtojson');

gulp.task('default', function () {
    return gulp.src('src/file.csv')
        .pipe(csvtojson())
        .pipe(gulp.dest('dist'));
});

I think this should be:

var gulp = require('gulp');
var csvtojson = require('gulp-csvtojson');
var insert = require('gulp-insert'); //module to insert into streamed data


gulp.task('default', function () {
    return gulp.src('src/file.csv')
        .pipe(csvtojson())
        .pipe(insert.prepend('var anyVariable = '))
        .pipe(insert.append(';'))
        .pipe(gulp.dest('dist'));
});

Gulp Insert plugin

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.