1.0.0 • Published 3 months ago

nthify v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

nthify

Archetype: Node.js package

nthify converts numbers into their ordinal representation such as 1st, 2nd, 3rd and so on.

Details

Lightweight – No dependencies.
Fast & Simple – One function, optimized.
Handles Edge Cases – Supports special numbers (e.g., 11th, 12th, 13th).
Fully Typed – Includes TypeScript definitions.

Install

npm install nthify

Usage

import nthify from 'nthify';

console.log(nthify(1)); // "1st"
console.log(nthify(2)); // "2nd"
console.log(nthify(3)); // "3rd"
console.log(nthify(4)); // "4th"
console.log(nthify(11)); // "11th"
console.log(nthify(21)); // "21st"
console.log(nthify(100)); // "100th"
console.log(nthify(101)); // "101st"

⚙️ API

nthify(number)

Converts a number into its ordinal representation.

Parameters

NameTypeDefaultDescription
numbernumberRequiredThe number to convert to an ordinal string.

Returns

  • string – The number with the correct ordinal suffix.

Throws

  • TypeError – If the input is not a valid number.

Related Links

This package is part of my highsociety meta suite:

https://github.com/alexstevovich/commadus-node - Formalized lists supporting oxford commas

Development Homepage

https://github.com/alexstevovich/nthify-node

This link might be suffixed with "-node" in the future if conflicts arise.

License

Licensed under the Apache License 2.0.