/REG003-roman-numerals

Primary LanguageTypeScriptMIT LicenseMIT

Roman Numerals

Roman numerals is a module that allows you to convert Arabic numbers into Roman numbers and vice versa.

Installation

In the same directory as your package.json file, create or edit an .npmrc file to include this line:

registry=https://npm.pkg.github.com/andy164

As a dependency in your project

  1. Install from the command line:
npm install @andy164/roman-numerals@1.0.1
  1. Install via package.json:
"@andy164/roman-numerals": "1.0.1"
npm install

Usage

1. API

The module exports two methods:

parse(str): Recibe un String como único argumento y retorna un número (Number) en caso que sea un número romano válido, en caso contrario arrojará un error especificando la causa.

parse(str)

It receives a string as the only argument and returns a number (Number) in case it is a valid Roman number, otherwise it will throw an error specifying the cause.

stringify(num)

It receives a number (Number) and returns a String with the representation of the number received as a Roman number. In case the number is out of range (1 <= num <= 3999) it will throw an error.

Example

const { parse, stringify } = require('usuario-de-github/roman-numerals');

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); // true

2. CLI

Roman numerlas can be run as follows via terminal:

roman-numerlas [options] <command> [<input>]

$ 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.

Example

$ npx roman-numerals parse MMXX
2020

$ npx roman-numerals stringify 2020
MMXX

$ npx roman-numerals -v
1.0.0

License

See the license here.


Learning objectives

Node.js

JavaScript

Control de Versiones (Git y GitHub)

  • Git: Instalación y configuración

  • Git: Control de versiones con git (init, clone, add, commit, status, push, pull, remote)

  • [-] Git: Integración de cambios entre ramas (branch, checkout, fetch, merge, reset, rebase, tag)

  • GitHub: Creación de cuenta y repos, configuración de llaves SSH

  • [-] GitHub: Colaboración en Github (branches | forks | pull requests | code review | tags)

  • [-] GitHub: Organización en Github (projects | issues | labels | milestones | releases)

Additional reading