@calipsa/array-to-csv

Convert array to CSV

Usage no npm install needed!

<script type="module">
  import calipsaArrayToCsv from 'https://cdn.skypack.dev/@calipsa/array-to-csv';
</script>

README

@calipsa/array-to-csv

NPM version Downloads Dependency status Dev Dependency status

Installation

# using npm:
npm install --save @calipsa/array-to-csv

# or if you like yarn:
yarn add @calipsa/array-to-csv

Usage

import arrayToCsv from '@calipsa/array-to-csv'

const columns = [
  'col1',
  'col2',
  {
    key: 'col3',
    label: 'Column 3',
  },
  {
    key: 'col4',
    label: 'Column 4 (uppercase)',
    transform: (val) => val.toUpperCase(),
  },
]

// get the converter
const toCsv = arrayToCsv(columns)
// get the csv
const result = toCsv(list)
console.log(result)