Coder Social home page Coder Social logo

fromcsv's Introduction

FromCsv

NPM version Build Status

This module implements an engine for CSV importing.

Compared to other such importers, this lirary is intended to be far more versataile particularly when it comes to situations encountered by users with the matching of CSV data using a hash.

Common user cases

Missing values

Rows with empty data are competely excluded from the upload. If there are no values within a columns that would otherwise be unmatched then that column is ignored.

Missing columns

Missing columns are not considered a reason to abort processing the file.

Reordered columns

Columns can be uploaded in any order.

Unmatched columns

Columns without a match are recorded and be default a file cannot be uploaded with partial matches. Instead a data structure is returned which the caller must validate.

Usage

The engine is ready for use by creating an instance:

const FromCsv = require("fromcsv");

const importer = new FromCsv({
  dialects: {
    some_format: {
      columpMap: {
        "First Column": null,
        "Second Column": null
      }
    }
  }
});

This creates an instance of the importer that can be used to match CSV files of the "some_format" of CSV files. The same instance can be reused for each attempt to process files with the same columns.

fromStream

A text stream containing CSV data can be processed by passing it directly to the fromStream method:

const fs = require("fs");

const inputStream = fs.createReadStream("/path/to/file.csv");

importer.fromStream(inputStream, (err, output) => {
  // ...
});

fromData

To submit an unsuccessful payload to the server to be processed again, the fromData method is used:

const data = {
  header: ["Title", "Surname"],
  rows: [["Mr.", "Smith"], ["Mrs.", "Smith"]]
};

importer.fromData(data, (err, output) => {
  // ...
});

fromcsv's People

Watchers

James Cloos avatar

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.