Skip to the content.

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

// default use
const roman2int = require('roman2int');

const number = roman2int("MMXX"); // 2020

To activate IntelliSense in VSCode (Tested on v-1.44.2)

// for VScode IntelliSense
const roman2int = require("roman2int/lib/index");

const number = roman2int("MMXX"); // 2020

IntelliSense

IntelliSense is a general term for a variety of code editing features including: code completion, parameter info, quick info, and member lists. IntelliSense features are sometimes called by other names such as “code completion”, “content assist”, and “code hinting.” visualstudio docs.

To use the minified version

// for minified version
const roman2int = require("roman2int/dist/index.min");

const number = roman2int("MMXX"); // 2020

Usage example

See the example.js file in the usage folder

npm run usage

# node usage/example.js

Live on Runkit roman2int and Runkit roman2int example

Running the tests

mkdir test-roman2int-folder

cd test-roman2int-folder

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.