1.2.1 ā€¢ Published 2 years ago

toroman v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

toroman

A minimalist library for Roman numeral operations.

šŸš€ Features

  • Convert Arabic numerals to Roman numerals ā…¦
  • Convert Roman numerals to Arabic numerals šŸ”¢
  • Validate Roman numerals āœ…
  • Add Roman numerals āž•
  • Subtract Roman numerals āž–
  • Get Roman numerals within a range šŸ“”

šŸ“¦ Installation

It can be installed with npm.

npm i toroman

šŸ“„ Usage

const roman = require("toRoman");

šŸ”„ Convert integer to Roman numerals: toRoman

/**
 * toRoman - Convert an integer to Roman numerals
 * @param { number } value Integer to be converted to Roman numerals
 * @returns { string } Roman numeral representation of the input value
 */
function toRoman(value: number): string | Error {}

šŸ”µ Example

console.log(roman.toRoman(765));

// Returns DCCLXV

šŸ” Convert Roman numeral to integer: fromRoman

/**
 * fromRoman - Convert Roman numeral to integer
 * @param { string } value Roman numeral to be converted to integer
 * @returns { number } Integer representation of the input value
 */
export function fromRoman(value: string): number | Error {}

šŸ”µ Example

console.log(roman.fromRoman("DCCLXV"));

// Returns 765

šŸ” Confirm if string is valid Roman numeral: isRoman

/**
 * isRoman - Confirm that string is a valid Roman numeral
 * @param { string } value String to be tested
 * @returns { boolean } true or false
 */
export function isRoman(value: string): true | Error {}

šŸ”µ Example

console.log(roman.isRoman("MMMCCXXXIV"));

// Returns true

āž• Sum Roman numerals and get output as Roman numeral or numbers: sum

/**
 * @param args Roman numerals to be added
 * @returns { string } Final Roman numeral
 */
export function sum(
  expected: "number" | "roman",
  ...args: string[]
): string | number | Error {}

šŸ”µ Example

console.log(roman.sum("number", "X", "MXC"));

// Returns 1100

āž– Get difference between two Roman numerals and get output as Roman numeral or numbers: diff

/**
 * @param expected { string } Expected response type
 * @param numerals { string[] } Roman numerals to subtract
 * @returns { string | number }
 */
export function diff(expected: "number" | "roman", numerals: string[]) {}

šŸ”µ Example

console.log(roman.diff("number", ["X", "MXC"]));

// Returns 1080

šŸ“” Get a range of Roman numerals: range

/**
 * Get range of Roman numerals
 * @param end { string | number } Value to stop at
 * @param start { string | number } Value to start from
 * @param intervals { string | number } Difference between values
 */
export function range(
  end: string | number,
  start: string | number = "I",
  intervals: string | number = "I"
): string[] | Error {}

šŸ”µ Examples

console.log(roman.range(7));

// Returns [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII' ]
console.log(roman.range("IX"));

// Returns [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' ]
console.log(roman.range(12, 7));

// Returns [ 'VII', 'VIII', 'IX', 'X', 'XI', 'XII' ]
console.log(roman.range(12, "IX"));

// Returns [ 'IX', 'X', 'XI', 'XII' ]
console.log(roman.range(22, 3, 5));

// Returns [ 'III', 'VIII', 'XIII', 'XVIII' ]

āœØ Found this project useful?

If you found this project useful or you like what you see, then please consider giving it a :star: on Github and sharing it with your social media folks šŸ™‚.

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago