Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-roman-numbers-converter

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-roman-numbers-converter - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/app.d.ts

4

lib/index.d.ts

@@ -1,3 +0,5 @@

import { RomanNumber } from "./RomanNumber";
import { RomanNumber } from './RomanNumber';
export declare const BaseNumbers: RomanNumber[];
export declare function toRoman(x: number): string;
export declare function toArabic(x: string): number | null;
export declare function isRoman(x: string): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toRoman = exports.BaseNumbers = void 0;
exports.isRoman = exports.toArabic = exports.toRoman = exports.BaseNumbers = void 0;
var RomanNumber_1 = require("./RomanNumber");
exports.BaseNumbers = [
new RomanNumber_1.RomanNumber(1000, "M"),
new RomanNumber_1.RomanNumber(900, "CM"),
new RomanNumber_1.RomanNumber(500, "D"),
new RomanNumber_1.RomanNumber(400, "CD"),
new RomanNumber_1.RomanNumber(100, "C"),
new RomanNumber_1.RomanNumber(90, "XC"),
new RomanNumber_1.RomanNumber(50, "L"),
new RomanNumber_1.RomanNumber(40, "XL"),
new RomanNumber_1.RomanNumber(10, "X"),
new RomanNumber_1.RomanNumber(9, "IX"),
new RomanNumber_1.RomanNumber(5, "V"),
new RomanNumber_1.RomanNumber(4, "IV"),
new RomanNumber_1.RomanNumber(1, "I")
new RomanNumber_1.RomanNumber(1000, 'M'),
new RomanNumber_1.RomanNumber(900, 'CM'),
new RomanNumber_1.RomanNumber(500, 'D'),
new RomanNumber_1.RomanNumber(400, 'CD'),
new RomanNumber_1.RomanNumber(100, 'C'),
new RomanNumber_1.RomanNumber(90, 'XC'),
new RomanNumber_1.RomanNumber(50, 'L'),
new RomanNumber_1.RomanNumber(40, 'XL'),
new RomanNumber_1.RomanNumber(10, 'X'),
new RomanNumber_1.RomanNumber(9, 'IX'),
new RomanNumber_1.RomanNumber(5, 'V'),
new RomanNumber_1.RomanNumber(4, 'IV'),
new RomanNumber_1.RomanNumber(1, 'I'),
];

@@ -23,5 +23,9 @@ function toRoman(x) {

var romanNumber;
if (x != 0) {
if (x <= 0 || x > 3999) {
return '';
}
else {
i = 0;
var toReturn = "";
var toReturn = '';
x = Math.floor(x);
while (x > 0) {

@@ -37,9 +41,34 @@ romanNumber = exports.BaseNumbers[i];

}
return toReturn;
}
else {
return "0";
}
exports.toRoman = toRoman;
function toArabic(x) {
var romanNumeral = x.toUpperCase();
if (!isRoman(romanNumeral)) {
return null;
}
return toReturn;
var result = 0;
var i = 0;
while (romanNumeral.length > 0 && i < exports.BaseNumbers.length) {
var romanNumber = exports.BaseNumbers[i];
if (romanNumeral.startsWith(romanNumber.str)) {
result += romanNumber.num;
romanNumeral = romanNumeral.substring(romanNumber.str.length);
}
else {
i++;
}
}
if (romanNumeral.length > 0) {
return null;
}
return result;
}
exports.toRoman = toRoman;
exports.toArabic = toArabic;
function isRoman(x) {
var regex = new RegExp('^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$');
return regex.test(x);
}
exports.isRoman = isRoman;
//# sourceMappingURL=index.js.map
{
"name": "typescript-roman-numbers-converter",
"version": "1.0.0",
"version": "1.1.0",
"description": "TypeScript package that converts arabic number to roman notation",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -34,2 +34,27 @@ [![NPM](https://nodei.co/npm/typescript-roman-numbers-converter.png?compact=true)](https://nodei.co/npm/typescript-roman-numbers-converter/)

</code>
</pre>
### toArabic
Converts the given **string** into a **number** that represents the same value in arabic notation.
<pre>
<code>
let a: number;
let r: string;
r = "XXXII"
a = toArabic(a); //a is now equal to 32
</code>
</pre>
### isRoman
Returns true if the given **string** is a valid written roman number
<pre>
<code>
let b = isRoman("MCM"); //b is true
let b_2 = isRoman("ABC"); //b_2 is false
</code>
</pre>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc