or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

file-size.mdindex.mdnumber-formatting.mdpluralization-lists.mdstring-operations.mdutility-functions.md
tile.json

index.mddocs/

Humanize Plus

Humanize Plus is a simple utility library for making the web more humane. It provides functions for formatting numbers with commas and compact representations, converting integers to ordinals, pluralizing words, truncating and capitalizing strings, formatting file sizes in human-readable formats, and creating readable lists from arrays.

Package Information

  • Package Name: humanize-plus
  • Package Type: npm
  • Language: JavaScript
  • Installation:
    npm install humanize-plus

Core Imports

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

For ES6 modules:

import Humanize from 'humanize-plus';

Browser global:

<script src="humanize.min.js"></script>
<script>
  // Humanize is available globally
</script>

Basic Usage

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

// Format numbers
console.log(Humanize.intComma(1234567)); // "1,234,567"
console.log(Humanize.compactInteger(1234567, 1)); // "1.2M"

// File sizes
console.log(Humanize.fileSize(1024 * 1024)); // "1.00 MB"

// String operations
console.log(Humanize.capitalize('hello world')); // "Hello world"
console.log(Humanize.truncate('This is a long string', 10)); // "This is..."

// Pluralization and lists
console.log(Humanize.pluralize(3, 'cat')); // "cats"
console.log(Humanize.oxford(['red', 'green', 'blue'])); // "red, green, and blue"

Architecture

Humanize Plus exposes a single Humanize object containing all utility functions. The library uses a UMD wrapper for compatibility across CommonJS, AMD, and browser global environments. All functions are stateless utilities that accept input parameters and return formatted strings or numbers.

Capabilities

Number Formatting

Functions for formatting numbers with thousand separators, compact notation, ordinals, and bounded values.

// Add commas to numbers
function intComma(number: number, decimals?: number): string;

// Compact integer representation (1k, 1M, 1B, 1T)
function compactInteger(input: number, decimals?: number): string;

// Convert to ordinal (1st, 2nd, 3rd, etc.)
function ordinal(value: number): string;

// Format with custom separators
function formatNumber(
  number: number, 
  precision?: number, 
  thousand?: string, 
  decimal?: string
): string;

// Bound number to upper limit
function boundedNumber(num: number, bound?: number, ending?: string): string;

Number Formatting

File Size Formatting

Human-readable file size formatting with appropriate units.

// Convert bytes to human-readable format
function fileSize(filesize: number, precision?: number): string;

File Size Formatting

String Operations

Text manipulation including capitalization, truncation, and line break conversion.

// Capitalize first letter
function capitalize(string: string, downCaseTail?: boolean): string;

// Capitalize all words
function capitalizeAll(string: string): string;

// Title case with proper grammar
function titleCase(string: string): string;

// Truncate to character or word limit
function truncate(str: string, length?: number, ending?: string): string;
function truncateWords(string: string, length: number): string;

// Convert line breaks
function nl2br(string: string, replacement?: string): string;
function br2nl(string: string, replacement?: string): string;

String Operations

Pluralization and Lists

Functions for handling pluralization and converting arrays to readable strings.

// Pluralize words based on count
function pluralize(number: number, singular: string, plural?: string): string;

// Convert arrays to Oxford comma lists
function oxford(items: string[], limit?: number, limitStr?: string): string;

// Convert occurrence counts to words
function times(value: number, overrides?: object): string;

Pluralization and Lists

Utility Functions

Helper functions for precision handling and object conversion.

// Fix JavaScript's toFixed rounding issues
function toFixed(value: number, precision?: number): string;

// Normalize precision to positive integer
function normalizePrecision(value: number, base?: number): number;

// Convert objects to definition strings
function dictionary(object: object, joiner?: string, separator?: string): string;

// Calculate pace/frequency
function pace(value: number, intervalMs: number, unit?: string): string;

// Describe array frequency
function frequency(list: any[], verb: string): string;

Utility Functions

Deprecated Functions

The following functions are deprecated and will be removed in the next major version:

  • intword
    → use
    compactInteger
  • intcomma
    → use
    intComma
  • filesize
    → use
    fileSize
  • truncatewords
    → use
    truncateWords
  • truncatenumber
    → use
    boundedNumber
  • titlecase
    → use
    titleCase