sparkline

0.2.0 · abandoned · verified Sun Apr 19

sparkline is a JavaScript library that generates textual sparklines (small, intense, word-sized graphics) inspired by Holman's 'spark' utility. It takes an array of numerical data and outputs a compact string representation of a line graph, primarily for console or plain text display. The current stable version, 0.2.0, was last released on June 23, 2017. Given the lack of updates since then, its development is considered abandoned. It differentiates itself by producing character-based sparklines suitable for terminal output or simple HTML, in contrast to modern SVG/Canvas-based solutions, and predates the common adoption of ES Modules (ESM) and TypeScript in the JavaScript ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic CommonJS usage in Node.js to generate a textual sparkline from an array of numbers.

const sparkline = require('sparkline');

// Generate a sparkline from an array of numbers
const data = [1, 5, 22, 7, 9, 15, 3, 18, 10, 25];
const line = sparkline(data);
console.log('Node.js Console Sparkline:', line);

// Example with more data points and options (inferred from v0.2.0 release notes)
// The README only shows basic usage, but 'html' option was added in v0.2.0
// For basic console output, the array is sufficient.
const largerData = Array.from({ length: 20 }, (_, i) => Math.sin(i / 2) * 10 + 10 + Math.random() * 5);
const anotherLine = sparkline(largerData);
console.log('Another Sparkline:', anotherLine);

// To run as a command-line utility:
// npm install -g sparkline
// sparkline 12 43 56 30 15
// echo 21,45,6,25,19,15 | sparkline

view raw JSON →