@pfarr.tools/romanize
v1.0.0
Published
Converts integers to Roman numeral strings.
Maintainers
Readme
@pfarr.tools/romanize
Converts positive integers to Roman numeral strings.
Installation
npm install @pfarr.tools/romanizeUsage
ESM
import { romanize } from '@pfarr.tools/romanize';
romanize(1); // 'I'
romanize(4); // 'IV'
romanize(9); // 'IX'
romanize(1994); // 'MCMXCIV'
romanize(2024); // 'MMXXIV'
romanize('X'); // NaNCommonJS
const { romanize } = require('@pfarr.tools/romanize');Default export
import romanize from '@pfarr.tools/romanize';API
romanize(num)
| Parameter | Type | Description |
|-----------|------|-------------|
| num | number \| string | A positive integer (or numeric string) to convert. |
Returns string — the Roman numeral representation, or NaN if num is not a valid number.
Supported range
1 to 3 999 999 (outputs become increasingly unwieldy beyond 3 999 due to the
unbounded M prefix, but the function never throws).
Subtractive notation
The standard subtractive pairs are used:
IV (4), IX (9), XL (40), XC (90), CD (400), CM (900).
Examples
romanize(42); // 'XLII'
romanize(99); // 'XCIX'
romanize(399); // 'CCCXCIX'
romanize(1776); // 'MDCCLXXVI'
romanize(3999); // 'MMMCMXCIX'License
GPL-3.0-or-later — © Christoph Fischer [email protected]
