CSVx.js is an open source CSV library written in TypeScript

Overview

This project has been transferred to DWTechs.

Please update your project dependencies to the latest version from the new repository.

License: MIT npm version last version release date Jest:coverage minified size

Synopsis

CSVx.js is an open source CSV library written in TypeScript.

Motivation

The main purpose of this library is to provide an easy way to export your data as CSV or transform your CSV data to something else.

Installation

npm

$ npm i @lcluber/csvxjs

yarn

$ yarn add @lcluber/csvxjs

Usage

ES6

Export CSV
">
<button id="csv">Export CSVbutton>
<div id="table">div>
import { Export, Convert } from '@lcluber/csvxjs';

// Convert an array to CSV file
let array = [
  {
    firstname:'Galileo',
    lastname:'Galiléi',
    born:1564,
    died:1642
  },
  {
    firstname:'Nikola',
    lastname:'Tesla',
    city:'Smiljan',
    born:1856,
    died:1943
  },
  {
    firstname:'Albert',
    born:1879,
    lastname:'Einstein',
    died:1955
  }
];
let customLabels = {
  firstname: 'First name',
  lastname: 'Last name', 
  city: 'City',
  born: 'Born',
  died: 'Died'
};
let exportButton = document.getElementById('csv');
exportButton.addEventListener('click', function() {
  Export.data('scientists',array,{separator: ';', customLabels: customLabels});// ; separator for excel friendly imports
});

// Convert CSV data to HTML table
let data = '"Firstname";"Lastname";"Born";"Died"\r\n\
"Galileo";"Galilei";"1564";"1642"\r\n\
"Nikola";"Tesla";"1856";"1943"\r\n\
"Albert";"Einstein";"1879";"1955"';

document.getElementById("table").innerHTML = Convert.table(data,{separator: ';'}, {table: 'table table-striped'});

IIFE

">
<script src="node-modules/@lcluber/csvxjs/dist/csvx.iife.min.js">script>
<button id="csv">Export CSVbutton>
<div id="table">div>
// Convert an array to CSV file
var array = [
 {
    firstname:'Galileo',
    lastname:'Galiléi',
    born:1564,
    died:1642
  },
  {
    firstname:'Nikola',
    lastname:'Tesla',
    city:'Smiljan',
    born:1856,
    died:1943
  },
  {
    firstname:'Albert',
    born:1879,
    lastname:'Einstein',
    died:1955
  }
];
var customLabels = {
  firstname: 'First name',
  lastname: 'Last name', 
  city: 'City',
  born: 'Born',
  died: 'Died'
};
var exportButton = document.getElementById('csv');
exportButton.addEventListener('click', function() {
  CSVx.Export.data('scientists',array,{separator: ';', customLabels: customLabels});// ; separator for excel friendly imports
});

// Convert CSV data to HTML table
var data = '"Firstname";"Lastname";"Born";"Died"\r\n\
"Galileo";"Galilei";"1564";"1642"\r\n\
"Nikola";"Tesla";"1856";"1943"\r\n\
"Albert";"Einstein";"1879";"1955"';

document.getElementById("table").innerHTML = CSVx.Convert.table(data,{separator: ';'}, {table: 'table table-striped'});

API Reference

class Convert {
  static setOptions(options: Partial<Options>): void;
  static setCSS(css: Partial<CSS>): void;
  // convert CSV to Javascript array
  static array(data: string, options?: Partial<Options>, css?: Partial<CSS>): Array<Array<string>> | false;
  // convert CSV to HTML table
  static table(data: string, options?: Options, css?: CSS): string | false;
}

class Export {
  // Exort CSV file
  static data(filename: string, data: Data[], options?: Partial<Options>): boolean;
  static setOptions(options: Partial<Options>): void;
}

interface Data { [key: string]: number|string }[]

interface Options {
  data?: string; // default : 'text/csv'
  charset?: string; // default : 'utf-8'
  labels?: boolean; // default : true
  quote?: string; // default : '"'
  separator?: string; // default : ','
  CRLF?: string; // default : '\r\n'
  customLabels: { [key: string]: string }; // default : {}
}

interface CSS {
  table?: string; // default : ''
  th?: string; // default : ''
}

Contributors

CSVx.js is still in early development and I would be glad to get all the help you can provide for this project. To contribute you can clone the project on GitHub and See NOTICE.md for detailed installation walkthrough.

License

MIT License

Copyright (c) 2018 Ludovic CLUBER

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Export data with custom labels on Firefox - missing CRLF

    Export data with custom labels on Firefox - missing CRLF

    Description Custom label row and first data row are not separated when exporting csv on Firefox.

    • Here is the csv file content produced with Firefox:
    "First name";"Last name";"Born";"Died""Galileo";"Galiléi";"1564";"1642"
    "Nikola";"Tesla";"1856";"1943"
    "Albert";"Einstein";"1879";"1955"
    
    • Here with Chrome:
    "First name";"Last name";"Born";"Died"
    "Galileo";"Galiléi";"1564";"1642"
    "Nikola";"Tesla";"1856";"1943"
    "Albert";"Einstein";"1879";"1955"
    

    Code

    var customLabels = ['First name', 'Last name', 'Born', 'Died'];
    exportButton.addEventListener('click', function () {
      CSVx.Export.data('scientists', array, {
        separator: ';',
        customLabels: customLabels
      });
    });
    
    opened by estellepicq 2
  • set default name to export if empty filename

    set default name to export if empty filename

    If provided filename is an empty string:

    • Before: get file 'csv'
    • Now: set value to 'export' and get file 'export.csv'

    Tried to pass it as default value (...public static data( filename: string = 'export',....) but empty strings are not undefined values.

    opened by estellepicq 2
  • Bump jquery from 3.2.1 to 3.5.0

    Bump jquery from 3.2.1 to 3.5.0

    Bumps jquery from 3.2.1 to 3.5.0.

    Commits
    • 7a0a850 3.5.0
    • 8570a08 Release: Update AUTHORS.txt
    • da3dd85 Ajax: Do not execute scripts for unsuccessful HTTP responses
    • 065143c Ajax: Overwrite s.contentType with content-type header value, if any
    • 1a4f10d Tests: Blacklist one focusin test in IE
    • 9e15d6b Event: Use only one focusin/out handler per matching window & document
    • 966a709 Manipulation: Skip the select wrapper for <option> outside of IE 9
    • 1d61fd9 Manipulation: Make jQuery.htmlPrefilter an identity function
    • 04bf577 Selector: Update Sizzle from 2.3.4 to 2.3.5
    • 7506c9c Build: Resolve Travis config warnings
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by mgol, a new releaser for jquery since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump bootstrap from 3.3.7 to 3.4.1

    Bump bootstrap from 3.3.7 to 3.4.1

    Bumps bootstrap from 3.3.7 to 3.4.1.

    Release notes

    Sourced from bootstrap's releases.

    v3.4.1

    • Security: Fixed an XSS vulnerability (CVE-2019-8331) in our tooltip and popover plugins by implementing a new HTML sanitizer
    • Handle bad selectors (#) in data-target for Dropdowns
    • Clarified tooltip selector documentation
    • Added support for NuGet contentFiles

    v3.4.0

    • New: Added a .row-no-gutters class.
    • New: Added docs searching via Algolia.
    • Fixed: Resolved an XSS issue in Alert, Carousel, Collapse, Dropdown, Modal, and Tab components. See https://snyk.io/vuln/npm:bootstrap:20160627 for details.
    • Fixed: Added padding to .navbar-fixed-* on modal open
    • Fixed: Removed the double border on <abbr> elements.
    • Removed Gist creation in web-based Customizer since anonymous gists were disabled long ago by GitHub.
    • Removed drag and drop support from Customizer since it didn't work anymore.
    • Added a dropdown to the docs nav for newer and previous versions.
    • Update the docs to use a new baseurl, /docs/3.4/, to version the v3.x documentation like we do with v4.
    • Reorganized the v3 docs CSS to use Less.
    • Switched to BrowserStack for tests.
    • Updated links to always use https and fix broken URLs.
    • Replaced ZeroClipboard with clipboard.js
    Commits
    Maintainer changes

    This version was pushed to npm by xhmikosr, a new releaser for bootstrap since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump jquery from 3.2.1 to 3.4.1

    Bump jquery from 3.2.1 to 3.4.1

    Bumps jquery from 3.2.1 to 3.4.1.

    Commits
    • 75f7e96 3.4.1
    • 7dddb19 Core: Make isAttached work with iOS 10.0-10.2
    • 6c1e7db Event: Prevent leverageNative from registering duplicate dummy handlers
    • 24d71ac Event: Fix handling of multiple async focus events
    • b4fadc9 Build: Test on Node.js 12, stop testing on Node.js 6 & 11
    • 0d4af52 Build: Fix unresolved jQuery reference in finalPropName
    • 22caea8 Build: Updating the 3.4-stable version to 3.4.1-pre
    • 59ea765 Release: update AUTHORS.txt
    • 7c1ef15 Release: update version to 3.4.0-pre
    • d940bc0 Build: Update Sizzle from 2.3.3 to 2.3.4
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump morgan from 1.9.0 to 1.10.0

    Bump morgan from 1.9.0 to 1.10.0

    Bumps morgan from 1.9.0 to 1.10.0.

    Release notes

    Sourced from morgan's releases.

    1.10.0

    • Add :total-time token
    • Fix trailing space in colored status code for dev format
    • deps: basic-auth@~2.0.1
    • deps: depd@~2.0.0
      • Replace internal eval usage with Function constructor
      • Use instance methods on process to check for listeners
    • deps: on-headers@~1.0.2
      • Fix res.writeHead patch missing return value

    1.9.1

    • Fix using special characters in format
    • deps: depd@~1.1.2
      • perf: remove argument reassignment
    Changelog

    Sourced from morgan's changelog.

    1.10.0 / 2020-03-20

    • Add :total-time token
    • Fix trailing space in colored status code for dev format
    • deps: basic-auth@~2.0.1
    • deps: depd@~2.0.0
      • Replace internal eval usage with Function constructor
      • Use instance methods on process to check for listeners
    • deps: on-headers@~1.0.2
      • Fix res.writeHead patch missing return value

    1.9.1 / 2018-09-10

    • Fix using special characters in format
    • deps: depd@~1.1.2
      • perf: remove argument reassignment
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • add BOM for excel

    add BOM for excel

    • Before: CSV files opened in Excel looked like 'Galiléi', because Excel does not detect utf8 encoding by default.

    • Now: Special characters are ok ('Galiléi' for example) Solution found here: https://stackoverflow.com/questions/19492846/javascript-to-csv-export-encoding-issue

    This feature does not affect the normal behaviour of the library, but maybe you want it as an option anyway?

    opened by estellepicq 0
Releases(v0.2.1)
Owner
Ludovic CLUBER
Software development expert / Solution architect @ Alten.
Ludovic CLUBER
Yunisdev-table2csv - Lightweight library to convert HTML table to CSV file

Installation Add following HTML before body end: <script src="https://yunisdev.github.io/table2csv/table2csv.min.js"></script> <!-- or --> <script src

Yunis Huseynzade 2 Oct 19, 2020
Import flow for Excel (.xlsx) and CSV file with automated column matching and validation.

RSI react-spreadsheet-import ⚡️ A component used for importing XLS / XLSX / CSV documents built with Chakra UI. Import flow combines: ?? Uploader ⚙️ P

Ugnis 123 Dec 24, 2022
An Obsidian Plugin that allows to export tables from a pane in reading mode to CSV files.

Obsidian Plugin "Table to CSV Exporter" This is my very first attempt in writing a plugin for Obsidian. I didn't even know TypeScript before (but Java

Stefan Wolfrum 26 Dec 27, 2022
Portable Activity Timeline that draws the Timeline based on data given in JSON or CSV format

Portable Activity Timeline that draws the Timeline based on data given in JSON or CSV format. By clicking on any activity a detailed modal window is displayed. Initially developed for post incident investigations to get a overview of the situation in an it-environment.

Daniel 5 Oct 11, 2022
A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!

?? JavaScript Object to csv, xls, pdf, doc and DOM to html generator ?? A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript O

null 61 Jan 7, 2023
CancerDB: A public domain knowledge graph about cancer treatments that compiles to a CSV file.

CancerDB: A public domain csv file to help build the next great cure CancerDB is a public domain database and website containing facts about all types

Breck Yunits 21 Dec 15, 2022
데이터 수집기 From DataServer, Csv File

Node.js 데이터 수집기 From DataServer, Csv File 실행 방법 가장 중요한 실행방법입니다. npm run dev 실행 or npm run build 후 npm run start http://localhost:3000/api-docs 로 접속합니다

Dominic Kim 1 Oct 10, 2022
Scrape tweets from Twitter search results based on keywords and date range using Playwright. Save scraped tweets in a CSV file for easy analysis

Tweet Harvest (Twitter Crawler) Tweet Harvest is a command-line tool that uses Playwright to scrape tweets from Twitter search results based on specif

Helmi Satria 33 Aug 9, 2023
An Open-Source Platform to certify open-source projects.

OC-Frontend This includes the frontend for Open-Certs. ?? After seeing so many open-source projects being monetized ?? without giving any recognition

Open Certs 15 Oct 23, 2022
Shikhar 4 Oct 9, 2022
This is a project for open source enthusiast who want to contribute to open source in this hacktoberfest 2022. 💻 🎯🚀

HACKTOBERFEST-2022-GDSC-IET-LUCKNOW Beginner-Hacktoberfest Need Your first pr for hacktoberfest 2k22 ? come on in About Participate in Hacktoberfest b

null 8 Oct 29, 2022
:books: The definitive guide to TypeScript and possibly the best TypeScript book :book:. Free and Open Source 🌹

TypeScript Deep Dive I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from Stack

Basarat Ali Syed 18.7k Jan 4, 2023
A free and open-source Automatic Account Creator (AAC) written in Javascript Stack;

A free and open-source Automatic Account Creator (AAC) written in Javascript Stack. ????‍?? Techs Front-end Vue.js Vuex-module-decorators Vuetify.js N

null 24 Dec 17, 2022
AwardBot is an open source advanced giveaway bot. Written in Discord.js

AwardBot is an open source advanced giveaway bot. Written in Discord.js. You can set conditions for the giveaways, automatically deliver the prizes, and lock the giveaways.

Award 2 Oct 29, 2022
⚡️ Free, open-source and easy to setup tempmail written in Node.JS!

tempmail-js ⚡️ Free, open-source and easy to setup tempmail written in Node.JS! tempmail.js uses MongoDB to store it's data. Installation Installing t

vida 2 Nov 7, 2022
An open-source URL Shortener written in Node.js 🔗

What's this? Qurl.gq is an open-source URL Shortener written in Node.js ?? Contributing ideas Apply a custom font Add tests UI Improvements Sanitise u

RedstoneRadiant 7 Oct 7, 2022
A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).

typescript.nvim A minimal typescript-language-server integration plugin to set up the language server via nvim-lspconfig and add commands for convenie

Jose Alvarez 315 Dec 29, 2022
Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

null 3 Jan 27, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022