romanizr
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

romanizr

license npm dependencies types coverage quality

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"

License

MIT

Package Sidebar

Install

npm i romanizr

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

16.1 kB

Total Files

35

Last publish

Collaborators

  • mekwall