All Projects → jgile → Vue Csv Import

jgile / Vue Csv Import

Licence: mit
Vue.js component to select a CSV file, map the columns to fields, and post it somewhere.

Projects that are alternatives of or similar to Vue Csv Import

Actions Package Update
keeps npm dependencies up-to-date by making pull requests from GitHub Actions or CI.
Stars: ✭ 36 (-62.11%)
Mutual labels:  npm, npm-package
Packagephobia
⚖️ Find the cost of adding a new dependency to your project
Stars: ✭ 1,110 (+1068.42%)
Mutual labels:  npm, npm-package
Nls
Missing inspector for npm packages.
Stars: ✭ 44 (-53.68%)
Mutual labels:  npm, npm-package
Np
A better `npm publish`
Stars: ✭ 6,401 (+6637.89%)
Mutual labels:  npm, npm-package
Minimal Feedback
🗳 minimal-feedback is a blazingly fast and highly customizable component to get user feedback.
Stars: ✭ 78 (-17.89%)
Mutual labels:  npm, npm-package
Eslint Plugin Node
Additional ESLint's rules for Node.js
Stars: ✭ 740 (+678.95%)
Mutual labels:  npm, npm-package
Awesome Node Utils
some useful npm packages for nodejs itself
Stars: ✭ 51 (-46.32%)
Mutual labels:  npm, npm-package
Vanilla Framework
From community websites to web applications, this CSS framework will help you achieve a consistent look and feel.
Stars: ✭ 476 (+401.05%)
Mutual labels:  npm, npm-package
Incompose
A inferno utility belt for function components and higher-order components
Stars: ✭ 76 (-20%)
Mutual labels:  npm, npm-package
Vue Scroll Progress Bar
Vue.js plugin for page scroll progress bar
Stars: ✭ 76 (-20%)
Mutual labels:  npm-package, vuejs2
Event Target Shim
An implementation of WHATWG EventTarget interface, plus few extensions.
Stars: ✭ 89 (-6.32%)
Mutual labels:  npm, npm-package
Node Fast Ratelimit
☔️ Fast and efficient in-memory rate-limit for Node, used to alleviate most common DOS attacks.
Stars: ✭ 84 (-11.58%)
Mutual labels:  npm, npm-package
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+593.68%)
Mutual labels:  npm, npm-package
Yarpm
CLI tool to run npm scripts with either npm or yarn, depending on how it was started
Stars: ✭ 13 (-86.32%)
Mutual labels:  npm, npm-package
Synp
Convert yarn.lock to package-lock.json and vice versa
Stars: ✭ 510 (+436.84%)
Mutual labels:  npm, npm-package
React Use Api
Async HTTP request data for axios. Designed for diverse UI states, SSR and data pre-caching.
Stars: ✭ 49 (-48.42%)
Mutual labels:  npm, npm-package
Node Thermal Printer
This npm package was made to control epson and star thermal printers
Stars: ✭ 424 (+346.32%)
Mutual labels:  npm, npm-package
Npm Run All
A CLI tool to run multiple npm-scripts in parallel or sequential.
Stars: ✭ 4,496 (+4632.63%)
Mutual labels:  npm, npm-package
Package.json
文件 package.json 的说明文档。
Stars: ✭ 67 (-29.47%)
Mutual labels:  npm, npm-package
Webcam Easy
javascript access webcam stream and take photo
Stars: ✭ 79 (-16.84%)
Mutual labels:  npm, npm-package

Vue.js component to handle CSV uploads with field mapping.

Latest Version on NPM Software License CircleCI Scrutinizer Code Quality

VueCsvImport is a completely un-styled, customizable, and modular CSV mapping component. It allows you to upload a CSV, and map the CSV to pre-defined fields.
All markup and text can be replaced and/or customized. This is a complete rebuild for Vue 3 and will NOT work with your old markup from Vue 2.

This version is for Vue 3. Click here for Vue 2.

Demo


Installation

You can install the package via npm or yarn:

# npm
npm install vue-csv-import

# Yarn
yarn add vue-csv-import

You can import components individually.

import {VueCsvToggleHeaders, VueCsvSubmit, VueCsvMap, VueCsvInput, VueCsvErrors, VueCsvImport} from 'vue-csv-import';

Or import all as a plugin.

import {createApp} from "vue";
import App from "./App.vue";
import {VueCsvImportPlugin} from "vue-csv-import";

createApp(App)
    .use(VueCsvImportPlugin)
    .mount("#app");

A minimal working example with all components will look something like this:

<template>
    <vue-csv-import
        v-model="csv"
        :fields="{name: {required: false, label: 'Name'}, age: {required: true, label: 'Age'}}"
    >
        <vue-csv-toggle-headers></vue-csv-toggle-headers>
        <vue-csv-errors></vue-csv-errors>
        <vue-csv-input></vue-csv-input>
        <vue-csv-map></vue-csv-map>
    </vue-csv-import>
</template>

Components

  • VueCsvImport - The primary component wrapper. All other components should be used within this component.
  • VueCsvToggleHeaders - Toggles whether CSV should be read as having headers or not.
  • VueCsvInput - The file input field to upload your CSV
  • VueCsvMap - Used to map CSV columns to your fields
  • VueCsvSubmit - Used to POST the mapped CSV.
  • VueCsvErrors - Used to display errors.

VueCsvImport

Primary wrapper component.

<template>
    <vue-csv-import
        v-model="csv"
        :fields="{
            name: {
                required: false,
                label: 'Name'
            },
            age: {
                required: true,
                label: 'Age'
            }
        }"
    >
        <!-- Other Components -->
    </vue-csv-import>
</template>

Props:

Prop Default Description
fields null (required) The field names used to map the CSV.
text see below (optional) Override the default text used in the component.
modelValue N/A (optional) Binds to the mapped CSV object.

Default text

{
    "errors": {
        "fileRequired" : "A file is required",
        "invalidMimeType" : "Invalid file type"
    },
    "toggleHeaders": "File has headers",
    "submitBtn": "Submit",
    "fieldColumn": "Field",
    "csvColumn": "Column"
}

Slot Props:

Prop Description
file The selected file
errors Current errors
fields The fields object

VueCsvToggleHeaders

Allows user to toggle whether the CSV has headers or not.

<template>
    <vue-csv-import>
        ...
        <vue-csv-toggle-headers></vue-csv-toggle-headers>
        ...
    </vue-csv-import>
</template>

Or with custom markup:

<template>
    <vue-csv-import>
        ...
        <vue-csv-toggle-headers v-slot="{hasHeaders, toggle}">
            <button @click.prevent="toggle">Has Headers</button>
        </vue-csv-toggle-headers>
        ...
    </vue-csv-import>
</template>

Props:

Prop Default Description
checkboxAttributes {} (optional) Attributes to bind to the checkbox.
labelAttributes {} (optional) Attributes to bind to the label.

Slot Props:

Prop Description
hasHeaders Whether CSV is marked as having headers.
toggle Toggle the 'hasHeaders' value.

VueCsvInput

The file field for importing CSV.

<template>
    <vue-csv-import>
        ...
        <vue-csv-input name="file"></vue-csv-input>
        ...
    </vue-csv-import>
</template>

Or with custom markup:

<template>
    <vue-csv-import>
        ...
        <vue-csv-input v-slot="{file, change}">
            ...
        </vue-csv-input>
        ...
    </vue-csv-import>
</template>

Props:

Prop Default Description
name N/A (required) The field names used to map the CSV.
headers true (optional) Override the default text used in the component.
parseConfig N/A (optional) Papaparse config object.
validation true (optional) Use validation or not
fileMimeTypes ["text/csv", "text/x-csv", "application/vnd.ms-excel", "text/plain"] (optional) Accepted CSV file mime types.

Slot Props:

Prop Description
file The current file object
change Change the file

VueCsvMap

Component to map the CSV to the specified fields.

<template>
    <vue-csv-import>
        ...
        <vue-csv-map></vue-csv-map>
        ...
    </vue-csv-import>
</template>

Or use slot for custom markup:

<template>
    <vue-csv-import>
        ...
        <vue-csv-map v-slot="{sample, map, fields}">
            ...
        </vue-csv-map>
        ...
    </vue-csv-import>
</template>

Props:

Prop Default Description
noThead false (optional) Attributes to bind to the checkbox.
selectAttributes {} (optional) Attributes to bind to the select fields.
autoMatch true (optional) Auto-match fields to columns when they share the same name
autoMatchIgnoreCase true (optional) Ignore case when auto-matching

Slot Props:

Prop Description
sample The first row of the CSV.
map The currently mapped fields.
fields The fields.

VueCsvSubmit

Displays a button to post the CSV to specified URL.

<template>
    <vue-csv-import>
        ...
        <vue-csv-submit url="/post/here"></vue-csv-submit>
        ...
    </vue-csv-import>
</template>

Or use slot for custom markup:

<template>
    <vue-csv-import>
        <vue-csv-submit v-slot="{submit, mappedCsv}">
            <button @click.prevent="submit">Submit!!</button>
        </vue-csv-submit>
    </vue-csv-import>
</template>

Props:

Prop Default Description
url N/A (required) Where to post the CSV.

Slot Props:

Prop Description
submit Submit the CSV (POST)
mappedCsv The mapped CSV object

VueCsvErrors

Displays any error messages.

<template>
    <vue-csv-import>
        ...
        <vue-csv-errors></vue-csv-errors>
        ...
    </vue-csv-import>
</template>

Or use slot for custom markup:

<template>
    <vue-csv-import>
        ...
        <vue-csv-errors v-slot="{errors}">
            ...
        </vue-csv-errors>
        ...
    </vue-csv-import>
</template>

Slot Props:

Prop Description
errors Object containing errors

Testing

npm run test

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please contact John Gile.

License

The MIT License (MIT). Please see License File for more information.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].