Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsejcksn/deno-roman-numerals
https://github.com/jsejcksn/deno-roman-numerals
deno module roman-numerals
Last synced: about 23 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsejcksn/deno-roman-numerals
- Owner: jsejcksn
- License: mit
- Created: 2021-04-08T05:04:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T04:00:59.000Z (over 3 years ago)
- Last Synced: 2024-11-02T11:12:37.337Z (14 days ago)
- Topics: deno, module, roman-numerals
- Language: TypeScript
- Homepage: https://deno.land/x/roman_numerals
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# roman-numerals
## Use
```ts
import { toArabic, toRoman } from "https://deno.land/x/roman_numerals/mod.ts";console.log(toArabic("XLII")); // 42
console.log(toArabic("xlii")); // 42
console.log(toRoman(42)); // "XLII"
console.log(toRoman("42")); // "XLII"
```## Notes
> This module started as a port of the npm package [roman-numerals](https://github.com/joshleaves/roman-numerals) (see [ACKNOWLEDGEMENTS.md](./ACKNOWLEDGEMENTS.md)). The API is the same (with the notable exception that non-primitives are not accepted as arguments).
The provided functions convert between [roman numerals](https://en.wikipedia.org/wiki/Roman_numerals) and [arabic integers](https://en.wikipedia.org/wiki/Arabic_numerals). The conversions utilize the "standard form" of roman numerals, so only values from `0` to `3999` (inclusive) are valid. Any values outside this range will throw an error.
## Exports
### `toArabic`
```ts
function toArabic(roman: string): number
```Converts a valid roman number to its arabic equivalent.
In addition to roman numerals in range, acceptable strings are also `"nulla"` and `""` (an empty string) which will both return 0.
### `toRoman`
```ts
function toRoman(arabic: number | string): string
```Converts an arabic number (0 to 3999 inclusive) to its roman equivalent.
The function will attempt to parse string integers. It will throw a TypeError on non-number inputs or `NaN`.
## Tests
```
deno test
```