Coder Social home page Coder Social logo

dataimport's Introduction

DataImport.js

Simple JavaScript browser-based CSV importer.

Inspired by Patrick McKenzie's Design and Implementation of CSV/Excel Upload for SaaS. DataImport is built on top of Handsontable and lets you do CSV input data pre-validation in the browser.

Demo on JSFiddle (Click Run or Cmd/Ctrl + Enter to launch it)

Example

var is = DataImport.is;

var containerElement = document.getElementById("handsontable-element");

var dataimport = new DataImport(containerElement, {
  fields: [{
    id: "fullName",
    name: "Full Name",
    required: true
  }, {
    id: "birthday",
    name: "Birthday",
    required: false,
  }, {
    id: "contactType",
    name: "Contact Type",
    required: true,
    choices: ["work", "home"],
    validate: [
      is.anyOf(["work", "home"], "Wrong value")
    ]
  }, {
    id: "email",
    name: "Email",
    required: true,
    validate: [
      is.unique(),
      is.matchingRegex(["[^@]+@[^\.]+\..+"], "Incorrect Email Address")
    ]
  }],
  // ...
});

dataimport.validate({
  complete: function (result) {
    console.log(result);
  },
  fail: function (errors) {
    console.log(errors);
  }
});

How it works

Here's what happens in the demo.

  1. When the user adds a CSV file the fields in the file are matched to the fields described in DataImport. This example uses Papa Parse to load the data from CSV and Fuse.js to do fuzzy matching of fields.

alt text

  1. If needed the user can fix automatic matching by selecting a proper field from the dropdown.

alt text

  1. When the user clicks Validate, DataImport checks the data and displays the errors.

alt text

  1. When there are no errors DataImport.validate calls complete callback with resulting data (array of arrays). This is your parced CSV data.

Check Demo on JSFiddle (Click Run or Cmd/Ctrl + Enter to launch it)

dataimport's People

Contributors

burnash avatar

Stargazers

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

Watchers

 avatar  avatar  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.