Socket
Socket
Sign inDemoInstall

strnum

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

2

package.json
{
"name": "strnum",
"version": "1.0.3",
"version": "1.0.4",
"description": "Parse String to Number based on configuration",

@@ -5,0 +5,0 @@ "main": "strnum.js",

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

const hexRegex = /0x[a-zA-Z0-9]+/;
const numRegex = /^([\-\+])?(0*)(\.[0-9]+(e\-?[0-9]+)?|[0-9]+(\.[0-9]+(e\-?[0-9]+)?)?)$/;
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
// const octRegex = /0x[a-z0-9]+/;

@@ -50,2 +50,2 @@ // const binRegex = /0x[a-z0-9]+/;

module.exports = toNumber
module.exports = toNumber

@@ -21,3 +21,3 @@ const toNumber = require("./strnum");

})
it("should parse hexaDecimal values", () => {
it("should parse hexadecimal values", () => {
expect(toNumber("0x2f")).toEqual(47);

@@ -30,2 +30,8 @@ expect(toNumber("-0x2f")).toEqual(-47);

})
it("should not parse strings with 0x embedded", () => {
expect(toNumber("0xzz")).toEqual("0xzz");
expect(toNumber("iweraf0x123qwerqwer")).toEqual("iweraf0x123qwerqwer");
expect(toNumber("1230x55")).toEqual("1230x55");
expect(toNumber("JVBERi0xLjMNCiXi48")).toEqual("JVBERi0xLjMNCiXi48");
})
it("leading zeros", () => {

@@ -94,2 +100,13 @@ expect(toNumber("06")).toEqual(6);

it("scientific notation with upper E", () => {
expect(toNumber("01.0E2" , { leadingZeros : false})).toEqual("01.0E2");
expect(toNumber("-01.0E2" , { leadingZeros : false})).toEqual("-01.0E2");
expect(toNumber("01.0E2") ).toEqual(100);
expect(toNumber("-01.0E2") ).toEqual(-100);
expect(toNumber("1.0E2") ).toEqual(100);
expect(toNumber("-1.0E2") ).toEqual(-100);
expect(toNumber("1.0E-2")).toEqual(0.01);
});
it("should skip matching pattern", () => {

@@ -109,3 +126,2 @@ expect(toNumber("+12", { skipLike: /\+[0-9]{10}/} )).toEqual(12);

})
});
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc