roman2int
Convert roman numerals to arabic number.
Romans Numerals are based on the following symbols.
{
I: 1;
V: 5;
X: 10;
L: 50;
C: 100;
D: 500;
M: 1000;
}
Roman Numerals rules
When a symbol appears after a larger (or equal) symbol it is added. But if the symbol appears before a larger symbol it is subtracted. Don't use the same symbol more than three times in a row.
NOTE: The bars are not compatible, so the maximum supported Roman number is MMMCMXCIX, which is equal to 3999.
Installation
Use the package manager npm to install roman2int.
npm i roman2int
Usage
Default use
// main.js
const roman2int = require('roman2int');
const convertResult = roman2int("MMXXII");
console.log(convertResult.success, convertResult.value); // true, 2022
Module use
// main.js
import roman2int from "roman2int/roman2int.es.js";
const convertResult = roman2int("MMXXII");
console.log(convertResult.success, convertResult.value); // true, 2022
On error
const roman2int = require('roman2int');
const convertResult = roman2int("XXXXX");
console.dir(convertResult);
// convertResult
{
value: null,
success: false,
message: 'Invalid or unsupported roman numeral'
}
Usage example
Live on Runkit roman2int and Runkit roman2int example
Running the tests
git clone https://github.com/mc-ireiser/roman2int.git
cd roman2int
npm i
npm run test
License
This project is licensed under the MIT License - see the LICENSE file for details.