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

@kktsvetkov/heiho

v0.3.3

Published

Quick spreadsheet viewer in vanilla JS

Downloads

26

Readme

Heihō

Quick spreadsheet viewer in vanilla JS

Heihō

What it does ?

The heiho.js script is quick and simple spreadsheet viewer. It is meant to preview the contents of csv files inside your browser without needing any other tools. It uses plain vanilla javascript so it has no dependencies, but for the applied styling from the css file.

This is not a spreadsheet editor, this is a preview tool only.

How to use ?

Simply include both the javascript file and the css stylesheet in your HTML document. It's best if you put them at the bottom, close to the closing <\body> tag.

<link rel="stylesheet" href="/path/to/heiho.css" />
<script src="/path/to/heiho.js"></script>

Or include it via jsDelivr CDN:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kktsvetkov/heiho@latest/heiho.css" />
<script src="https://cdn.jsdelivr.net/gh/kktsvetkov/heiho@latest/heiho.js"></script>

Once included in your document, simply call Heiho() and pass the data as argument

var data = [ ['a', 'b', 'c'], [1,2,3], [4,5,6] ];
Heiho(data);

You can modify some of the output using a second argument that passes additional options

Heiho(data, {max:20}); // shows only 20 rows from data

Explore more cases in the examples section below.

Options

There is a small set of options used to influence the output of the spreadsheet preview.

  • options.header is boolean value whether to style the first row in the
    preview differently; this meant to be used with CSV files, where the first row holds the column titles; default value is null which triggers an attempt to auto-detect whether the first row is header or not.

  • options.max is an integer value that restricts how many rows to be included in the preview; you can use 0 to disable it, and its' default value is 100.

  • options.title this is used to output the header title; you can use a string to just pass a text to be inserted there, or you can use a function that manipulates the HTML element that is the header title (look in the examples below)

  • options.truncate is a function used to render the output in the "truncate" element of the preview; this element appears if the rows of the data previewed are more than options.max as an acknowledgement that the data was truncated (look in the examples below to see how this work)

Options are passed as a second argument to Heiho() function.

Heiho(data, { max: 20, title: 'proba.csv' });

You can add more elements to the options argument which you can later use in some of the functions inside it such as options.title and options.truncate.

Examples

Let's explore few examples of what you can do with Heihō

Title

You can modify what is rendered in the header title of the preview. The basic approach here is to just pass the title as a string in the options, like this:

Heiho(data, { title: 'users.csv' });

You can also do more with it if you pass a function as the title. In that case it will be executed to populate the contents of the header title will be. The arguments are the header title element, and the options used.

var file = {filename: 'Proba.csv', size: '123KB', created: '2009-08-21 14:01:36'}
Heiho(data, { title: function(el, o)
	{
		el.innerHTML = '<b>'
			+ file.filename + '<\/b> <code>'
			+ file.size + '<\/code> '
			+ file.created;
	}
});

Truncate

Similar to how options.title is used as a function, options.truncate is used to populate the contents of the "truncate" element (the warning shown when there are more rows to preview than the options.max restriction). This function gets more arguments:

/**
* @param {DomElement} el the truncate element
* @param {Integer} max
* @param {Array|Object} data data previewed
* @param {Object} o options
*/
options.truncate = function(el, max, data, o)
{
	el.innerHTML = 'Showing only first ' + max + ' rows';
	el.style.display = '';
}

Papa Parse

You can use the popular Papa Parse (github) library to parse CSV data inside your browser. You can use it together with Heihō to preview the result from the CSV parsing

Papa.parse(file, {
	complete: function(results) {
		Heiho(results.data);
	}
});

Explore all the examples on papaparse.com, they are a blast!

Here's an example of Papa Parse and Heiho previewing a remote csv file:

Papa.parse("http://example.com/file.csv", {
	download: true,
	complete: function(results) {
		Heiho(results.data);
	}
});