nhb-toolbox 4.12.69 → 4.12.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/guards/primitives.js +4 -4
- package/dist/cjs/guards/specials.js +11 -5
- package/dist/dts/guards/primitives.d.ts +3 -3
- package/dist/dts/guards/specials.d.ts +8 -4
- package/dist/dts/guards/specials.d.ts.map +1 -1
- package/dist/esm/guards/primitives.js +4 -4
- package/dist/esm/guards/specials.js +11 -5
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.12.70] - 2025-07-08
|
|
10
|
+
|
|
11
|
+
- **Updated** numeric string related issues, specifically in `isNumber` & `isNumericString` and other helper functions.
|
|
12
|
+
|
|
13
|
+
## [4.12.68-69] - 2025-07-05
|
|
14
|
+
|
|
15
|
+
- **Updated Docs:** Added links to other npm packages.
|
|
16
|
+
|
|
9
17
|
## [4.12.67] - 2025-07-03
|
|
10
18
|
|
|
11
19
|
- **Fixed** some import alias typo.
|
|
@@ -15,12 +15,12 @@ exports.isNonEmptyString = isNonEmptyString;
|
|
|
15
15
|
exports.isFalsy = isFalsy;
|
|
16
16
|
exports.isTruthy = isTruthy;
|
|
17
17
|
/**
|
|
18
|
-
* * Type guard to check
|
|
19
|
-
* @param value - The value to
|
|
20
|
-
* @returns `true` if the value is a number
|
|
18
|
+
* * Type guard to check whether a value is a finite number (excluding `NaN` and `Infinity`).
|
|
19
|
+
* @param value - The value to test.
|
|
20
|
+
* @returns `true` if the value is a finite number; otherwise `false`.
|
|
21
21
|
*/
|
|
22
22
|
function isNumber(value) {
|
|
23
|
-
return typeof value === 'number' &&
|
|
23
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* * Type guard to check if a value is a string.
|
|
@@ -107,16 +107,22 @@ function isIPAddress(value) {
|
|
|
107
107
|
/**
|
|
108
108
|
* * Type guard to check if the current environment matches a given string.
|
|
109
109
|
* @param env - The expected environment (e.g., "production", "development").
|
|
110
|
-
* @returns `true` if the
|
|
110
|
+
* @returns `true` if the value is a numeric string parsable by `Number()`, otherwise `false`.
|
|
111
111
|
*/
|
|
112
112
|
function isEnvironment(env) {
|
|
113
113
|
return process.env.NODE_ENV === env;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* * Type guard to check if a value is a
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* * Type guard to check if a value is a string representing a finite number.
|
|
117
|
+
*
|
|
118
|
+
* Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`.
|
|
119
|
+
* Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`.
|
|
120
|
+
*
|
|
121
|
+
* @param value - The value to test.
|
|
122
|
+
* @returns `true` if the value is a string that fully represents a finite number.
|
|
119
123
|
*/
|
|
120
124
|
function isNumericString(value) {
|
|
121
|
-
return (0, primitives_1.isString)(value) &&
|
|
125
|
+
return ((0, primitives_1.isString)(value) &&
|
|
126
|
+
value?.trim() !== '' &&
|
|
127
|
+
Number.isFinite(Number(value)));
|
|
122
128
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { FalsyPrimitive, NormalPrimitive, Primitive } from '../types/index';
|
|
2
2
|
/**
|
|
3
|
-
* * Type guard to check
|
|
4
|
-
* @param value - The value to
|
|
5
|
-
* @returns `true` if the value is a number
|
|
3
|
+
* * Type guard to check whether a value is a finite number (excluding `NaN` and `Infinity`).
|
|
4
|
+
* @param value - The value to test.
|
|
5
|
+
* @returns `true` if the value is a finite number; otherwise `false`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isNumber(value: unknown): value is number;
|
|
8
8
|
/**
|
|
@@ -59,13 +59,17 @@ export declare function isIPAddress(value: unknown): value is string;
|
|
|
59
59
|
/**
|
|
60
60
|
* * Type guard to check if the current environment matches a given string.
|
|
61
61
|
* @param env - The expected environment (e.g., "production", "development").
|
|
62
|
-
* @returns `true` if the
|
|
62
|
+
* @returns `true` if the value is a numeric string parsable by `Number()`, otherwise `false`.
|
|
63
63
|
*/
|
|
64
64
|
export declare function isEnvironment(env: string): boolean;
|
|
65
65
|
/**
|
|
66
|
-
* * Type guard to check if a value is a
|
|
67
|
-
*
|
|
68
|
-
*
|
|
66
|
+
* * Type guard to check if a value is a string representing a finite number.
|
|
67
|
+
*
|
|
68
|
+
* Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`.
|
|
69
|
+
* Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`.
|
|
70
|
+
*
|
|
71
|
+
* @param value - The value to test.
|
|
72
|
+
* @returns `true` if the value is a string that fully represents a finite number.
|
|
69
73
|
*/
|
|
70
74
|
export declare function isNumericString(value: unknown): value is `${number}`;
|
|
71
75
|
//# sourceMappingURL=specials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specials.d.ts","sourceRoot":"","sources":["../../../src/guards/specials.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAKvD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAOtD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;;GAGG;AACH,w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AAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAK3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,MAAM,EAAE,CAMpE"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* * Type guard to check
|
|
3
|
-
* @param value - The value to
|
|
4
|
-
* @returns `true` if the value is a number
|
|
2
|
+
* * Type guard to check whether a value is a finite number (excluding `NaN` and `Infinity`).
|
|
3
|
+
* @param value - The value to test.
|
|
4
|
+
* @returns `true` if the value is a finite number; otherwise `false`.
|
|
5
5
|
*/
|
|
6
6
|
export function isNumber(value) {
|
|
7
|
-
return typeof value === 'number' &&
|
|
7
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* * Type guard to check if a value is a string.
|
|
@@ -93,16 +93,22 @@ export function isIPAddress(value) {
|
|
|
93
93
|
/**
|
|
94
94
|
* * Type guard to check if the current environment matches a given string.
|
|
95
95
|
* @param env - The expected environment (e.g., "production", "development").
|
|
96
|
-
* @returns `true` if the
|
|
96
|
+
* @returns `true` if the value is a numeric string parsable by `Number()`, otherwise `false`.
|
|
97
97
|
*/
|
|
98
98
|
export function isEnvironment(env) {
|
|
99
99
|
return process.env.NODE_ENV === env;
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* * Type guard to check if a value is a
|
|
103
|
-
*
|
|
104
|
-
*
|
|
102
|
+
* * Type guard to check if a value is a string representing a finite number.
|
|
103
|
+
*
|
|
104
|
+
* Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`.
|
|
105
|
+
* Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`.
|
|
106
|
+
*
|
|
107
|
+
* @param value - The value to test.
|
|
108
|
+
* @returns `true` if the value is a string that fully represents a finite number.
|
|
105
109
|
*/
|
|
106
110
|
export function isNumericString(value) {
|
|
107
|
-
return isString(value) &&
|
|
111
|
+
return (isString(value) &&
|
|
112
|
+
value?.trim() !== '' &&
|
|
113
|
+
Number.isFinite(Number(value)));
|
|
108
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.70",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions and classes for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"globals": "^16.2.0",
|
|
53
53
|
"globby": "^14.1.0",
|
|
54
54
|
"jest": "^29.7.0",
|
|
55
|
-
"nhb-scripts": "^1.
|
|
55
|
+
"nhb-scripts": "^1.3.4",
|
|
56
56
|
"prettier": "^3.5.3",
|
|
57
57
|
"progress-estimator": "^0.3.1",
|
|
58
58
|
"rimraf": "^6.0.1",
|
|
@@ -247,6 +247,7 @@
|
|
|
247
247
|
"lint": "node scripts/lint.mjs",
|
|
248
248
|
"fix": "node scripts/fix.mjs",
|
|
249
249
|
"commit": "nhb-commit",
|
|
250
|
+
"module": "nhb-module",
|
|
250
251
|
"count": "nhb-count",
|
|
251
252
|
"types": "node scripts/types.mjs"
|
|
252
253
|
}
|