Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@qit.tools/ordinal-format
Advanced tools
This tiny library (🪶 726 bytes) given number into its ordinal representation based on the specified locale and custom suffixes. Ordinal numbers denote position or order (e.g., 1st, 2nd, 3rd).
This tiny library (🪶 726 bytes) converts numbers into their ordinal representation based on the specified locale and custom suffixes. Ordinal numbers denote position or order (e.g., 1st, 2nd, 3rd).
The library provides a simple utility to format numbers as ordinal strings, supporting different locales and custom suffixes, utilizing Intl.PluralRules().
npm i @qit.tools/ordinal-format
pnpm add @qit.tools/ordinal-format
yarn add @qit.tools/ordinal-format
import { OrdinalFormat } from "@qit.tools/ordinal-format";
const ordinal = new OrdinalFormat();
console.log(ordinal.format(1)); // '1st'
console.log(ordinal.format(2)); // '2nd'
console.log(ordinal.format(3)); // '3rd'
const frSuffixes = [
["one", "er"],
["other", "e"]
];
const ordinal = new OrdinalFormat({ locale: "fr-FR", suffixes: frSuffixes });
console.log(ordinal.format(1)); // '1er'
console.log(ordinal.format(2)); // '2e'
console.log(ordinal.format(3)); // '3e'
const pluralSuffixes = [
["one", " cat"],
["other", " cats"]
];
const ordinal = new OrdinalFormat({ locale: "en-US", suffixes: pluralSuffixes });
console.log(ordinal.format(1)); // '1 cat'
console.log(ordinal.format(2)); // '2 cats'
console.log(ordinal.format(3)); // '3 cats'
OrdinalFormat
A class to format numbers as ordinal strings.
constructor(options?: Options)
options
(Options, optional): An optional object to specify the locale and custom suffixes.formatOrdinal
Formats a number as an ordinal string.
formatOrdinal(num: number): string
num
(number): The number to be formatted as an ordinal.type Options = {
locale?: string;
suffixes?: [string, string][];
};
locale
(optional): The locale code (e.g., "en-US", "fr-FR") that determines the language rules for ordinal formatting. Defaults to "en-US".suffixes
(optional): An array of tuples, where each tuple consists of a plural rule category (e.g., "one", "two", "few", "other") and its corresponding ordinal suffix.MIT
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Developed by Qit.tools.
Feel free to explore the source code and contribute to this library on GitHub.
FAQs
This tiny library (🪶 726 bytes) given number into its ordinal representation based on the specified locale and custom suffixes. Ordinal numbers denote position or order (e.g., 1st, 2nd, 3rd).
We found that @qit.tools/ordinal-format demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.