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

@vizabi/reader-excel

v1.0.0

Published

Vizabi reader for a Excel files

Downloads

1

Readme

Vizabi Excel reader

The main goal of this repo is to provide ability for Vizabi to work with XLS and XLSX data.

Install

npm i vizabi-excel-reader

Usage

Usage on backend

import * as path from 'path';
import { excelReaderObject as excelReaderPlainObject } from 'vizabi-excel-reader';

global.d3 = require('d3');
global.Vizabi = require('vizabi');

const ExcelReader = global.Vizabi.Reader.extend(excelReaderPlainObject);
const excelReaderObject = new ExcelReader({
  path: path.resolve('path to XLS file'),
  sheet: 'basic'
});
const result = await excelReaderObject.load();

console.log(result);

Usage on frontend

<script src="node_modules/vizabi-excel-reader/dist/vizabi-excel-reader.js"></script>
<script>
  // ExcelReader global variable was imported by script above
  Vizabi.Reader.extend("excel-reader", ExcelReader.excelReaderObject);
  // use "excel-reader" as a Vizabi init parameter
  // .....
</script>

Get assets on backend

import * as fs from 'fs';
import { excelReaderObject as excelReaderPlainObject } from 'vizabi-excel-reader';

global.d3 = require('d3');
global.Vizabi = require('vizabi');

const readJson = (filePath, onFileRead) => {
  fs.stat(filePath, (fileErr, stat) => {
    if (fileErr) {
      return onFileRead(fileErr);
    }

    if (stat.code === 'ENOENT') {
      return onFileRead('No such file: ' + filePath);
    }

    fs.readFile(filePath, 'utf-8', (readErr, content) => {
      if (readErr) {
        return onFileRead(readErr);
      }

      try {
        onFileRead(null, JSON.parse(content.toString()));
      } catch (e) {
        onFileRead(e);
      }
    });
  });
};

const ExcelReader = global.Vizabi.Reader.extend(excelReaderPlainObject);
const excelReaderObject = new ExcelReader({
  assetsPath: 'path to assets', // must be ended with '/'
  additionalJsonReader: readJson
});
const result = await excelReaderObject.getAsset('asset file name');

console.log(result);

Get worksheets names

import * as path from 'path';
import { excelReaderObject as excelReaderPlainObject } from 'vizabi-excel-reader';

global.d3 = require('d3');
global.Vizabi = require('vizabi');

const ExcelReader = global.Vizabi.Reader.extend(excelReaderPlainObject);
const excelReaderObject = new ExcelReader({
  path: path.resolve('path to XLS file'),
  sheet: 'basic'
});

const result = await excelReaderObject.getWorksheets();

console.log(result);

Initial parameters

  • path - path to XLS file that would be processed
  • timeInColumns - a flag that indicates that Excel file contains data in time-in-columns format (false by default)
  • sheet- XLS sheet to open, can be a number or a string. In case of number it should be an order number of the expected sheet, in case of string it should be a name of the expected sheet (0 is default)
  • lastModified - last modification date (optional)
  • keySize - key size (1 by default)
  • hasNameColumn - an extra column that contains country name (should not be processed, optional, false by default)
  • nameColumnIndex - index of nameColumn (default value is 0)
  • assetsPath - path to assets JSON file (optional, must be ended with '/')
  • additionalTextReader - function that should replace tenured text reading function (optional, see examples above, could be useful on frontend or testing)
  • additionalJsonReader - function that should replace tenured JSON reading function (optional, see examples above, could be useful on frontend or testing)

Run tests

npm test

Build

git clone https://github.com/vizabi/vizabi-excel-reader.git
cd vizabi-excel-reader
npm i
npm run build

The result is a couple of directories: dist and lib.

dist contain two files: vizabi-excel-reader.js and vizabi-excel-reader.js.map. These files could be used on frontend: see Usage on frontend

lib (lib/index.js) - is used 'by default' (see main section of package.json) and could be used on backend (see Usage on backend)