Humanize Plus Utilities
raw JSON →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).
Common errors
error TypeError: Humanize.intcomma is not a function ↓
Humanize.intcomma(...) to Humanize.intComma(...). error ReferenceError: Humanize is not defined ↓
<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 ↓
<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' ↓
require syntax: const Humanize = require('humanize-plus'); and then access methods like Humanize.compactInteger(...). Warnings
deprecated The `intcomma` method is deprecated. Use `Humanize.intComma` (camelCase) instead. ↓
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). ↓
deprecated The `truncatenumber` method is deprecated. Use `Humanize.boundedNumber` instead. ↓
deprecated The `filesize` method is deprecated. Use `Humanize.fileSize` (camelCase) instead. ↓
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. ↓
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. ↓
Install
npm install humanize-plus yarn add humanize-plus pnpm add humanize-plus Imports
- Humanize wrong
import Humanize from 'humanize-plus';correctconst Humanize = require('humanize-plus'); - Humanize wrong
require('humanize-plus'); // Not for browser global scopecorrect// <script src="humanize.min.js"></script> // ... then access via global `Humanize` object - compactInteger wrong
import { compactInteger } from 'humanize-plus';correctconst Humanize = require('humanize-plus'); Humanize.compactInteger(123456, 1);
Quickstart
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"