Babar CLI Bar Charts

raw JSON →
0.2.3 verified Thu Apr 23 auth: no javascript abandoned

Babar is a minimalistic Node.js library, currently at version 0.2.3, designed to render simple bar charts directly in the command line interface using ASCII characters. It provides basic visualizations for quickly understanding data distributions without the need for advanced charting features. The package is lightweight, consisting of approximately 100 lines of code, and offers options for color output, custom dimensions, and axis scaling. Its development appears to be inactive, with the last release nearly a decade ago (published 9 years ago as of April 2026), making it suitable for very basic, quick console output rather than robust data visualization needs. Key differentiators are its extreme simplicity and small footprint, focusing solely on console-based bar chart rendering.

error SyntaxError: Cannot use import statement outside a module
cause Attempting to use `import babar from 'babar';` in a CommonJS-configured Node.js project or a script without `"type": "module"` in `package.json`.
fix
Change the import statement to const babar = require('babar');.
error Error [ERR_REQUIRE_ESM]: require() of ES Module [path_to_node_modules]/babar/index.js from [your_script].js not supported.
cause Attempting to use `require('babar');` in a Node.js project configured as an ES Module (with `"type": "module"` in `package.json`).
fix
Babar is CJS-only. You must either configure your project as CommonJS or find an alternative library that supports ESM. If absolutely necessary, you might try dynamic import('babar').then(mod => mod.default) but this is not officially supported and can be fragile.
error TypeError: babar is not a function
cause Incorrectly trying to destructure the default CommonJS export, e.g., `const { babar } = require('babar');`
fix
The 'babar' module exports a single function as its default. Import it directly: const babar = require('babar');
breaking Babar is a CommonJS-only module and does not natively support ES Modules (ESM) import syntax. Attempting to 'import' it directly in an ESM project will cause runtime errors.
fix Use CommonJS 'require()' syntax. If in an ESM project, consider using a bundler like Webpack or Rollup, or a dynamic 'import()' call (with caution) to consume it.
gotcha The package is no longer actively maintained, with the last update nearly a decade ago. This implies a lack of security updates, bug fixes, or guaranteed compatibility with newer Node.js versions or modern development practices.
fix Evaluate alternatives for critical applications or those requiring ongoing support. For basic, non-critical console output, it may still suffice but proceed with awareness of its abandoned status.
gotcha Babar has significant limitations: it only supports single-dataset bar charts, linear axes, positive Y-values (minY cannot be negative), and numerical labels. It is not suitable for complex data visualization or rich interactive charts.
fix Review the 'Limitations' section in the README to ensure it meets your specific needs. For advanced charting, explore more robust libraries like 'chart.js', 'd3', 'vega-lite', or 'plotly.js'.
npm install babar
yarn add babar
pnpm add babar

Demonstrates how to import the babar function and generate a simple bar chart, both with default settings and custom options for styling and scaling, outputting ASCII art to the console.

const babar = require('babar');

// Basic usage with an array of [x, y] points
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]));

// Usage with custom options for colors, dimensions, and axis scaling
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], {
  caption: 'Sample Data Distribution',
  color: 'green',
  grid: 'blue',
  width: 60,
  height: 12,
  maxY: 10,
  yFractions: 1
}));