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.
npm install --save romanizr
yarn add romanizr
import { deromanize } from "romanizr";
const decimal = deromanize("MDCCLXXVI");
// decimal = 1776
import { romanize } from "romanizr";
const romans = romanize(1776);
// romans = "MDCCLXXVI"
import { deromanizeText } from "romanizr";
const result = decimalizeText("In Year MMXII We Will All Die");
// result = "In Year 2012 We Will All Die"
import { romanizeText } from "romanizr";
const result = romanizeText("In Year 2012 We Will All Die");
// result = "In Year MMXII We Will All Die"
import { matchRomans } from "romanizr";
const matches = matchRomans("Match Roman numerals MMXII in this string");
// matches[0][0] = "MMXII"