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

@mathieu-bour/node-sparkline

v2.0.0-alpha.1

Published

A lightweight and zero-dependencies pure Node.js sparkline generator

Downloads

15,909

Readme

Table of Contents

Presentation

node-sparkline is a sparkline generator written in pure Node.js using ES6 and ES7 features with no dependency. It calculates points based on values to finally generate a polyline in a pure SVG (Scalable Vector Graphics) format. These values could be prices during the last 7 fays for an example.

The aim of this project is to provide a very simple, lightweight, zero-dependency, fast and fully-tested sparkline generator in SVG format and let user tune height, width, stroke color, stroke width and stroke opacity.

Installation

npm install node-sparkline

npm i -S node-sparkline

Technical information

Node.js

  • Language: JavaScript ES6/ES7
  • VM: Node.js >=10.0.0

Debugging

  • Own debugger embedded that writes on process.stderr when the DEBUG environment variable is set. See Environment variables.

Tests

Linting

ESLint with Airbnb base rules. See Airbnb JavaScript Style Guide.

npm run lint

Unit

Mocha and Chai.

npm test

Usage

Library

Import node-sparkline

node-sparkline module exports one function named sparkline.

const sparkline = require('node-sparkline');

sparkline(options)

  • options<Object>:

    • values* <Array> An array of values to draw the sparkline.
    • width <Number> The width in pixels to fix for the generated SVG. Default: 135
    • height <Number> The height in pixels to fix for the generated SVG. Default: 50
    • stroke <String> The stroke color. An hexadecimal value or one of these generic names. Default: #57bd0f
    • strokeWidth <Number> The stroke width in pixels. Min: 0 Default: 1.25
    • strokeOpacity <Number> The stroke opacity. Min: 0 Max: 1 Default: 1
  • Returns: <String> The SVG tags of the generated SVG image

  • Throws: <InputError>

Examples

You can find examples here: docs/examples

In these examples please prefer a well-known and tested asynchronous logger over the use of console module.

const sparkline = require('node-sparkline');
const values = require('./values'); // values is an array

try {
  const svg = sparkline({
    values,
    width: 135,
    height: 50,
    stroke: '#57bd0f',
    strokeWidth: 1.25,
    strokeOpacity: 1,
  });

  // svg is a string with SVG + polyline tags
  // ...
} catch (e) {
  console.error(e.toString());
}

Bitcoin

Ethereum

Chainlink

Kusama

Tether

Environment variables

  • DEBUG: used to debug node-sparkline.

    Examples:

    • DEBUG=node-sparkline:* will debug all node-sparkline modules that could use the debugger.
    • DEBUG=-node-sparkline:* will disable debugging any node-sparkline modules that could use the debugger.
    • DEBUG=* will debug all node-sparkline modules that could use the debugger plus other modules used in your project if they use an equivalent debugger.

Errors

Object structure

Errors emitted by node-sparkline inherit the native Error prototype.

{
  name,
  code,
  message,
  stack,
  toString(),
}

Codes

Known issues

/

Code of Conduct

This project has a Code of Conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

Contributing

Please take a moment to read our Contributing Guidelines if you haven't done so yet.

Support

Please see our Support page if you have any questions or for any help needed.

Security

For any security concerns or issues, please visit our Security Policy page.

License

MIT.