Registry / data / sparkline

sparkline

JSON →
library0.2.0jsnpmunverified

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.

npm install sparkline
INSTALL
IMPORT
SIG · SPARKLINE
S
sparkline
datajavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sparkline
const sparkline = require('sparkline');
import sparkline from 'sparkline';
The package is CommonJS-only and does not export ES Modules. Direct ESM import will fail.
sparkline
sparkline([1, 5, 22, 7, 9]);
import { sparkline } from 'sparkline';
When included directly in the browser via a <script> tag, 'sparkline' is available as a global function.

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
Debug
Known issues
gotchaThis package is not actively maintained, with the last release (v0.2.0) dating back to June 2017. It does not receive updates for bug fixes, performance improvements, or compatibility with newer JavaScript features or environments.
fix
Consider using a more actively maintained sparkline library, especially if targeting modern web applications or Node.js environments. Alternatives often offer SVG/Canvas rendering, ESM support, and TypeScript definitions.
affects: >=0.1.0
gotchaThe package is distributed as CommonJS (CJS) only, without native ES Module (ESM) support. Importing it directly in an ESM-only environment or bundler configuration may lead to import errors or require specific CJS compatibility settings.
fix
For Node.js, use `const sparkline = require('sparkline');`. For browser, include it via a `<script>` tag. If using a modern bundler that defaults to ESM, configure it to allow CJS imports (e.g., `resolve.fullySpecified: false` in Webpack 5, or equivalent for other bundlers).
affects: >=0.1.0
gotchaThe library does not provide TypeScript type definitions. Integrating it into a TypeScript project will require creating custom declaration files (`.d.ts`) to avoid type errors and enable type checking.
fix
Create a `sparkline.d.ts` file with `declare module 'sparkline' { function sparkline(data: number[], options?: { html?: boolean; min?: number; max?: number }): string; export = sparkline; }` or use a different library with built-in TypeScript support.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: sparkline is not a function
Attempting to use `sparkline` as a named or default export in an ES Module context, or calling it without first requiring it in a CommonJS context.
fix
Ensure you are using the CommonJS `require` syntax in Node.js (`const sparkline = require('sparkline');`) or that the script is loaded globally in the browser context before calling `sparkline()`.
Error [ERR_REQUIRE_ESM]: require() of ES Module ... sparkline.js not supported.
A modern Node.js or bundler environment is configured to treat modules as ESM by default and does not correctly handle the CJS `sparkline` package, preventing it from being `require`d.
fix
This error typically occurs when trying to `require` an ES Module from a CJS context. While `sparkline` is CJS, this error can arise if the surrounding project is incorrectly treating it as ESM. Ensure your project and bundler correctly identify `sparkline` as CJS. If `package.json` has `"type": "module"`, `require()` calls inside `.js` files need specific handling, or ensure the consumer file is `.cjs` or `require`d from a CJS file. For Node.js, ensure your consuming script is also CommonJS. For bundlers, check their specific configuration for CJS compatibility.
Module not found: Error: Can't resolve 'sparkline'
The module 'sparkline' could not be found by the module resolver, often due to an incorrect import path, missing installation, or a bundler struggling with legacy CJS packages in a modern setup.
fix
First, ensure `npm install sparkline` has been run. If the issue persists in a modern bundler (e.g., Webpack, Rollup, Vite), it might be a compatibility issue with CJS. Check the bundler's configuration for `resolve` or `alias` settings to ensure it can locate and process CommonJS modules.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
sparkline — npm install sparkline · libregistry