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 sparklineVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic CommonJS usage in Node.js to generate a textual sparkline from an array of numbers.
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.
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).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.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()`.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.
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.
No dependency data recorded yet.