roman2int

2.0.2 • Public • Published

MIT license GitHub repo size npm Node.js CI David Snyk Vulnerabilities for npm package Codacy grade Coveralls github npm Package Quality

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.

Package Sidebar

Install

npm i roman2int

Weekly Downloads

2

Version

2.0.2

License

MIT

Unpacked Size

6.99 kB

Total Files

5

Last publish

Collaborators

  • ireiser