nhb-toolbox 4.28.4 → 4.28.7
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 +10 -1
- package/dist/cjs/hash/core.js +3 -0
- package/dist/dts/hash/core.d.ts +2 -2
- package/dist/dts/string/types.d.ts +20 -2
- package/dist/dts/utils/index.d.ts +2 -3
- package/dist/esm/hash/core.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ All notable changes to the package will be documented here.
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [4.28.7] - 2025-12-02
|
|
10
|
+
|
|
11
|
+
- **Updated** *invalid links* in *tsdoc* of the *hash utilities*.
|
|
12
|
+
- **Implemented** input type *validation* for `sha256` utility.
|
|
13
|
+
|
|
14
|
+
## [4.28.6] - 2025-12-02
|
|
15
|
+
|
|
16
|
+
- **Updated** *tsdoc* for `stableStringify` + *type augmentation* for `String` methods: `toLowerCase` and `toUpperCase`.
|
|
17
|
+
|
|
9
18
|
## [4.28.4] - 2025-12-02
|
|
10
19
|
|
|
11
20
|
- **Updated** *implementation* and *tsdoc* for:
|
|
@@ -32,7 +41,7 @@ All notable changes to the package will be documented here.
|
|
|
32
41
|
|
|
33
42
|
## [4.27.10] - 2025-11-28
|
|
34
43
|
|
|
35
|
-
- **Updated** type augmentation for `String` methods: `toLowerCase` and `toUpperCase` (type level only, implementation remains intact).
|
|
44
|
+
- **Updated** *type augmentation* for `String` methods: `toLowerCase` and `toUpperCase` (type level only, implementation remains intact).
|
|
36
45
|
|
|
37
46
|
## [4.27.1] - 2025-11-28
|
|
38
47
|
|
package/dist/cjs/hash/core.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.md5 = md5;
|
|
4
4
|
exports.sha1 = sha1;
|
|
5
5
|
exports.sha256 = sha256;
|
|
6
|
+
const primitives_1 = require("../guards/primitives");
|
|
6
7
|
const helpers_1 = require("./helpers");
|
|
7
8
|
const utils_1 = require("./utils");
|
|
8
9
|
function md5(str) {
|
|
@@ -85,5 +86,7 @@ function sha1(msg) {
|
|
|
85
86
|
return h.map(toHex).join('');
|
|
86
87
|
}
|
|
87
88
|
function sha256(msg) {
|
|
89
|
+
if (!(0, primitives_1.isString)(msg))
|
|
90
|
+
throw new TypeError('Input must be of type string!');
|
|
88
91
|
return (0, utils_1.bytesToHex)((0, utils_1.sha256Bytes)((0, utils_1.utf8ToBytes)(msg)));
|
|
89
92
|
}
|
package/dist/dts/hash/core.d.ts
CHANGED
|
@@ -59,8 +59,8 @@ export declare function sha1(msg: string): string;
|
|
|
59
59
|
* // Returns: '7037e204b825b83553ba336a6ec35b796d505599286ae864729ed6cb33ae9fe1'
|
|
60
60
|
* ```
|
|
61
61
|
*
|
|
62
|
-
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/
|
|
62
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#sha256bytes sha256Bytes} for hashing raw bytes
|
|
63
63
|
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#utf8tobytes utf8ToBytes} for converting string to bytes
|
|
64
|
-
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#
|
|
64
|
+
* @see {@link https://toolbox.nazmul-nhb.dev/docs/utilities/hash/encoding#bytestohex bytesToHex} for converting bytes to a hexadecimal string
|
|
65
65
|
*/
|
|
66
66
|
export declare function sha256(msg: string): string;
|
|
@@ -4,9 +4,27 @@ import type { LOWERCASE } from './constants';
|
|
|
4
4
|
declare global {
|
|
5
5
|
interface String {
|
|
6
6
|
toLowerCase(): string;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* * Converts all the alphabetic characters in a string to lowercase.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam `Lower` - A type-level flag. If `'T'`, returns the lowercase string type (`Lowercase<string>`). Otherwise, returns literal `Lower` (must be Lowercase type).
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* - This augmentation only affects TypeScript type inference.
|
|
14
|
+
* - Runtime behavior remains identical to the standard `toLowerCase()` method.
|
|
15
|
+
*/
|
|
16
|
+
toLowerCase<Lower extends 'T' | Lowercase<string>>(): Lower extends 'T' ? Lowercase<string> : Lower;
|
|
8
17
|
toUpperCase(): string;
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* * Converts all the alphabetic characters in a string to uppercase.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam `Upper` - A type-level flag. If `'T'`, returns the uppercase string type (`Uppercase<string>`). Otherwise, returns literal `Upper` (must be Uppercase type).
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* - This augmentation only affects TypeScript type inference.
|
|
25
|
+
* - Runtime behavior remains identical to the standard `toUpperCase()` method.
|
|
26
|
+
*/
|
|
27
|
+
toUpperCase<Upper extends 'T' | Uppercase<string>>(): Upper extends 'T' ? Uppercase<string> : Upper;
|
|
10
28
|
}
|
|
11
29
|
}
|
|
12
30
|
/** - Options for generating anagrams. */
|
|
@@ -122,8 +122,7 @@ export declare function getStaticGetterNames(cls: Constructor): string[];
|
|
|
122
122
|
export declare function getClassDetails(cls: Constructor): ClassDetails;
|
|
123
123
|
/**
|
|
124
124
|
* * Create a deterministic JSON string representation of any value.
|
|
125
|
-
*
|
|
126
|
-
*
|
|
125
|
+
* - The output format matches standard JSON but with guaranteed sorted keys.
|
|
127
126
|
*
|
|
128
127
|
* @remarks
|
|
129
128
|
* - This function guarantees **stable, repeatable output** by:
|
|
@@ -131,7 +130,7 @@ export declare function getClassDetails(cls: Constructor): ClassDetails;
|
|
|
131
130
|
* - Recursively stabilizing nested objects and arrays.
|
|
132
131
|
* - Converting all `undefined` values into `null` so the output remains valid JSON.
|
|
133
132
|
* - Converting date-like objects (`Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, `Temporal`) **in the same way that {@link JSON.stringify} would serialize them**, ensuring predictable and JSON-compliant output.
|
|
134
|
-
*
|
|
133
|
+
* - Falling back to native JSON serialization for primitives.
|
|
135
134
|
*
|
|
136
135
|
* - **Useful for:**
|
|
137
136
|
* - Hash generation (e.g., signatures, cache keys)
|
package/dist/esm/hash/core.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isString } from '../guards/primitives.js';
|
|
1
2
|
import { _md5cycle, _numToHex, _stringToNumbers } from './helpers.js';
|
|
2
3
|
import { bytesToHex, sha256Bytes, utf8ToBytes } from './utils.js';
|
|
3
4
|
export function md5(str) {
|
|
@@ -80,5 +81,7 @@ export function sha1(msg) {
|
|
|
80
81
|
return h.map(toHex).join('');
|
|
81
82
|
}
|
|
82
83
|
export function sha256(msg) {
|
|
84
|
+
if (!isString(msg))
|
|
85
|
+
throw new TypeError('Input must be of type string!');
|
|
83
86
|
return bytesToHex(sha256Bytes(utf8ToBytes(msg)));
|
|
84
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.28.
|
|
3
|
+
"version": "4.28.7",
|
|
4
4
|
"description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|