GithubHelp home page GithubHelp logo

csvparser's Introduction

CSVParser

Drag 'n drop CSV parser

##Usage

Instantiate CSVParser with a config, the config should be structured as follows:

var CSVParser = require('csvparser');

var myConfig = {
	rules: myRules,
	tests: myTests,
	target: myTarget, // optional
	options: myOptions // optional
}

var myParser = new CSVParser(myConfig);

###rules

CSVParser uses rules to test and parse all values in your CSV. For each field in your CSV you must define a rule to tell CSVParser how to handle it.

var myRules = {
	id: 'string',
	name: 'string',
	age: 'number',
	married: 'boolean',
	birthday: 'date',
	department: 'departmentId'
}

###tests

CSVParser has a few built-in tests:

  • boolean
  • date
  • number
  • string
  • timeString

You are free to create your own. It will need a test and parse function.

var myTests = {
	departmentId:
		test: function (value) { return departmentData.hasOwnProperty(value); },
		parse: function (value) { return value; }
	}
}

###target

CSVParser will create a table to show the result of validation of the parsed data. Provide a DOM element so it can appear in your page.

var myTarget = document.getElementById('personnelTarget');

###options

CSVParser has a few options that you can set:

  • allowNull: boolean, defaults to true - null values are acceptable in all fields.
  • allowUndefined: boolean, defaults to true - undefined values are acceptable in all fields.
  • empty: defaults to undefined - What you want to replace empty values with.
  • optional: array of keys - Which keys are optional, by default all keys are required.
  • rotate: boolean, defaults to false - treats rows as columns and columns as rows.
  • unique: number, string, or array of strings. - which fields represent the unique key for a row. defaults to the first field.

csvparser's People

Contributors

bjornstar avatar christopherobin avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

csvparser's Issues

Parse unix timestamps by default

It seems the built in date parser is pretty useless, we should replace it with one that we actually want to use.

This is the primary candidate:

module.exports = {
    test: function (value) {
        return !isNaN(new Date(value));
    },
    parse: function (value) {
        return Math.floor(Date.parse(value) / 1000);
    }
};

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.