roman-numerals

Use

import { toArabic, toRoman } from "https://deno.land/x/roman_numerals/mod.ts";

console.log(toArabic("XLII")); // 42
console.log(toArabic("xlii")); // 42
console.log(toRoman(42)); // "XLII"
console.log(toRoman("42")); // "XLII"

This module has been converted to ESM-formatted TypeScript, but its API is otherwise unchanged (with the notable exception that non-primitives are no longer accepted as arguments).

To-do: Update this readme

Readme contents from original NPM module:

Installation

Using npm:

$ npm install roman-numerals

Using git:

$ git clone git@github.com:joshleaves/roman-numerals.git

Usage

roman-numerals.toArabic(roman)

toArabic() takes a roman number (as a string literal or a string object) and returns a number with the arabic equivalent.

var toArabic = require('roman-numerals').toArabic;
[ 'XLII', new String('XLII') ].forEach(function (x, i) {
    console.log('%d: %s', i, toArabic(x));
});

Will output:

0: 42
1: 42

toArabic() will throw a TypeError when passed a non-string variable and will throw an Error when passed an invalid roman number. Acceptable strings are also "nulla" and "" (that's empty string) which will both return 0.

roman-numerals.toRoman(arabic)

toRoman() takes an arabic number (as a number literal, a number object, a stringed literal number or a stringed object number) and returns a string with the roman equivalent.

var toRoman = require('roman-numerals').toRoman;
[ 42, new Number(42), '42', new String('42')].forEach(function (x, i) {
    console.log('%d: %s', i, toRoman(x));
});

Will output:

0: XLII
1: XLII
2: XLII
3: XLII

toRoman() will throw a TypeError when passed a non-number variable or NaN and will throw an Error when passed a number under 0 or over 3999.

Tests

Unit tests are done using mocha. To run the tests on your machine, install mocha using npm and run make test or npm test.

$ npm install --dev
$ make test

You can also use make nyan for something new.