New:Socket for Asana Is Now Available.Learn more
Get Started

strnum

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strnum - npm Package Compare versions

Comparing version
2.3.0
to
2.4.0
+8
-0
CHANGELOG.md
**2.4.0 / 2026-06-09**
- support unicode numerals using 'anynum'
**2.3.0 / 2026-05-07**
- support octal and binary, test with @byspec/numbers
- test with @byspec/numbers
**2.2.3 / 2026-04-07**

@@ -3,0 +11,0 @@ - remove unnecessary files from npm package

+4
-1
{
"name": "strnum",
"version": "2.3.0",
"version": "2.4.0",
"description": "Parse String to Number based on configuration",

@@ -31,3 +31,6 @@ "type": "module",

"jasmine": "^5.6.0"
},
"dependencies": {
"anynum": "^1.0.0"
}
}
# strnum
Parse string into Number based on configuration
[![strnum downloads](https://img.shields.io/npm/dw/strnum.svg)](https://npm-compare.com/strnum)
[![strnum version](https://img.shields.io/npm/v/strnum.svg)](https://www.npmjs.com/package/strnum)
[![strnum license](https://img.shields.io/npm/l/strnum.svg)](https://github.com/NaturalIntelligence/strnum)
## Users

@@ -89,2 +93,6 @@

toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212"
toNumber("1e1000", { unicode: true, infinity: "original" }); //"1e1000"
toNumber("1000", { unicode: true }); //1000
toNumber("1000", { unicode: false }); //"1000"
```

@@ -99,2 +107,3 @@

infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal))
unicode: false, //when number with unicode numerals should be parsed
```

@@ -101,0 +110,0 @@

+9
-1

@@ -6,2 +6,4 @@ const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;

import anynum from "anynum";
const consider = {

@@ -16,2 +18,3 @@ hex: true,

infinity: "original", // "null", "infinity" (Infinity type), "string" ("Infinity" (the string literal))
unicode: false,
};

@@ -28,3 +31,8 @@

else if (trimmedStr === "0") return 0;
else if (options.hex && hexRegex.test(trimmedStr)) {
if (options.unicode) {
trimmedStr = anynum(trimmedStr);
if (trimmedStr === "0") return 0; // re-check after normalization
}
if (options.hex && hexRegex.test(trimmedStr)) {
return parse_int(trimmedStr, 16);

@@ -31,0 +39,0 @@ } else if (options.binary && binRegex.test(trimmedStr)) {