npm.io
1.1.1 • Published 1 month ago

@tammergard/roman

Licence
MIT
Version
1.1.1
Deps
0
Size
5 kB
Vulns
0
Weekly
0

@tammergard/roman

Convert to and from roman numerals.

Installation

# npm
npm install @tammergard/roman

# pnpm
pnpm add @tammergard/roman

# bun
bun add @tammergard/roman

Usage

import { fromRoman, pattern, toRoman } from "@tammergard/roman"

toRoman(123) // "CXXIII"
fromRoman("CXXIII") // 123

pattern.test("MMXXIV") // true
pattern.test("VIIII") // false

API

toRoman(arabic: number): string

Converts an integer in the range 13999 to a roman numeral. Throws if the input is not a number, is 0, is negative, is a decimal, or is 4000 or greater.

fromRoman(roman: string): number

Parses a roman numeral and returns its arabic value. Throws if the input is not a string or not a valid roman numeral.

pattern: RegExp

The regular expression used to validate roman numerals (13999).

License

MIT