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

export-data.js

v1.1.1

Published

Download/export and print data in various formats, such as JSON, CSV, XLSX (Excel), PDF and images.

Downloads

191

Readme

export-data.js

Download/export and print data in various formats, such as JSON, CSV, XLSX (Excel), PDF and images (using canvas).

Installation

NPM

Install the library using NPM:

npm i export-data.js

Import it into your project:

CommonJS

const exportData = require('export-data.js/export-data.cjs.js');

ES Modules

import exportData from 'export-data.js/export-data.esm.js';

CDN

Add the library directly to your HTML via CDN:

<script src='https://cdn.jsdelivr.net/gh/lullaby6/export-data.js/export-data.cdn.min.js'></script>

Direct Download

Download the minified version:

  • export-data.cdn.min.js

Include the downloaded file in your project:

<script src="/path/to/export-data.min.js"></script>

Dependencies

The dependencies loaded automatically if not included.

  • jsPDF for PDF generation (v1.5.3).
  • jsPDF AutoTable for table rendering in PDFs (v3.5.6).

Usage

Example data:

const products = [
    { id: 1, name: "Laptop", price: 1200, category: "Electronics", stock: 15 },
    { id: 2, name: "Smartphone", price: 800, category: "Electronics", stock: 25 },
    { id: 3, name: "Headphones", price: 100, category: "Accessory", stock: 50 },
    { id: 4, name: "Mouse", price: 25, category: "Accessory", stock: 100 },
    { id: 5, name: "Keyboard", price: 50, category: "Accessory", stock: 80 },
    // ...
]

Downloading data

Download data as JSON file

exportData.json(products, 'products')
  • data: Array to objects to export (e.g products).
  • title: File name (optional).

Download data as CSV file

exportData.csv(products, 'products')
  • data: Array to objects to export (e.g products).
  • title: File name (optional).

Download data as XLSX/Excel file

exportData.xlsx(products, 'products')
  • data: Array to objects to export (e.g products).
  • title: File name (optional).

Download data as PDF file

exportData.pdf(products, 'products', true)
  • data: Array to objects to export (e.g products).
  • title: Title of the PDF (optional).
  • date: Boolean to include the current date in the title (optional).

Download data as Image (using canvas)

exportData.pdf(products, 'products', true)
  • data: Array to objects to export (e.g products).
  • title: Title of the PDF (optional).
  • cellWidth: Width of each cell in the canvas (default: 300px).

Printing data

The module also allows printing data in HTML, PDF or as a canvas-generated image.

Print as HTML Table

exportData.print(products, 'Product List', true)
  • data: Array to objects to export (e.g products).
  • title: Title in the printed table (optional).
  • date: Boolean to include the current date in the title (optional).

Print as PDF Table

exportData.printPDF(products, 'Product List', true)
  • data: Array to objects to export (e.g products).
  • title: Title of the PDF table (optional).
  • date: Boolean to include the current date in the title (optional).
  • theme: Table style theme (default: 'grid', themes: 'grid', 'striped', 'plain').

Print as Image (using canvas)

exportData.printImage(products, 'Product List', true)
  • data: Array to objects to export (e.g products).
  • title: Title of the printed image (optional).
  • date: Boolean to include the current date in the title (optional).
  • cellWidth: Width of each cell in the canvas (default: 300px).