{"id":14927,"library":"sparkline","title":"sparkline","description":"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.","status":"abandoned","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/shiwano/sparkline","tags":["javascript","spark","graph"],"install":[{"cmd":"npm install sparkline","lang":"bash","label":"npm"},{"cmd":"yarn add sparkline","lang":"bash","label":"yarn"},{"cmd":"pnpm add sparkline","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and does not export ES Modules. Direct ESM import will fail.","wrong":"import sparkline from 'sparkline';","symbol":"sparkline","correct":"const sparkline = require('sparkline');"},{"note":"When included directly in the browser via a <script> tag, 'sparkline' is available as a global function.","wrong":"import { sparkline } from 'sparkline';","symbol":"sparkline","correct":"sparkline([1, 5, 22, 7, 9]);"}],"quickstart":{"code":"const sparkline = require('sparkline');\n\n// Generate a sparkline from an array of numbers\nconst data = [1, 5, 22, 7, 9, 15, 3, 18, 10, 25];\nconst line = sparkline(data);\nconsole.log('Node.js Console Sparkline:', line);\n\n// Example with more data points and options (inferred from v0.2.0 release notes)\n// The README only shows basic usage, but 'html' option was added in v0.2.0\n// For basic console output, the array is sufficient.\nconst largerData = Array.from({ length: 20 }, (_, i) => Math.sin(i / 2) * 10 + 10 + Math.random() * 5);\nconst anotherLine = sparkline(largerData);\nconsole.log('Another Sparkline:', anotherLine);\n\n// To run as a command-line utility:\n// npm install -g sparkline\n// sparkline 12 43 56 30 15\n// echo 21,45,6,25,19,15 | sparkline","lang":"javascript","description":"Demonstrates basic CommonJS usage in Node.js to generate a textual sparkline from an array of numbers."},"warnings":[{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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).","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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()`.","cause":"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.","error":"TypeError: sparkline is not a function"},{"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.","cause":"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.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... sparkline.js not supported."},{"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.","cause":"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.","error":"Module not found: Error: Can't resolve 'sparkline'"}],"ecosystem":"npm"}