Skip to main content
Deno 2 is finally here 🎉️
Learn more

roman-numerals

Use

import { toArabic, toRoman } from "https://deno.land/x/roman_numerals/mod.ts";

console.log(toArabic("XLII")); // 42
console.log(toArabic("xlii")); // 42
console.log(toRoman(42)); // "XLII"
console.log(toRoman("42")); // "XLII"

Notes

This module started as a port of the npm package roman-numerals (see ACKNOWLEDGEMENTS.md). The API is the same (with the notable exception that non-primitives are not accepted as arguments).

The provided functions convert between roman numerals and arabic integers. The conversions utilize the “standard form” of roman numerals, so only values from 0 to 3999 (inclusive) are valid. Any values outside this range will throw an error.

Exports

toArabic

function toArabic(roman: string): number

Converts a valid roman number to its arabic equivalent.

In addition to roman numerals in range, acceptable strings are also "nulla" and "" (an empty string) which will both return 0.

toRoman

function toRoman(arabic: number | string): string

Converts an arabic number (0 to 3999 inclusive) to its roman equivalent.

The function will attempt to parse string integers. It will throw a TypeError on non-number inputs or NaN.

Tests

deno test