Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 179 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# toroman

[![wakatime](https://wakatime.com/badge/github/Zubs/toRoman.svg)](https://wakatime.com/badge/github/Zubs/toRoman)

A minimalist library for Roman numeral operations.

## 🚀 Features

- Convert Arabic numerals to Roman numerals
- Convert Roman numerals to Arabic numerals 🔢
- Convert 🔁 Arabic numerals 🔢 to Roman numerals
- Convert 🔁 Roman numerals to Arabic numerals 🔢
- Validate Roman numerals ✅
- Add Roman numerals ➕
- Subtract Roman numerals ➖
- Multiply Roman numerals ✖️
- Divide Roman numerals ➗
- Get maximum Roman numeral ⬆️
- Get minimum Roman numeral ⬇️
- Get a random Roman numeral 🤹
- Generate a table of Roman numerals 📋
- Get Roman numerals within a range 📡

## 📦 Installation
Expand All @@ -27,17 +31,18 @@ npm i toroman
const roman = require("toRoman");
```

<!-- ### 🔩 Methods -->
## 🔩 Methods

#### 🔄 Convert integer to Roman numerals: `toRoman`
### 🔄 Convert integer to Roman numerals: `toRoman`

```js
```ts
/**
* toRoman - Convert an integer to Roman numerals
* 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
* @throws { Error } When the input is not a valid integer or is out of range
*/
function toRoman(value: number): string | Error {}
function toRoman(value: number): string {}
```

🔵 <b>Example</b>
Expand All @@ -48,15 +53,16 @@ console.log(roman.toRoman(765));
// Returns DCCLXV
```

#### 🔁 Convert Roman numeral to integer: `fromRoman`
### 🔁 Convert Roman numeral to integer: `fromRoman`

```js
```ts
/**
* fromRoman - Convert Roman numeral to integer
* Convert Roman numeral to integer
* @param { string } value Roman numeral to be converted to integer
* @returns { number } Integer representation of the input value
* @throws { Error } When the input is not a valid Roman numeral
*/
export function fromRoman(value: string): number | Error {}
function fromRoman(value: string): number {}
```

🔵 <b>Example</b>
Expand All @@ -67,15 +73,16 @@ console.log(roman.fromRoman("DCCLXV"));
// Returns 765
```

#### 🔍 Confirm if string is valid Roman numeral: `isRoman`
### 🔍 Confirm if string is valid Roman numeral: `isRoman`

```js
```ts
/**
* isRoman - Confirm that string is a valid Roman numeral
* Confirm that string is a valid roman numeral
* @param { string } value String to be tested
* @returns { boolean } true or false
* @throws { Error } When the input is not a valid roman numeral
*/
export function isRoman(value: string): true | Error {}
function isRoman(value: string): true {}
```

🔵 <b>Example</b>
Expand All @@ -86,17 +93,17 @@ console.log(roman.isRoman("MMMCCXXXIV"));
// Returns true
```

#### ➕ Sum Roman numerals and get output as Roman numeral or numbers: `sum`
### ➕ Sum Roman numerals and get output as a Roman numeral or numbers: `sum`

```js
```ts
/**
* @param args Roman numerals to be added
* @returns { string } Final Roman numeral
* Sum roman numerals
* @param expected { string } Expected response type
* @param args { string[] } Roman numerals to be added
* @returns { string | number } Final roman numeral
* @throws { Error } When the result exceeds maximum value of 3999 or invalid numeral is provided
*/
export function sum(
expected: "number" | "roman",
...args: string[]
): string | number | Error {}
function sum(expected: "number" | "roman", ...args: string[]): general {}
```

🔵 <b>Example</b>
Expand All @@ -107,15 +114,20 @@ console.log(roman.sum("number", "X", "MXC"));
// Returns 1100
```

#### ➖ Get difference between two Roman numerals and get output as Roman numeral or numbers: `diff`
### ➖ Get difference between two Roman numerals and get output as a Roman numeral or numbers: `diff`

```js
```ts
/**
* Get difference between two roman numerals
* @param expected { string } Expected response type
* @param numerals { string[] } Roman numerals to subtract
* @returns { string | number }
* @throws { Error } When more than two numerals are provided
*/
export function diff(expected: "number" | "roman", numerals: string[]) {}
function diff(
expected: "number" | "roman",
numerals: [string, string]
): general {}
```

🔵 <b>Example</b>
Expand All @@ -126,54 +138,170 @@ console.log(roman.diff("number", ["X", "MXC"]));
// Returns 1080
```

#### 📡 Get a range of Roman numerals: `range`
### ✖️ Multiply Roman numerals and get output as a Roman numeral or numbers: `multiply`

```ts
/**
* Multiply roman numerals
* @param expected { string } Expected response type
* @param args { string[] } Roman numerals to be added
* @returns { string | number } Final roman numeral
* @throws { Error } When the result exceeds maximum value of 3999 or invalid numeral is provided
*/
function multiply(expected: "number" | "roman", ...args: string[]): general {}
```

🔵 <b>Example</b>

```js
console.log(roman.multiply("roman", "X", "V"));

// Returns L
```

### ➗ Divide two Roman numerals and get output as a Roman numeral or numbers: `divide`

```ts
/**
* 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
* Divide two roman numerals
* @param expected { string } Expected response type
* @param numerals { string[] } Roman numerals to divide
* @returns { string | number }
* @throws { Error } When more than two numerals are provided
*/
export function range(
end: string | number,
start: string | number = "I",
intervals: string | number = "I"
): string[] | Error {}
function divide(
expected: "number" | "roman",
numerals: [string, string]
): general {}
```

🔵 <b>Examples</b>
🔵 <b>Example</b>

```js
console.log(roman.range(7));
console.log(roman.divide("number", ["L", "X"]));

// Returns [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII' ]
// Returns 5
```

### ⬆️ Get maximum Roman numeral from a list: `max`

```ts
/**
* Get maximum roman numeral from a list
* @param args { string[] } Roman numerals to compare
* @returns { string } Maximum roman numeral
* @throws { Error } When an invalid numeral is provided
*/
function max(...args: string[]): string {}
```

🔵 <b>Example</b>

```js
console.log(roman.max("X", "V", "III", "VIII"));

// Returns X
```

### ⬇️ Get minimum Roman numeral from a list: `min`

```ts
/**
* Get minimum roman numeral from a list
* @param args { string[] } Roman numerals to compare
* @returns { string } Minimum roman numeral
* @throws { Error } When an invalid numeral is provided
*/
function min(...args: string[]): string {}
```

🔵 <b>Example</b>

```js
console.log(roman.range("IX"));
console.log(roman.min("X", "V", "III", "VIII"));

// Returns [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' ]
// Returns III
```

### 🤹 Get a random Roman numeral: `random`

```ts
/**
* Generate a random Roman numeral within a specified range
* @param max Maximum value
* @param min Minimum value
* @returns { string } Random Roman numeral within the specified range
* @throws { Error } When the inputs are invalid or out of range
*/
function random(max: general = 3999, min: general = 1): string {}
```

🔵 <b>Example</b>

```js
console.log(roman.range(12, 7));
console.log(roman.random(10));

// Returns a random Roman numeral between I and X
```

// Returns [ 'VII', 'VIII', 'IX', 'X', 'XI', 'XII' ]
### 📋 Generate a table of Roman numerals: `table`

```ts
/**
* Generate a table of Roman numerals within a specified range
* @param start Starting point for table
* @param end Stopping point for table
* @returns { number: number; roman: string }[] Array of objects containing number and its Roman numeral representation
* @throws { Error } When the inputs are invalid or out of range
*/
function table(
start: general,
end: general
): { number: number; roman: string }[] {}
```

🔵 <b>Example</b>

```js
console.log(roman.range(12, "IX"));
console.log(roman.table("I", "V"));

// Returns [ 'IX', 'X', 'XI', 'XII' ]
/**
* Returns [
* { number: 1, roman: 'I' },
* { number: 2, roman: 'II' },
* { number: 3, roman: 'III' },
* { number: 4, roman: 'IV' },
* { number: 5, roman: 'V' }
* ]
*/
```

### 📡 Get a range of Roman numerals: `range`

```ts
/**
* 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
* @returns { string[] } Array of roman numerals in the specified range
* @throws { Error } When any of the inputs are invalid or out of range
*/
function range(
end: general,
start: general = "I",
intervals: general = "I"
): string[] {}
```

🔵 <b>Examples</b>

```js
console.log(roman.range(22, 3, 5));
console.log(roman.range(7));

// Returns [ 'III', 'VIII', 'XIII', 'XVIII' ]
// Returns [ 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII' ]
```

### ✨ Found this project useful?
## ✨ 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 🙂.
If you found this project useful, or you like what you see, then please consider giving it a ⭐️ on GitHub and sharing it with your social media folks 🙂.
16 changes: 8 additions & 8 deletions templates/contributing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to Transcriptase
# Contributing to toroman

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

Expand All @@ -8,13 +8,13 @@ We love your input! We want to make contributing to this project as easy and tra
- Proposing new features
- Becoming a maintainer

## We Develop with Github
## We Develop with GitHub

We use github to host code, to track issues and feature requests, as well as accept pull requests.
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.

## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
## We Use [GitHub Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests

Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
Pull requests are the best way to propose changes to the codebase (we use [GitHub Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:

1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
Expand All @@ -27,9 +27,9 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using Github's [issues](https://github.com/Zubs/toRoman/issues)
## Report bugs using GitHub's [issues](https://github.com/Zubs/toRoman/issues)

We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/Zubs/toRoman/issues); it's that easy!

## Write bug reports with detail, background, and sample code

Expand All @@ -50,7 +50,7 @@ People _love_ thorough bug reports. I'm not even kidding.
I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)

- 2 spaces for indentation rather than tabs
- You can try running `npm run lint` for style unification
- You can try running `npm run format` for style unification

## License

Expand Down