Humanize Plus Utilities

raw JSON →
1.8.2 verified Sat Apr 25 auth: no javascript maintenance

Humanize Plus is a utility library designed to make data presented on the web more digestible and 'humane'. It provides a collection of functions for formatting numbers, file sizes, and time-related values into human-readable strings. The current stable version is 1.8.2, with recent releases primarily focusing on minor updates and deprecating older methods in preparation for a potential v2.0. The library's release cadence appears to be slow, with several months or years between significant updates. Key differentiators include its broad range of number and time formatting utilities, such as `compactInteger` for abbreviating large numbers, `fileSize` for converting byte counts, `intComma` for comma-separating integers, `ordinal` for adding suffixes like "st" or "nd", and `pace` for interpreting rates over time. It supports both Node.js (via CommonJS) and browser environments (via a global `Humanize` object).

error TypeError: Humanize.intcomma is not a function
cause Attempting to use the deprecated lowercase method name `intcomma` instead of `intComma`.
fix
Change the method call from Humanize.intcomma(...) to Humanize.intComma(...).
error ReferenceError: Humanize is not defined
cause The `humanize-plus` script has not been loaded in the browser, or it's being accessed outside its intended scope.
fix
Ensure <script src="humanize.min.js"></script> is correctly included in your HTML before attempting to use the Humanize global object.
error ReferenceError: require is not defined
cause Attempting to use Node.js CommonJS `require()` in a browser environment without a module bundler.
fix
For browser usage, include the library via a <script> tag and access the global Humanize object. If using a bundler (like Webpack or Rollup), ensure it's configured to handle CommonJS modules.
error SyntaxError: The requested module 'humanize-plus' does not provide an export named 'compactInteger'
cause Attempting to use ES module named imports for `humanize-plus`, which is a CommonJS module that exports a single object.
fix
Use CommonJS require syntax: const Humanize = require('humanize-plus'); and then access methods like Humanize.compactInteger(...).
deprecated The `intcomma` method is deprecated. Use `Humanize.intComma` (camelCase) instead.
fix Replace `Humanize.intcomma(...)` with `Humanize.intComma(...)`.
deprecated The `intword` method is deprecated. It is now a thin wrapper around `Humanize.compactInteger` and will be removed in the next major version (v2).
fix Migrate to using `Humanize.compactInteger(...)` directly for future compatibility.
deprecated The `truncatenumber` method is deprecated. Use `Humanize.boundedNumber` instead.
fix Replace `Humanize.truncatenumber(...)` with `Humanize.boundedNumber(...)`.
deprecated The `filesize` method is deprecated. Use `Humanize.fileSize` (camelCase) instead.
fix Replace `Humanize.filesize(...)` with `Humanize.fileSize(...)`.
breaking Support for Node.js v0.6 was dropped in version 1.5.0. Ensure your Node.js environment is v0.8.0 or newer.
fix Upgrade your Node.js runtime to version 0.8.0 or higher.
breaking Several methods (intcomma, intword, truncatenumber, filesize) have been marked as deprecated since v1.4.2 and are explicitly stated to 'not be present in the next major version' (v2). Relying on these will cause breakage.
fix Update all calls to deprecated methods to their recommended replacements (e.g., `intComma`, `compactInteger`, `boundedNumber`, `fileSize`) before upgrading to version 2.x.
npm install humanize-plus
yarn add humanize-plus
pnpm add humanize-plus

Demonstrates importing `humanize-plus` in Node.js and using several core formatting functions like `compactInteger`, `fileSize`, `intComma`, and `ordinal`.

const Humanize = require('humanize-plus');

console.log('Original number:', 123456789);
console.log('Compact integer (1 decimal place):', Humanize.compactInteger(123456789, 1));
// Expected: "123.5M"

console.log('Original file size:', 1024 * 2000);
console.log('Human-readable file size:', Humanize.fileSize(1024 * 2000));
// Expected: "1.95 Mb"

console.log('Formatting with commas:', Humanize.intComma(987654321));
// Expected: "987,654,321"

console.log('Ordinal for 22:', Humanize.ordinal(22));
// Expected: "22nd"