Internationalization (i18n) to get the ordinal numbers in every languages.
1st, 2nd, 3rd, 4th …
1.º, 2.º, 3.º …
1.ª, 2.ª, 3.ª …
last, 2nd to last, 3rd to last …
nth, nth to last
# npm
npm install intl-ordinal
# yarn
yarn add intl-ordinal
# pnpm
pnpm add intl-ordinal
import ordinal from "intl-ordinal";
// Get ordinal numbers
console.log(ordinal("en-US").format(3)); // "3rd"
// BigInt
console.log(ordinal("en-US").format(12n)); // "12th"
// With gender (defaults to male)
console.log(ordinal("es-ES").format(5)); // "5.º"
console.log(ordinal("es-ES", { gender = "female" }).format(5)); // "5.ª"
// From last
console.log(ordinal("en-US").format(-1)); // "last"
console.log(ordinal("en-US").format(-128)); // "128th to last"
// nth
console.log(ordinal("en-US").format(Infinity)); // "nth"
console.log(ordinal("en-US").format(-Infinity)); // "nth to last"
console.log(ordinal("de-DE").format(Infinity)); // "x-te"
// Check if the locale is supported\
console.log(ordinal("en-GB").supports); // true
console.log(ordinal("art-x-myownlanguage").supports); // false
intl-ordinal is available under the MIT License. See the LICENSE file for more info.
If you would like support for other languages, please submit an issue.
The resources in the existing languages are obtained through data query, and are not guaranteed to be all correct. Corrections are welcome.
Supported languages
- English
- Chinese
- Japanese
- Korean
- Vietnamese
- Indonesian
- Malay
- French
- Spanish
- Portuguese
- Italian
- German
- Russian