npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-csv-import

v4.1.2

Published

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

Downloads

10,244

Readme

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

Latest Version on NPM Software License CircleCI Scrutinizer Code Quality

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

VueCsvImport is completely un-styled and customizable. All markup can be replaced and all text can be customized.

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

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