{"id":17210,"library":"easy-table","title":"Easy Table","description":"easy-table is a JavaScript utility for rendering plain text tables primarily for command-line interfaces. It allows for highly customizable table structures, including dynamic cell content formatting via 'printer' functions, column sorting with specific syntax, and aggregation features like totaling and averaging. The package is currently at version 1.2.0. Its last known activity on npm was 5 years ago, and the GitHub repository shows an 8-year inactivity period, suggesting it is in an abandoned state rather than actively maintained. It ships with TypeScript type definitions, enabling type-safe usage in modern TypeScript projects. Key differentiators include its flexible cell rendering pipeline and built-in aggregation capabilities for simple CLI reporting.","status":"abandoned","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/eldargab/easy-table","tags":["javascript","table","text","cli","typescript"],"install":[{"cmd":"npm install easy-table","lang":"bash","label":"npm"},{"cmd":"yarn add easy-table","lang":"bash","label":"yarn"},{"cmd":"pnpm add easy-table","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary CommonJS import pattern shown in documentation.","symbol":"Table (CommonJS)","correct":"const Table = require('easy-table')"},{"note":"The package uses a CommonJS default export, which translates to a default import in ESM. Named imports like `import { Table }` will result in errors in strict ESM environments.","wrong":"import { Table } from 'easy-table'","symbol":"Table (ESM)","correct":"import Table from 'easy-table'"},{"note":"Static methods like `print` and helper functions like `number` are accessed as properties of the main `Table` export, not as named exports directly.","wrong":"import { print } from 'easy-table'; print(data)","symbol":"Table.print","correct":"import Table from 'easy-table'; Table.print(data)"}],"quickstart":{"code":"import Table from 'easy-table';\n\nconst data = [\n  { id: 123123, desc: 'Something awesome', price: 1000.00 },\n  { id: 245452, desc: 'Very interesting book', price: 11.45},\n  { id: 232323, desc: 'Yet another product', price: 555.55 }\n];\n\n// Using instance methods for fine-grained control\nlet t = new Table();\n\ndata.forEach(product => {\n  t.cell('Product Id', product.id);\n  t.cell('Description', product.desc);\n  t.cell('Price, USD', product.price, Table.number(2)); // Format price to 2 decimal places\n  t.newRow();\n});\n\nconsole.log('Formatted Table:\\n' + t.toString());\n\n// Using the static print method for quick rendering with options\nconsole.log('\\nAuto-generated Table with options:\\n' + Table.print(data, {\n  desc: { name: 'Product Description' }, // Rename column\n  price: { printer: Table.number(2) }     // Apply printer\n}));\n\n// Example of sorting and totaling\nlet sortableTable = new Table();\ndata.forEach(product => {\n  sortableTable.cell('Product Id', product.id);\n  sortableTable.cell('Description', product.desc);\n  sortableTable.cell('Price, USD', product.price);\n  sortableTable.newRow();\n});\nsortableTable.sort(['Price, USD|des']); // Sort by Price descending\nsortableTable.total('Price, USD', { printer: Table.aggr.printer('Total: ', Table.number(2)) });\n\nconsole.log('\\nSorted and Totaled Table:\\n' + sortableTable.toString());","lang":"typescript","description":"Demonstrates basic table creation, custom cell formatting, static `Table.print` usage with options, and sorting and totaling features."},"warnings":[{"fix":"Consider migrating to a more actively maintained library for text table rendering if new features, bug fixes, or security updates are required.","message":"The package appears to be abandoned, with no new features, bug fixes, or security updates for over 5 years. Relying on it for critical applications may pose risks.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Use `import Table from 'easy-table'` for ESM projects to correctly import the default export. For CommonJS, `const Table = require('easy-table')` is correct.","message":"The package primarily uses CommonJS module syntax (`require`). While it ships with TypeScript types, direct ESM `import { Table } from 'easy-table'` will likely fail in strict ESM environments because it's a default export from a CommonJS module.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure custom printer functions accept both `value` and `width` parameters and use `Table.padLeft` or `Table.padRight` with `width` if alignment is desired, as shown in the documentation example for `currency`.","message":"Custom cell 'printer' functions require explicit handling of the `width` parameter for correct padding. If `width` is not handled, content might not be correctly aligned or truncated when the library calculates layout.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Carefully check column names and use the exact `|asc` or `|des` suffixes. For complex sorting, consider providing a custom comparator function to `t.sort()`.","message":"Sorting columns by string-based syntax (e.g., `['Column Name|des']`) is specific and can be prone to typos. No validation is provided for column names or sort orders (e.g., 'des' vs 'descending').","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For ESM, use `import Table from 'easy-table'`. For CommonJS, ensure you're doing `const Table = require('easy-table')` if `Table` is the default/module.exports object.","cause":"Attempting to instantiate `Table` using an incorrect import, typically `import { Table } from 'easy-table'` instead of `import Table from 'easy-table'` in ESM, or `require('easy-table').Table` in CommonJS if it's a default export.","error":"TypeError: Table is not a constructor"},{"fix":"Ensure `let t = new Table()` is called after correctly importing `Table`.","cause":"`t` is not an instance of `Table`. This often happens if `new Table()` was not called, or the import of `Table` was incorrect, resulting in `t` being undefined or an unexpected object.","error":"TypeError: t.cell is not a function"},{"fix":"Switch to ESM import syntax: `import Table from 'easy-table'`. If you must use `require` in an ESM file, Node.js v22+ has some experimental support, or consider `await import('easy-table')` for older versions, or explicitly configure `type: 'commonjs'` in your `package.json`.","cause":"Attempting to use `require('easy-table')` in an ECMAScript Module (ESM) context (e.g., a file with `\"type\": \"module\"` in `package.json` or a `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Verify that the column name string passed to `t.sort()` is an exact match for one of the column headers used in `t.cell()`. Ensure sort order suffixes are strictly `|asc` or `|des`.","cause":"The string passed to `t.sort(['Column Name'])` does not exactly match a column name or uses an invalid sort order suffix (e.g., 'asc' vs 'ass').","error":"Table does not sort correctly or throws an error for column 'XYZ'"}],"ecosystem":"npm","meta_description":null}