romanizr
v1.0.2
Published
Romanize decimals. Decimalize romans.
Downloads
5
Maintainers
Readme
romanizr
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 install --save romanize
$ yarn add romanize
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"