npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

toroman

v2.0.1

Published

Convert any number less than 4000 to roman numerals and back to integer

Downloads

12

Readme

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 ➖
  • 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

It can be installed with npm.

npm i toroman

📥 Usage

const roman = require("toRoman");

🔩 Methods

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

🔵 Example

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

// Returns DCCLXV

🔁 Convert Roman numeral to integer: fromRoman

/**
 * 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
 */
function fromRoman(value: string): number {}

🔵 Example

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

// Returns 765

🔍 Confirm if string is valid Roman numeral: isRoman

/**
 * 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
 */
function isRoman(value: string): true {}

🔵 Example

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

// Returns true

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

/**
 * 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
 */
function sum(expected: "number" | "roman", ...args: string[]): general {}

🔵 Example

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

// Returns 1100

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

/**
 * 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
 */
function diff(
  expected: "number" | "roman",
  numerals: [string, string]
): general {}

🔵 Example

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

// Returns 1080

✖️ Multiply Roman numerals and get output as a Roman numeral or numbers: multiply

/**
 * 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 {}

🔵 Example

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

// Returns L

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

/**
 * 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
 */
function divide(
  expected: "number" | "roman",
  numerals: [string, string]
): general {}

🔵 Example

console.log(roman.divide("number", ["L", "X"]));

// Returns 5

⬆️ Get maximum Roman numeral from a list: max

/**
 * 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 {}

🔵 Example

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

// Returns X

⬇️ Get minimum Roman numeral from a list: min

/**
 * 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 {}

🔵 Example

console.log(roman.min("X", "V", "III", "VIII"));

// Returns III

🤹 Get a random Roman numeral: random

/**
 * 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 {}

🔵 Example

console.log(roman.random(10));

// Returns a random Roman numeral between I and X

📋 Generate a table of Roman numerals: table

/**
 * 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 }[] {}

🔵 Example

console.log(roman.table("I", "V"));

/**
 * 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

/**
 * 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[] {}

🔵 Examples

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

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

⏭️ Get the next Roman numeral: nextRoman

/**
 * Get the next Roman numeral
 * @param value Current Roman numeral
 * @returns { string } Next Roman numeral
 * @throws { Error } When the input is invalid or out of range
 */
export function nextRoman(value: string): string {}

🔵 Example

console.log(roman.nextRoman("XIV"));

// Returns XV

⏮️ Get the previous Roman numeral: prevRoman

/**
 * Get the previous Roman numeral
 * @param value Current Roman numeral
 * @returns { string } Previous Roman numeral
 * @throws { Error } When the input is invalid or out of range
 */
export function previousRoman(value: string): string {}

🔵 Example

console.log(roman.previousRoman("XIV"));

// Returns XIII

🔀 Map an array of general inputs to either numbers or Roman numerals: map

/**
 * Map an array of general inputs to either numbers or Roman numerals
 * @param expected { string } Expected response type
 * @param args { general[] } Array of general inputs
 * @returns { general[] } Mapped array of numbers or Roman numerals
 * @throws { Error } When any of the inputs are invalid or out of range
 */
export function map(expected: "number" | "roman", args: general[]): general[] {}

🔵 Example

console.log(roman.map("roman", [1, 2, 3, 4, 5]));

// Returns [ 'I', 'II', 'III', 'IV', 'V' ]

✨ Found this project useful?

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