Skip to content

Romanize decimals. Deromanize Roman numerals.

License

Notifications You must be signed in to change notification settings

mekwall/romanizr

Repository files navigation

romanizr

license npm dependencies types coverage

Romanize decimals. Deromanize Roman numerals.

This is a hybrid package that provides both CommonJS and ES modules with zero dependencies.

The regular expression used to match Roman numerals is a modified version of Reilly's Modern roman numerals strict expression. I wrote an answer on StackOverflow related to this.

NOTE: This library only support the Roman numeral standard form. That means that the largest number that can be represented is 3,999 (MMMCMXCIX). There are variant forms out there that allow for higher numbers but I don't think there's a need to implement any of them.

Installation

npm

npm install --save romanizr

Yarn

yarn add romanizr

Usage

Deromanize a Roman numeral

import { deromanize } from "romanizr";

const decimal = deromanize("MDCCLXXVI");
// decimal = 1776

Romanize a decimal

import { romanize } from "romanizr";

const romans = romanize(1776);
// romans = "MDCCLXXVI"

Deromanize Roman numerals in text

import { deromanizeText } from "romanizr";

const result = decimalizeText("In Year MMXII We Will All Die");
// result = "In Year 2012 We Will All Die"

Romanize decimals in text

import { romanizeText } from "romanizr";

const result = romanizeText("In Year 2012 We Will All Die");
// result = "In Year MMXII We Will All Die"

Matching Roman numerals within a string

import { matchRomans } from "romanizr";

const matches = matchRomans("Match Roman numerals MMXII in this string");
// matches[0][0] = "MMXII"

License

MIT

About

Romanize decimals. Deromanize Roman numerals.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •