Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 1 addition & 138 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,138 +1 @@
[@flatfile/adapter](README.md) › [Globals](globals.md)

# @flatfile/adapter

# Flatfile.io CSV Importer Adapter

[![Build Status](https://travis-ci.org/FlatFilers/Adapter.svg?branch=master)](https://travis-ci.org/FlatFilers/Adapter)
[![Codecov](https://img.shields.io/codecov/c/github/FlatFilers/Adapter.svg)](https://codecov.io/gh/FlatFilers/Adapter)
[![NPM version](https://img.shields.io/npm/v/typescript-starter.svg)](https://www.npmjs.com/package/typescript-starter)
[![Standard Version](https://img.shields.io/badge/release-standard%20version-brightgreen.svg)](https://github.com/conventional-changelog/standard-version)
[![dependencies Status](https://david-dm.org/flatfilers/adapter/status.svg)](https://david-dm.org/flatfilers/adapter)
[![devDependencies Status](https://david-dm.org/flatfilers/adapter/dev-status.svg)](https://david-dm.org/flatfilers/adapter?type=dev)

A simple adapter for elegantly importing CSV files via [flatfile.io](https://www.flatfile.io) (Typescript, ES6, Browser)

Read the developer docs → https://developers.flatfile.io/docs/install

![Preview](https://flatfile.io/img/preview.png)

> **License Key**
>
> In order to setup, you need to [create or sign in to your flatfile.io account](https://flatfile.io) and obtain a license key.

## Using NPM

If you don't like external dependencies, or you have a nice build system like Webpack in place. You can install and use Flatfile as an npm package.

```sh
npm install flatfile-csv-importer --save
```

## Using CDN

The latest version of the package is available via CDN so you can just drop it into your website and start using it.

```sh
https://unpkg.com/flatfile-csv-importer/build/dist/index.min.js
```

## Quickstart
Add the following code before the ending `</body>` tag in your html.

```js

<script src="https://unpkg.com/flatfile-csv-importer/build/dist/index.min.js"></script>

<script>
var LICENSE_KEY = 'PASTE YOUR KEY HERE'

var importer = new FlatfileImporter('demo-account', {
fields: [{
label: 'Robot Name',
key: 'name'
}, {
label: 'Shield Color',
key: 'shieldColor',
validator: /^[a-zA-Z]+$/
}, {
label: 'Robot Helmet Style',
key: 'helmetStyle',
}, {
label: 'Call Sign',
key: 'sign',
alternates: ['nickname', 'wave'],
validator: /^\w{4}$/
}],
type: 'Robot'
})

importer.requestDataFromUser().then(function(results) {
importer.displayLoader()

// replace this setTimeout with an ajax request to your server with the data
doSomethingWithYourData(results.data).then(function() {
importer.displaySuccess()
})
})

/**
* Use this function to do something with your data like upload it your server
*
* @param data An array of objects matching your earlier configuration
* [
* {
* name: 'R2D2',
* shieldColor: 'blue',
* helmetStyle: 'awesome',
* callSign: 'beep'
* }
* ...
* ]
*/
function doSomethingWithYourData (data) {

}

</script>
```

## ES6 / Babel

```js
import FlatfileImporter from 'flatfile-csv-importer'
import $ from 'jquery'

// configure your flatfile options here
const options = {}

// Obtain your license key from https://flatfile.io
const LICENSE_KEY = 'PASTE YOUR KEY HERE'

// initialize the importer
const importer = new FlatfileImporter(FLATFILE_LICENSE_KEY, options)

// setup your handler
const buttonClickHandler = async () => {
try {
const response = await importer.requestDataFromUser()
await uploadYourData(response.data)
} catch(e) {
// handle a failed upload
}

}

const uploadYourData = (data) => {
// logic here to upload the clean data your server
}

$("#upload-button").click(buttonClickHandler)
```

## Promise Overrides
Flatfile includes a basic native compatible Promise shim for IE support. You can override this with your preferred library by using the following global setting:

```js
FlatfileImporter.Promise = Bluebird.Promise
```
sinanews://sina.cn/article/detail.pg?newsId=icezzrq2972023-comos-tech-cms&dataid=comos:icezzrq2972023&pkey=default&skipAd=0&backUrl=%257B%2522needBackConfig%2522%253A%25221%2522%257D&k=sinawap_clip*tech*tech*wm_art_icezzrq2972023_uid*SN_7575001*1654835204435*https%3A%2F%2Ftech.sina.cn%2Fmobile%2Fxp%2F2019-09-03%2Fdetail-iicezzrq2972023.d.html%3Ffrom%3Dwap*ustat___187.189.146.86_1654835164_0.86833300_end*%7B%22ref%22%3A%22-%22%2C%22dataid%22%3A%22comos%3Aicezzrq2972023%22%2C%22pageDataid%22%3A%22comos%3Aicezzrq2972023%22%2C%22pkey%22%3A%22-%22%2C%22tjShowType%22%3A%22%22%2C%22fromSN%22%3A%22SN_7575%22%2C%22sid%22%3A%22644960857166.2635.1654835167861%22%2C%22pageType%22%3A%22art%22%2C%22channel%22%3A%22tech%22%2C%22backId%22%3A%22%22%2C%22browser%22%3A%22HuaweiBrowser%22%2C%22gkid%22%3A%223002%22%2C%22qeid%22%3A%22%22%2C%22other%22%3A%22%22%2C%22issmallpackage%22%3A%220%22%2C%22qetype%22%3A%22%22%2C%22gbreq%22%3A1%2C%22platform%22%3A%22Linux%20aarch64%22%2C%22device%22%3A%22Mobile%22%2C%22isautocall%22%3A0%7D&percent=0.687&ustat=__187.189.146.86_1654835164_0.86833300&opid=16548352044461436959