Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ordinal-number

amitx-npm93ISC1.1.0TypeScript support: included

Lightweight, dependency-free utility to convert numbers to ordinal strings.

converter, number, ordinal, ordinal-number, ordinalize, suffix, humanize, format, i18n, internationalization, utility, lightweight, zero-dependencies

readme

ordinal-number

npm version npm downloads CI license: ISC

Lightweight, dependency-free utility to convert numbers to their ordinal strings: 1 -> 1st, 2 -> 2nd, 3 -> 3rd, …

Install

npm i ordinal-number
# or
pnpm add ordinal-number
# or
yarn add ordinal-number

Usage

ESM:

import ordinal from 'ordinal-number';

ordinal(1); // "1st"
ordinal(2); // "2nd"

CommonJS:

const ordinal = require('ordinal-number');

ordinal(3); // "3rd"
ordinal(11); // "11th"

TypeScript:

import { ordinal } from 'ordinal-number';

const out: string = ordinal(22);

API

ordinal(input: number | bigint | string): string

Converts an integer-like input into a string with an ordinal suffix. Handles:

  • 0: 0th
  • Negatives: -1st, -2nd, -3rd, -11th
  • Very large integers: via bigint or numeric strings
  • Strings: numeric strings are parsed; other inputs are stringified as-is

Edge cases

ordinal(0);      // "0th"
ordinal(-1);     // "-1st"
ordinal(11);     // "11th"
ordinal(12);     // "12th"
ordinal(13);     // "13th"
ordinal(111);    // "111th"
ordinal(112);    // "112th"
ordinal(113);    // "113th"
ordinal(101);    // "101st"
ordinal(-22);    // "-22nd"
ordinal(12345678901234567890n); // "12345678901234567890th"
ordinal('42');   // "42nd"
ordinal('foo');  // "foo" (non-numeric strings are returned stringified)

Why this package?

  • Dependency-free and tiny
  • Dual ESM/CJS with TypeScript types
  • Robust edge-case handling

Contributing

See CONTRIBUTING.md.

License

ISC © Amit

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[1.1.0] - 2025-09-10

Added

  • Rewrote in TypeScript with strong types and edge-case handling
  • Dual ESM/CJS builds via tsup with type declarations
  • Vitest test suite with coverage
  • ESLint + Prettier configuration
  • GitHub Actions CI for build and tests
  • CONTRIBUTING, LICENSE, and updated README

Changed

  • Package metadata and keywords improved

[1.0.3] - 2019-xx-xx

  • Original JavaScript implementation and publish