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-json-to-csv-async

v1.0.5

Published

A Vue.js 2 component to transform and download a json in csv format. It also accepts promises as value.

Downloads

638

Readme

vue-json-to-csv-async

A Vue.js 2 component to transform and download a json in csv format https://github.com/nemanjagajic/vue-json-to-csv

Installation

npm install --save vue-json-to-csv-async or yarn add vue-json-to-csv-async

Usage

For vue-cli user:

import VueJsonToCsv from 'vue-json-to-csv-async'

If you just want to use component

import VueJsonToCsv from 'vue-json-to-csv-async/src/JsonToCsv'

For standalone usage:

<script src="vue.min.js"></script>
<!-- must place this line after vue.js -->
<script src="dist/vue-json-to-csv.min.js"></script>
<script type="text/javascript">
  Vue.use(VueJsonToCsv);
</script>

Sample 1 (simple use)

Simple usage: will generate a default button. The csv will include all the labels (name, surname) and the data

<vue-json-to-csv :json-data="[
    { name: 'Joe', surname: 'Roe' },
    { name: 'John', surname: 'Doe' }
  ]">
</vue-json-to-csv>

If you want, you can pass async function which will return an array instead of just passing plain array

<vue-json-to-csv :json-data-generator="getItemsToExport">
</vue-json-to-csv>

Result csv

csv.csv

| name | surname | |----------|------| | Joe | Roe | | John | Doe |

Sample 2 (filter labels)

Selected labels with custom csv title: will generate a custom button as defined at the slot. The csv will include only the "name" label with the "First name" title and the relevant data.

<vue-json-to-csv :json-data="[
    { name: 'Joe', surname: 'Roe' },
    { name: 'John', surname: 'Doe' }
  ]"
  :labels="{ name: { title: 'First name' } }"
  :csv-title="My_CSV"
  >
  <button>
    <b>My custom button</b>
  </button>
</vue-json-to-csv>

Result csv

My_CSV.csv

| First name | |----------| | Joe | | John |

Sample 3 (handle success/error, custom button, configure labels)

Handle success/error with custom button, returns specific labels with custom title: use of custom methods on success or error.

<vue-json-to-csv :json-data="[
    { name: 'John', surname: 'Doe', age: 20, salary: 20.000, hours: 37.4 },
    { name: 'John', surname: 'Roe', age: 40, salary: 40.000, hours: 35.2 },
    { name: 'Jane', surname: 'Woe', age: 50, salary: 52.000, hours: 30.4 }
  ]"
  :labels="{
    name: { title: 'First name' },
    salary: { title: 'Annual salary' },
    hours: { title: 'Hours/week' }
  }"
  @success="val => handleSuccess(val)"
  @error="val => handleError(val)">
  <button>
    <b>My custom button</b>
  </button>
</vue-json-to-csv>

Configuration

| Prop | Details | |----------|------| | json-data | Array of the objects which contain the data to display (required). Each key will be a different column at the csv. All the objects should contain the same keys. If empty array an error will be returned. Example: [ { name: 'Joe', surname: 'Roe' }, { name: 'Joe', surname: 'Doe' }]| | show-labels | Boolean. If false the first row of the csv will not contain the labels names. | | labels | An object of the keys of the labels will be displayed. Use to filter the keys to display and modify their label title. For each key we provide the title of the key to displayed. If not defined all the keys will be parsed. Example: { name: { title: 'First name' } }| | csv-title | String. The title of the generated csv. Default: 'csv' | | separator | String. The separator of the columns. Default: ',' | | @update:error | Will be triggered in case of an empty json array, if the labels object has not children or any parsing issue | | @update:success| Will be triggered in case of a successful csv creation |