roman-numerals-api
v1.0.6
Published
CLI - The library allows to convert Arabic numerals to Roman numerals and vice versa.
Maintainers
Readme
Roman numerals
CLI - The library allows to convert Arabic numerals to Roman numerals and vice versa.
Install
npm i roman-numerals-apiUsage
roman-numeralsAPI - JavaScript
The module exports an object with two methods:
parse(str): Receives aStringas a single argument and returns a number (Number) if it is a valid Roman numeral, otherwise it will throw an error specifying the cause.stringify(num): Receives a number (Number) and returns aStringwith the representation of the received number as a Roman numeral. In case the number is out of range (1 <= num <= 3999).
Example of use:
const { parse, stringify } = require('roman-numerals-convers');
console.log(parse('I') === 1); // true
console.log(parse('III') === 3); // true
console.log(parse('IV') === 4); // true
console.log(parse('IX') === 9); // true
console.log(parse('MCMXLIV') === 1944); // true
console.log(stringify(1) === 'I'); // true
console.log(stringify(3) === 'III'); // true
console.log(stringify(4) === 'IV'); // true
console.log(stringify(9) === 'IX'); // true
console.log(stringify(1944) === 'MCMXLIV'); // true
console.log(parse(stringify(1)) === 1); // true
console.log(parse(stringify(3)) === 3); // true
console.log(parse(stringify(4)) === 4); // true
console.log(parse(stringify(9)) === 9); // true
console.log(parse(stringify(1944)) === 1944); // trueCLI - Command Line Interface
The module can be installed with the npm i roman-numerals-convert command globally and also using the npx command (a tool that comes with node and npm).
This interface offers two sub-commands (parse and stringify) plus options to display help (--help) and the module version (--version).
Examples
You can also execute directly with the romans-numerals command.
Comands
parse
$ npx roman-numerals parse MMXX 2020stringify
$ npx roman-numerals stringify 2020 MMXX
Options
--version
$ npx roman-numerals -v 1.0.5--help
$ npx roman-numerals -h Usage: roman-numerals [opttions] <command> [<input>] Commands: parse <input> Parse a roman numeral string into an integer. stringify <input> Takes an integer and converts it to a roman numeral. Options: --h,--help Show this help. --v,--version Show version number.
Install - NPM
You can download the package NPM.
License
roman-numerals is released under the MIT License.
