nhb-toolbox 4.28.30 → 4.28.44
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 +9 -0
- package/dist/cjs/date/Chronos.js +1 -1
- package/dist/cjs/date/chronos-fn.js +11 -13
- package/dist/cjs/date/constants.js +100 -1
- package/dist/cjs/guards/specials.js +10 -0
- package/dist/cjs/hash/TextCodec.js +75 -0
- package/dist/cjs/hash/helpers.js +15 -0
- package/dist/cjs/hash/index.js +4 -1
- package/dist/cjs/hash/utils.js +9 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/number/constants.js +0 -8
- package/dist/dts/date/Chronos.d.ts +2 -2
- package/dist/dts/date/constants.d.ts +6 -2
- package/dist/dts/date/types.d.ts +16 -6
- package/dist/dts/guards/specials.d.ts +15 -2
- package/dist/dts/hash/TextCodec.d.ts +166 -0
- package/dist/dts/hash/helpers.d.ts +4 -0
- package/dist/dts/hash/index.d.ts +2 -1
- package/dist/dts/hash/utils.d.ts +40 -1
- package/dist/dts/index.d.ts +1 -1
- package/dist/dts/number/constants.d.ts +2 -6
- package/dist/esm/date/Chronos.js +1 -1
- package/dist/esm/date/chronos-fn.js +11 -13
- package/dist/esm/date/constants.js +99 -0
- package/dist/esm/guards/specials.js +8 -0
- package/dist/esm/hash/TextCodec.js +71 -0
- package/dist/esm/hash/helpers.js +13 -0
- package/dist/esm/hash/index.js +2 -1
- package/dist/esm/hash/utils.js +8 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/number/constants.js +0 -8
- package/package.json +12 -7
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.44] - 2025-12-19
|
|
10
|
+
|
|
11
|
+
- **Updated** `DateTimeFormatOptions` with *improved type system* and **removed** *unsupported* **locales/currencies** from *constants* and *types*.
|
|
12
|
+
|
|
13
|
+
## [4.28.40] - 2025-12-15
|
|
14
|
+
|
|
15
|
+
- **Added** *new class* `TextCodec` with only *static methods* to convert between `text`, `hex`, `binary`, and `Base64` representations using *byte-level transformations*.
|
|
16
|
+
- **Added** *new utility* `hexToBytes` with 2 new special *type guards:* `isHexString` and `isBinaryString`.
|
|
17
|
+
|
|
9
18
|
## [4.28.30] - 2025-12-13
|
|
10
19
|
|
|
11
20
|
- **Updated** *tsdoc* for `Chronos` and *signature* of `Currency` class with generic `CurrencyCode`.
|
package/dist/cjs/date/Chronos.js
CHANGED
|
@@ -216,7 +216,7 @@ class Chronos {
|
|
|
216
216
|
return this.toDate().toISOString();
|
|
217
217
|
}
|
|
218
218
|
toLocaleString(locales, options) {
|
|
219
|
-
return this.
|
|
219
|
+
return this.#date.toLocaleString(locales, options);
|
|
220
220
|
}
|
|
221
221
|
getTimeStamp() {
|
|
222
222
|
return this.toDate().getTime();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chronos = void 0;
|
|
4
4
|
const Chronos_1 = require("./Chronos");
|
|
5
|
-
const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
5
|
+
const $chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
6
6
|
if (typeof valueOrYear === 'number' && typeof month === 'number') {
|
|
7
7
|
return new Chronos_1.Chronos(valueOrYear, month, date ?? 1, hours ?? 0, minutes ?? 0, seconds ?? 0, ms ?? 0);
|
|
8
8
|
}
|
|
@@ -10,27 +10,25 @@ const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
|
10
10
|
return new Chronos_1.Chronos(valueOrYear);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
function _isChronosStaticKey(prop) {
|
|
14
|
+
return (prop in Chronos_1.Chronos &&
|
|
15
|
+
prop !== 'prototype' &&
|
|
16
|
+
prop !== 'name' &&
|
|
17
|
+
prop !== 'length' &&
|
|
18
|
+
typeof Chronos_1.Chronos[prop] === 'function');
|
|
19
|
+
}
|
|
20
|
+
const chronosStatics = new Proxy($chronos, {
|
|
14
21
|
get(target, prop, receiver) {
|
|
15
22
|
if (prop in target) {
|
|
16
23
|
return Reflect.get(target, prop, receiver);
|
|
17
24
|
}
|
|
18
|
-
if (prop
|
|
19
|
-
prop !== 'prototype' &&
|
|
20
|
-
prop !== 'name' &&
|
|
21
|
-
prop !== 'length' &&
|
|
22
|
-
typeof Chronos_1.Chronos[prop] === 'function') {
|
|
25
|
+
if (_isChronosStaticKey(prop)) {
|
|
23
26
|
return Chronos_1.Chronos[prop];
|
|
24
27
|
}
|
|
25
28
|
return Reflect.get(target, prop, receiver);
|
|
26
29
|
},
|
|
27
30
|
has(target, prop) {
|
|
28
|
-
return
|
|
29
|
-
(prop in Chronos_1.Chronos &&
|
|
30
|
-
prop !== 'prototype' &&
|
|
31
|
-
prop !== 'name' &&
|
|
32
|
-
prop !== 'length' &&
|
|
33
|
-
typeof Chronos_1.Chronos[prop] === 'function'));
|
|
31
|
+
return prop in target || _isChronosStaticKey(prop);
|
|
34
32
|
},
|
|
35
33
|
});
|
|
36
34
|
exports.chronos = chronosStatics;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MS_MAP = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.TIME_FORMATS = exports.MILLISECOND_FORMATS = exports.ZONE_FORMATS = exports.SECOND_FORMATS = exports.MINUTE_FORMATS = exports.HOUR_FORMATS = exports.DAY_FORMATS = exports.DATE_FORMATS = exports.MONTH_FORMATS = exports.YEAR_FORMATS = exports.MONTHS = exports.DAYS = exports.INTERNALS = void 0;
|
|
3
|
+
exports.LOCALE_NUMBERING_SYSTEMS = exports.LOCALE_CALENDARS = exports.MS_MAP = exports.TIME_UNIT_VARIANTS = exports.ZODIAC_PRESETS = exports.VEDIC_ZODIAC_SIGNS = exports.WESTERN_ZODIAC_SIGNS = exports.DATE_PART_RANGES = exports.SORTED_TIME_FORMATS = exports.TIME_FORMATS = exports.MILLISECOND_FORMATS = exports.ZONE_FORMATS = exports.SECOND_FORMATS = exports.MINUTE_FORMATS = exports.HOUR_FORMATS = exports.DAY_FORMATS = exports.DATE_FORMATS = exports.MONTH_FORMATS = exports.YEAR_FORMATS = exports.MONTHS = exports.DAYS = exports.INTERNALS = void 0;
|
|
4
4
|
exports.INTERNALS = Symbol('Internals');
|
|
5
5
|
exports.DAYS = /* @__PURE__ */ Object.freeze([
|
|
6
6
|
'Sunday',
|
|
@@ -151,3 +151,102 @@ exports.MS_MAP = /* @__PURE__ */ Object.freeze((() => {
|
|
|
151
151
|
milliseconds: 1,
|
|
152
152
|
};
|
|
153
153
|
})());
|
|
154
|
+
exports.LOCALE_CALENDARS = /* @__PURE__ */ Object.freeze([
|
|
155
|
+
'buddhist',
|
|
156
|
+
'chinese',
|
|
157
|
+
'coptic',
|
|
158
|
+
'dangi',
|
|
159
|
+
'ethioaa',
|
|
160
|
+
'ethiopic',
|
|
161
|
+
'gregory',
|
|
162
|
+
'hebrew',
|
|
163
|
+
'indian',
|
|
164
|
+
'islamic',
|
|
165
|
+
'islamic-civil',
|
|
166
|
+
'islamic-rgsa',
|
|
167
|
+
'islamic-tbla',
|
|
168
|
+
'islamic-umalqura',
|
|
169
|
+
'iso8601',
|
|
170
|
+
'japanese',
|
|
171
|
+
'persian',
|
|
172
|
+
'roc',
|
|
173
|
+
]);
|
|
174
|
+
exports.LOCALE_NUMBERING_SYSTEMS = /* @__PURE__ */ Object.freeze([
|
|
175
|
+
'adlm',
|
|
176
|
+
'ahom',
|
|
177
|
+
'arab',
|
|
178
|
+
'arabext',
|
|
179
|
+
'bali',
|
|
180
|
+
'beng',
|
|
181
|
+
'bhks',
|
|
182
|
+
'brah',
|
|
183
|
+
'cakm',
|
|
184
|
+
'cham',
|
|
185
|
+
'deva',
|
|
186
|
+
'diak',
|
|
187
|
+
'fullwide',
|
|
188
|
+
'gara',
|
|
189
|
+
'gong',
|
|
190
|
+
'gonm',
|
|
191
|
+
'gujr',
|
|
192
|
+
'gukh',
|
|
193
|
+
'guru',
|
|
194
|
+
'hanidec',
|
|
195
|
+
'hmng',
|
|
196
|
+
'hmnp',
|
|
197
|
+
'java',
|
|
198
|
+
'kali',
|
|
199
|
+
'kawi',
|
|
200
|
+
'khmr',
|
|
201
|
+
'knda',
|
|
202
|
+
'krai',
|
|
203
|
+
'lana',
|
|
204
|
+
'lanatham',
|
|
205
|
+
'laoo',
|
|
206
|
+
'latn',
|
|
207
|
+
'lepc',
|
|
208
|
+
'limb',
|
|
209
|
+
'mathbold',
|
|
210
|
+
'mathdbl',
|
|
211
|
+
'mathmono',
|
|
212
|
+
'mathsanb',
|
|
213
|
+
'mathsans',
|
|
214
|
+
'mlym',
|
|
215
|
+
'modi',
|
|
216
|
+
'mong',
|
|
217
|
+
'mroo',
|
|
218
|
+
'mtei',
|
|
219
|
+
'mymr',
|
|
220
|
+
'mymrepka',
|
|
221
|
+
'mymrpao',
|
|
222
|
+
'mymrshan',
|
|
223
|
+
'mymrtlng',
|
|
224
|
+
'nagm',
|
|
225
|
+
'newa',
|
|
226
|
+
'nkoo',
|
|
227
|
+
'olck',
|
|
228
|
+
'onao',
|
|
229
|
+
'orya',
|
|
230
|
+
'osma',
|
|
231
|
+
'outlined',
|
|
232
|
+
'rohg',
|
|
233
|
+
'saur',
|
|
234
|
+
'segment',
|
|
235
|
+
'shrd',
|
|
236
|
+
'sind',
|
|
237
|
+
'sinh',
|
|
238
|
+
'sora',
|
|
239
|
+
'sund',
|
|
240
|
+
'sunu',
|
|
241
|
+
'takr',
|
|
242
|
+
'talu',
|
|
243
|
+
'tamldec',
|
|
244
|
+
'telu',
|
|
245
|
+
'thai',
|
|
246
|
+
'tibt',
|
|
247
|
+
'tirh',
|
|
248
|
+
'tnsa',
|
|
249
|
+
'vaii',
|
|
250
|
+
'wara',
|
|
251
|
+
'wcho',
|
|
252
|
+
]);
|
|
@@ -8,6 +8,8 @@ exports.isBrowser = isBrowser;
|
|
|
8
8
|
exports.isNode = isNode;
|
|
9
9
|
exports.isURL = isURL;
|
|
10
10
|
exports.isBase64 = isBase64;
|
|
11
|
+
exports.isHexString = isHexString;
|
|
12
|
+
exports.isBinaryString = isBinaryString;
|
|
11
13
|
exports.isPhoneNumber = isPhoneNumber;
|
|
12
14
|
exports.isIPAddress = isIPAddress;
|
|
13
15
|
exports.isEnvironment = isEnvironment;
|
|
@@ -49,6 +51,14 @@ function isBase64(value) {
|
|
|
49
51
|
return ((0, primitives_1.isString)(value) &&
|
|
50
52
|
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value));
|
|
51
53
|
}
|
|
54
|
+
function isHexString(value) {
|
|
55
|
+
return ((0, primitives_1.isString)(value) &&
|
|
56
|
+
/^[\da-fA-F\s]+$/.test(value) &&
|
|
57
|
+
value.replace(/\s+/g, '').length % 2 === 0);
|
|
58
|
+
}
|
|
59
|
+
function isBinaryString(value) {
|
|
60
|
+
return ((0, primitives_1.isString)(value) && /^[01\s]+$/.test(value) && value.replace(/\s+/g, '').length % 8 === 0);
|
|
61
|
+
}
|
|
52
62
|
function isPhoneNumber(value) {
|
|
53
63
|
return (0, primitives_1.isString)(value) && /^\+?[1-9]\d{1,14}$/.test(value);
|
|
54
64
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextCodec = void 0;
|
|
4
|
+
const primitives_1 = require("../guards/primitives");
|
|
5
|
+
const specials_1 = require("../guards/specials");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
class TextCodec {
|
|
9
|
+
constructor() { }
|
|
10
|
+
static isValidHex(hex) {
|
|
11
|
+
return (0, specials_1.isHexString)(hex);
|
|
12
|
+
}
|
|
13
|
+
static isValidBinary(binary) {
|
|
14
|
+
return (0, specials_1.isBinaryString)(binary);
|
|
15
|
+
}
|
|
16
|
+
static isValidBase64(b64) {
|
|
17
|
+
return (0, specials_1.isBase64)(b64);
|
|
18
|
+
}
|
|
19
|
+
static utf8ToHex(text, spaced = true) {
|
|
20
|
+
return [...(0, utils_1.utf8ToBytes)(text)]
|
|
21
|
+
.map((b) => (0, helpers_1._padStartWith0)(b, 'hex'))
|
|
22
|
+
.join(spaced ? ' ' : '');
|
|
23
|
+
}
|
|
24
|
+
static utf8ToBinary(text, spaced = true) {
|
|
25
|
+
return [...(0, utils_1.utf8ToBytes)(text)]
|
|
26
|
+
.map((b) => (0, helpers_1._padStartWith0)(b, 'binary'))
|
|
27
|
+
.join(spaced ? ' ' : '');
|
|
28
|
+
}
|
|
29
|
+
static hexToUtf8(hex) {
|
|
30
|
+
return (0, utils_1.bytesToUtf8)((0, utils_1.hexToBytes)(hex));
|
|
31
|
+
}
|
|
32
|
+
static binaryToUtf8(binary) {
|
|
33
|
+
if (!(0, specials_1.isBinaryString)(binary))
|
|
34
|
+
return '';
|
|
35
|
+
const bytes = (0, helpers_1._splitByCharLength)(binary, 8).map((b) => parseInt(b, 2));
|
|
36
|
+
return (0, utils_1.bytesToUtf8)(new Uint8Array(bytes));
|
|
37
|
+
}
|
|
38
|
+
static hexToBinary(hex, spaced = true) {
|
|
39
|
+
if (!(0, specials_1.isHexString)(hex))
|
|
40
|
+
return '';
|
|
41
|
+
return (0, helpers_1._splitByCharLength)(hex, 2)
|
|
42
|
+
.map((h) => (0, helpers_1._padStartWith0)(parseInt(h, 16), 'binary'))
|
|
43
|
+
.join(spaced ? ' ' : '');
|
|
44
|
+
}
|
|
45
|
+
static binaryToHex(binary, spaced = true) {
|
|
46
|
+
if (!(0, specials_1.isBinaryString)(binary))
|
|
47
|
+
return '';
|
|
48
|
+
return (0, helpers_1._splitByCharLength)(binary, 8)
|
|
49
|
+
.map((b) => (0, helpers_1._padStartWith0)(parseInt(b, 2), 'hex'))
|
|
50
|
+
.join(spaced ? ' ' : '');
|
|
51
|
+
}
|
|
52
|
+
static base64ToUtf8(b64) {
|
|
53
|
+
if (!(0, specials_1.isBase64)(b64))
|
|
54
|
+
return '';
|
|
55
|
+
return (0, utils_1.bytesToUtf8)((0, utils_1.base64ToBytes)(b64));
|
|
56
|
+
}
|
|
57
|
+
static utf8ToBase64(text) {
|
|
58
|
+
if (!(0, primitives_1.isNonEmptyString)(text))
|
|
59
|
+
return '';
|
|
60
|
+
return (0, utils_1.bytesToBase64)((0, utils_1.utf8ToBytes)(text));
|
|
61
|
+
}
|
|
62
|
+
static base64ToHex(b64, spaced = true) {
|
|
63
|
+
return this.utf8ToHex(this.base64ToUtf8(b64), spaced);
|
|
64
|
+
}
|
|
65
|
+
static base64ToBinary(b64, spaced = true) {
|
|
66
|
+
return this.utf8ToBinary(this.base64ToUtf8(b64), spaced);
|
|
67
|
+
}
|
|
68
|
+
static hexToBase64(hex) {
|
|
69
|
+
return this.utf8ToBase64(this.hexToUtf8(hex));
|
|
70
|
+
}
|
|
71
|
+
static binaryToBase64(binary) {
|
|
72
|
+
return this.utf8ToBase64(this.binaryToUtf8(binary));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.TextCodec = TextCodec;
|
package/dist/cjs/hash/helpers.js
CHANGED
|
@@ -10,6 +10,8 @@ exports._formatUUID = _formatUUID;
|
|
|
10
10
|
exports._isOptionV3V5 = _isOptionV3V5;
|
|
11
11
|
exports._checkUUIDVersion = _checkUUIDVersion;
|
|
12
12
|
exports._constantTimeEquals = _constantTimeEquals;
|
|
13
|
+
exports._splitByCharLength = _splitByCharLength;
|
|
14
|
+
exports._padStartWith0 = _padStartWith0;
|
|
13
15
|
const non_primitives_1 = require("../guards/non-primitives");
|
|
14
16
|
const primitives_1 = require("../guards/primitives");
|
|
15
17
|
const specials_1 = require("../guards/specials");
|
|
@@ -168,3 +170,16 @@ function _constantTimeEquals(a, b) {
|
|
|
168
170
|
}
|
|
169
171
|
return res === 0;
|
|
170
172
|
}
|
|
173
|
+
function _splitByCharLength(str, splitByChars = 2) {
|
|
174
|
+
if (!(0, primitives_1.isNonEmptyString)(str))
|
|
175
|
+
return [];
|
|
176
|
+
const sanitized = str.replace(/\s+/g, '');
|
|
177
|
+
const result = [];
|
|
178
|
+
for (let i = 0; i < sanitized.length; i += splitByChars) {
|
|
179
|
+
result.push(sanitized.slice(i, i + splitByChars));
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
function _padStartWith0(byte, type) {
|
|
184
|
+
return byte.toString(type === 'hex' ? 16 : 2).padStart(type === 'hex' ? 2 : 8, '0');
|
|
185
|
+
}
|
package/dist/cjs/hash/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuid = exports.isUUIDv8 = exports.isUUIDv7 = exports.isUUIDv6 = exports.isUUIDv5 = exports.isUUIDv4 = exports.isUUIDv3 = exports.isUUIDv2 = exports.isUUIDv1 = exports.decodeUUID = exports.utf8ToBytes = exports.uint8To32ArrayBE = exports.sha256Bytes = exports.randomHex = exports.intTo4BytesBE = exports.hmacSha256 = exports.concatBytes = exports.bytesToUtf8 = exports.bytesToHex = exports.bytesToBase64 = exports.base64ToBytes = exports.Signet = exports.sha256 = exports.sha1 = exports.md5 = exports.Cipher = exports.randomID = exports.generateRandomID = exports.isUUID = void 0;
|
|
3
|
+
exports.uuid = exports.isUUIDv8 = exports.isUUIDv7 = exports.isUUIDv6 = exports.isUUIDv5 = exports.isUUIDv4 = exports.isUUIDv3 = exports.isUUIDv2 = exports.isUUIDv1 = exports.decodeUUID = exports.utf8ToBytes = exports.uint8To32ArrayBE = exports.sha256Bytes = exports.randomHex = exports.intTo4BytesBE = exports.hmacSha256 = exports.hexToBytes = exports.concatBytes = exports.bytesToUtf8 = exports.bytesToHex = exports.bytesToBase64 = exports.base64ToBytes = exports.TextCodec = exports.Signet = exports.sha256 = exports.sha1 = exports.md5 = exports.Cipher = exports.randomID = exports.generateRandomID = exports.isUUID = void 0;
|
|
4
4
|
var specials_1 = require("../guards/specials");
|
|
5
5
|
Object.defineProperty(exports, "isUUID", { enumerable: true, get: function () { return specials_1.isUUID; } });
|
|
6
6
|
var basics_1 = require("../string/basics");
|
|
@@ -14,12 +14,15 @@ Object.defineProperty(exports, "sha1", { enumerable: true, get: function () { re
|
|
|
14
14
|
Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return core_1.sha256; } });
|
|
15
15
|
var Signet_1 = require("./Signet");
|
|
16
16
|
Object.defineProperty(exports, "Signet", { enumerable: true, get: function () { return Signet_1.Signet; } });
|
|
17
|
+
var TextCodec_1 = require("./TextCodec");
|
|
18
|
+
Object.defineProperty(exports, "TextCodec", { enumerable: true, get: function () { return TextCodec_1.TextCodec; } });
|
|
17
19
|
var utils_1 = require("./utils");
|
|
18
20
|
Object.defineProperty(exports, "base64ToBytes", { enumerable: true, get: function () { return utils_1.base64ToBytes; } });
|
|
19
21
|
Object.defineProperty(exports, "bytesToBase64", { enumerable: true, get: function () { return utils_1.bytesToBase64; } });
|
|
20
22
|
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return utils_1.bytesToHex; } });
|
|
21
23
|
Object.defineProperty(exports, "bytesToUtf8", { enumerable: true, get: function () { return utils_1.bytesToUtf8; } });
|
|
22
24
|
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_1.concatBytes; } });
|
|
25
|
+
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return utils_1.hexToBytes; } });
|
|
23
26
|
Object.defineProperty(exports, "hmacSha256", { enumerable: true, get: function () { return utils_1.hmacSha256; } });
|
|
24
27
|
Object.defineProperty(exports, "intTo4BytesBE", { enumerable: true, get: function () { return utils_1.intTo4BytesBE; } });
|
|
25
28
|
Object.defineProperty(exports, "randomHex", { enumerable: true, get: function () { return utils_1.randomHex; } });
|
package/dist/cjs/hash/utils.js
CHANGED
|
@@ -11,6 +11,9 @@ exports.hmacSha256 = hmacSha256;
|
|
|
11
11
|
exports.uint8To32ArrayBE = uint8To32ArrayBE;
|
|
12
12
|
exports.intTo4BytesBE = intTo4BytesBE;
|
|
13
13
|
exports.bytesToHex = bytesToHex;
|
|
14
|
+
exports.hexToBytes = hexToBytes;
|
|
15
|
+
const specials_1 = require("../guards/specials");
|
|
16
|
+
const helpers_1 = require("./helpers");
|
|
14
17
|
function randomHex(length, uppercase = false) {
|
|
15
18
|
const genHex = () => Math.floor(Math.random() * 16).toString(16);
|
|
16
19
|
const hex = Array.from({ length }, genHex).join('');
|
|
@@ -250,3 +253,9 @@ function bytesToHex(bytes) {
|
|
|
250
253
|
}
|
|
251
254
|
return hex;
|
|
252
255
|
}
|
|
256
|
+
function hexToBytes(hex) {
|
|
257
|
+
if (!(0, specials_1.isHexString)(hex))
|
|
258
|
+
return new Uint8Array();
|
|
259
|
+
const bytes = (0, helpers_1._splitByCharLength)(hex, 2).map((h) => parseInt(h, 16));
|
|
260
|
+
return new Uint8Array(bytes);
|
|
261
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.formatDateTime = exports.formatDate = exports.extractTotalMinutesFromTim
|
|
|
7
7
|
exports.convertIntoFormData = exports.splitArrayByProperty = exports.splitArray = exports.rotateArray = exports.removeDuplicatesFromArray = exports.removeDuplicates = exports.moveArrayElement = exports.groupArrayByProperty = exports.getMissingElements = exports.getDuplicatesFromArray = exports.getDuplicates = exports.findMissingElements = exports.extractMissingElements = exports.extractDuplicatesFromArray = exports.extractDuplicates = exports.createOptionsArray = exports.sortAnArray = exports.naturalSortForString = exports.naturalSort = exports.compareSorter = exports.compareNaturally = exports.Finder = exports.totalDeltaByField = exports.sumFieldDifference = exports.sumByField = exports.groupAndSumByField = exports.groupAndAvgByField = exports.groupAndAverageByField = exports.avgByField = exports.averageByField = exports.shuffleArray = exports.isValidEmptyArray = exports.isInvalidOrEmptyArray = exports.getLastArrayElement = exports.flattenArray = exports.filterArrayOfObjects = exports.minutesToUTCOffset = exports.getTotalMinutesFromUTC = exports.getTotalMinutesFromTime = exports.getTotalMinutes = exports.getTimeZoneIds = exports.getTimeZoneDetails = exports.getTimeStringFromUTC = exports.getTimeFromMinutes = exports.getNativeTimeZoneId = exports.getMinutesFromUTC = exports.getHourMinutesFromMinutes = exports.getCurrentTime = exports.getCurrentDateTime = exports.formatUTCOffset = void 0;
|
|
8
8
|
exports.parseQueryStringLiteral = exports.parseQueryString = exports.literalQueryStringToObject = exports.getQueryStringAsObject = exports.getQueryParams = exports.generateQueryParams = exports.formatQueryParams = exports.createQueryParams = exports.removeObjectFields = exports.removeFields = exports.remapObjectFields = exports.remapFields = exports.pickObjectFieldsByCondition = exports.pickObjectFields = exports.pickFieldsByCondition = exports.pickFields = exports.omitObjectFields = exports.omitFields = exports.deleteObjectFields = exports.deleteFields = exports.convertObjectValues = exports.sanitizeData = exports.parseStringifiedObjectValues = exports.parseObjectValues = exports.parseJsonToObject = exports.mergeObjects = exports.mergeAndFlattenObjects = exports.flattenObjectKeyValue = exports.flattenObjectDotNotation = exports.extractUpdatedFields = exports.extractUpdatedAndNewFields = exports.extractNewFields = exports.extractObjectKeysDeep = exports.extractObjectKeys = exports.extractKeysDeep = exports.extractKeys = exports.countObjectFields = exports.cloneObject = exports.isValidFormData = exports.isOriginFileObj = exports.isFileUpload = exports.isFileOrBlob = exports.isFileList = exports.isFileArray = exports.isCustomFileArray = exports.isCustomFile = exports.serializeForm = exports.parseFormData = exports.createFormData = exports.createControlledFormData = void 0;
|
|
9
9
|
exports.isArrayOfType = exports.isArray = exports.doesReturnPromise = exports.isUndefined = exports.isTruthy = exports.isSymbol = exports.isString = exports.isPrimitive = exports.isPositiveInteger = exports.isNumber = exports.isNull = exports.isNormalPrimitive = exports.isNonEmptyString = exports.isInteger = exports.isFalsy = exports.isBoolean = exports.isBigInt = exports.Paginator = exports.throttleAction = exports.stripJsonEdgeGarbage = exports.stableStringify = exports.parsePrimitivesDeep = exports.parseJsonDeep = exports.parseJSON = exports.joinArrayElements = exports.isDeepEqual = exports.getStaticMethodsCount = exports.getStaticMethodNames = exports.getStaticGetterNames = exports.getInstanceMethodsCount = exports.getInstanceMethodNames = exports.getInstanceGetterNames = exports.getClassDetails = exports.definePrototypeMethod = exports.deepParsePrimitives = exports.debounceAction = exports.countStaticMethods = exports.countInstanceMethods = exports.convertArrayToString = exports.saveToSessionStorage = exports.saveToLocalStorage = exports.removeFromSessionStorage = exports.removeFromLocalStorage = exports.getFromSessionStorage = exports.getFromLocalStorage = exports.toggleFullScreen = exports.smoothScrollTo = exports.copyToClipboard = exports.updateQueryParam = exports.queryStringToObject = void 0;
|
|
10
|
-
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBase64 = exports.httpStatus = exports.HttpStatus = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isValidArray = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = exports.isObjectWithKeys = exports.isObjectEmpty = exports.isObject = exports.isNotEmptyObject = exports.isMethodDescriptor = exports.isMethod = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isEmptyObject = exports.isDate = exports.isArrayWithLength = void 0;
|
|
10
|
+
exports.isValidURL = exports.isValidEmail = exports.isUUID = exports.isURL = exports.isPhoneNumber = exports.isNumericString = exports.isNodeEnvironment = exports.isNodeENV = exports.isNode = exports.isIPAddress = exports.isHexString = exports.isExpectedNodeENV = exports.isEnvironment = exports.isEmailArray = exports.isEmail = exports.isDateString = exports.isBrowser = exports.isBinaryString = exports.isBase64 = exports.httpStatus = exports.HttpStatus = exports.isValidSet = exports.isValidObject = exports.isValidMap = exports.isValidJSON = exports.isValidArray = exports.isSet = exports.isReturningPromise = exports.isRegularExpression = exports.isRegExp = exports.isPromise = exports.isObjectWithKeys = exports.isObjectEmpty = exports.isObject = exports.isNotEmptyObject = exports.isMethodDescriptor = exports.isMethod = exports.isMap = exports.isJSONObject = exports.isJSON = exports.isFunction = exports.isError = exports.isEmptyObjectGuard = exports.isEmptyObject = exports.isDate = exports.isArrayWithLength = void 0;
|
|
11
11
|
var basics_1 = require("./string/basics");
|
|
12
12
|
Object.defineProperty(exports, "generateRandomID", { enumerable: true, get: function () { return basics_1.generateRandomID; } });
|
|
13
13
|
Object.defineProperty(exports, "trimString", { enumerable: true, get: function () { return basics_1.trimString; } });
|
|
@@ -439,12 +439,14 @@ Object.defineProperty(exports, "HttpStatus", { enumerable: true, get: function (
|
|
|
439
439
|
Object.defineProperty(exports, "httpStatus", { enumerable: true, get: function () { return HttpStatus_1.httpStatus; } });
|
|
440
440
|
var specials_1 = require("./guards/specials");
|
|
441
441
|
Object.defineProperty(exports, "isBase64", { enumerable: true, get: function () { return specials_1.isBase64; } });
|
|
442
|
+
Object.defineProperty(exports, "isBinaryString", { enumerable: true, get: function () { return specials_1.isBinaryString; } });
|
|
442
443
|
Object.defineProperty(exports, "isBrowser", { enumerable: true, get: function () { return specials_1.isBrowser; } });
|
|
443
444
|
Object.defineProperty(exports, "isDateString", { enumerable: true, get: function () { return specials_1.isDateString; } });
|
|
444
445
|
Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return specials_1.isEmail; } });
|
|
445
446
|
Object.defineProperty(exports, "isEmailArray", { enumerable: true, get: function () { return specials_1.isEmailArray; } });
|
|
446
447
|
Object.defineProperty(exports, "isEnvironment", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
447
448
|
Object.defineProperty(exports, "isExpectedNodeENV", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
449
|
+
Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return specials_1.isHexString; } });
|
|
448
450
|
Object.defineProperty(exports, "isIPAddress", { enumerable: true, get: function () { return specials_1.isIPAddress; } });
|
|
449
451
|
Object.defineProperty(exports, "isNode", { enumerable: true, get: function () { return specials_1.isNode; } });
|
|
450
452
|
Object.defineProperty(exports, "isNodeENV", { enumerable: true, get: function () { return specials_1.isEnvironment; } });
|
|
@@ -243,10 +243,6 @@ exports.CURRENCY_CODES = /* @__PURE__ */ Object.freeze([
|
|
|
243
243
|
'VND',
|
|
244
244
|
'VUV',
|
|
245
245
|
'WST',
|
|
246
|
-
'XAF',
|
|
247
|
-
'XCD',
|
|
248
|
-
'XOF',
|
|
249
|
-
'XPF',
|
|
250
246
|
'YER',
|
|
251
247
|
'ZAR',
|
|
252
248
|
'ZMW',
|
|
@@ -532,10 +528,6 @@ exports.CURRENCY_LOCALES = /* @__PURE__ */ Object.freeze({
|
|
|
532
528
|
VND: 'vi-VN',
|
|
533
529
|
VUV: 'en-VU',
|
|
534
530
|
WST: 'en-WS',
|
|
535
|
-
XAF: 'fr-XAF',
|
|
536
|
-
XCD: 'en-XCD',
|
|
537
|
-
XOF: 'fr-XOF',
|
|
538
|
-
XPF: 'fr-XPF',
|
|
539
531
|
YER: 'ar-YE',
|
|
540
532
|
ZAR: 'en-ZA',
|
|
541
533
|
ZMW: 'en-ZM',
|
|
@@ -215,10 +215,10 @@ export declare class Chronos {
|
|
|
215
215
|
/** @instance Returns a date as a string value in ISO format (UTC). */
|
|
216
216
|
toISOString(): string;
|
|
217
217
|
/**
|
|
218
|
-
* @instance Wrapper over native
|
|
218
|
+
* @instance Wrapper over native {@link Date.toLocaleString} with improved type system.
|
|
219
219
|
* @description Converts a date and time to a string by using the current or specified locale.
|
|
220
220
|
*
|
|
221
|
-
* @param locales A locale string, array of locale strings,
|
|
221
|
+
* @param locales A locale string, array of locale strings, {@link Intl.Locale} object, or array of {@link Intl.Locale} objects that contain one or more language or locale tags (see: {@link LocalesArguments}). If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
|
|
222
222
|
* @param options An object that contains one or more properties that specify comparison options (see: {@link DateTimeFormatOptions}).
|
|
223
223
|
*/
|
|
224
224
|
toLocaleString(locales?: LocalesArguments, options?: DateTimeFormatOptions): string;
|
|
@@ -15,7 +15,7 @@ export declare const SECOND_FORMATS: readonly ["ss", "s"];
|
|
|
15
15
|
export declare const ZONE_FORMATS: readonly ["ZZ"];
|
|
16
16
|
export declare const MILLISECOND_FORMATS: readonly ["ms", "mss"];
|
|
17
17
|
export declare const TIME_FORMATS: readonly ["a", "A"];
|
|
18
|
-
export declare const SORTED_TIME_FORMATS: readonly ("MM" | "DD" | "D" | "Do" | "M" | "mmm" | "mmmm" | "d" | "dd" | "ddd" | "YYYY" | "YY" | "yyyy" | "yy" | "H" | "HH" | "hh" | "h" | "mm" | "m" | "a" | "A" | "ss" | "s" | "
|
|
18
|
+
export declare const SORTED_TIME_FORMATS: readonly ("MM" | "ms" | "DD" | "D" | "Do" | "M" | "mmm" | "mmmm" | "d" | "dd" | "ddd" | "YYYY" | "YY" | "yyyy" | "yy" | "H" | "HH" | "hh" | "h" | "mm" | "m" | "a" | "A" | "ss" | "s" | "mss" | "ZZ")[];
|
|
19
19
|
/** Ranges for day parts. */
|
|
20
20
|
export declare const DATE_PART_RANGES: Readonly<Record<DayPart, [ClockHour, ClockHour]>>;
|
|
21
21
|
/** Western Zodiac Signs */
|
|
@@ -41,4 +41,8 @@ export declare const TIME_UNIT_VARIANTS: Readonly<{
|
|
|
41
41
|
readonly millisecond: readonly ["ms", "msec", "msecs", "millisecond", "milliseconds"];
|
|
42
42
|
}>;
|
|
43
43
|
/** Map to different time units to milliseconds */
|
|
44
|
-
export declare const MS_MAP: Readonly<Record<"year" | "month" | "hour" | "minute" | "second" | "millisecond" | "day" | "
|
|
44
|
+
export declare const MS_MAP: Readonly<Record<"year" | "month" | "hour" | "minute" | "second" | "millisecond" | "day" | "ms" | "hr" | "d" | "h" | "m" | "s" | "week" | "min" | "y" | "yr" | "yrs" | "years" | "mo" | "months" | "w" | "weeks" | "days" | "hrs" | "hours" | "mins" | "minutes" | "sec" | "secs" | "seconds" | "msec" | "msecs" | "milliseconds", number>>;
|
|
45
|
+
/** List of locale calendars supported by {@link Intl} API */
|
|
46
|
+
export declare const LOCALE_CALENDARS: readonly ["buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-civil", "islamic-rgsa", "islamic-tbla", "islamic-umalqura", "iso8601", "japanese", "persian", "roc"];
|
|
47
|
+
/** List of locale numbering systems supported by {@link Intl} API */
|
|
48
|
+
export declare const LOCALE_NUMBERING_SYSTEMS: readonly ["adlm", "ahom", "arab", "arabext", "bali", "beng", "bhks", "brah", "cakm", "cham", "deva", "diak", "fullwide", "gara", "gong", "gonm", "gujr", "gukh", "guru", "hanidec", "hmng", "hmnp", "java", "kali", "kawi", "khmr", "knda", "krai", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrepka", "mymrpao", "mymrshan", "mymrtlng", "nagm", "newa", "nkoo", "olck", "onao", "orya", "osma", "outlined", "rohg", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "sunu", "takr", "talu", "tamldec", "telu", "thai", "tibt", "tirh", "tnsa", "vaii", "wara", "wcho"];
|
package/dist/dts/date/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Enumerate, LocaleCode, NumberRange } from '../number/types';
|
|
2
2
|
import type { Maybe } from '../types/index';
|
|
3
|
-
import type { LooseLiteral, RangeTuple } from '../utils/types';
|
|
3
|
+
import type { LooseLiteral, RangeTuple, Split } from '../utils/types';
|
|
4
4
|
import type { Chronos } from './Chronos';
|
|
5
5
|
import type { ChronosStatics } from './chronos-statics';
|
|
6
|
-
import type { DATE_FORMATS, DAY_FORMATS, DAYS, HOUR_FORMATS, MILLISECOND_FORMATS, MINUTE_FORMATS, MONTH_FORMATS, MONTHS, SECOND_FORMATS, TIME_FORMATS, TIME_UNIT_VARIANTS, WESTERN_ZODIAC_SIGNS, YEAR_FORMATS, ZODIAC_PRESETS } from './constants';
|
|
6
|
+
import type { DATE_FORMATS, DAY_FORMATS, DAYS, HOUR_FORMATS, LOCALE_NUMBERING_SYSTEMS, MILLISECOND_FORMATS, MINUTE_FORMATS, MONTH_FORMATS, MONTHS, SECOND_FORMATS, LOCALE_CALENDARS, TIME_FORMATS, TIME_UNIT_VARIANTS, WESTERN_ZODIAC_SIGNS, YEAR_FORMATS, ZODIAC_PRESETS } from './constants';
|
|
7
7
|
import type { SEASON_PRESETS } from './seasons';
|
|
8
8
|
import type { TIME_ZONE_IDS, TIME_ZONE_LABELS, TIME_ZONES, TIME_ZONES_NATIVE } from './timezone';
|
|
9
9
|
export type { ChronosStatics, UTCOffset as UTCOffSet };
|
|
@@ -101,12 +101,22 @@ type DateTimeISO = 'YYYY-MM-DDTHH:mm:ss.mssZZ';
|
|
|
101
101
|
type DateTimeConnector = ' ' | ', ' | '; ' | ' - ';
|
|
102
102
|
/** Pre-defined literal types for formatting date and time. Optionally can pass any string. */
|
|
103
103
|
export type StrictFormat = LooseLiteral<DateTimeISO | DateParts | TimeParts | `${DateParts}${DateTimeConnector}${TimeParts}`>;
|
|
104
|
-
/**
|
|
105
|
-
export type
|
|
106
|
-
/**
|
|
104
|
+
/** `BCP47` locale string or {@link Intl.Locale} object that contain one or more language or locale tags */
|
|
105
|
+
export type $LocalArguments = LooseLiteral<LocaleCode | Split<LocaleCode, '-'>[0]> | Intl.Locale;
|
|
106
|
+
/** `BCP47` locale string, array of locale strings, {@link Intl.Locale} object, or array of {@link Intl.Locale} objects that contain one or more language or locale tags. */
|
|
107
|
+
export type LocalesArguments = $LocalArguments | $LocalArguments[];
|
|
108
|
+
/** Locale calendars supported by {@link Intl} API */
|
|
109
|
+
export type LocaleCalendar = (typeof LOCALE_CALENDARS)[number];
|
|
110
|
+
/** Locale numbering systems supported by {@link Intl} API */
|
|
111
|
+
export type NumberingSystem = (typeof LOCALE_NUMBERING_SYSTEMS)[number];
|
|
112
|
+
/** Extends {@link Intl.DateTimeFormatOptions} with improved type system. */
|
|
107
113
|
export interface DateTimeFormatOptions extends Intl.DateTimeFormatOptions {
|
|
108
|
-
/** {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Time zone identifier} excluding `'Factory'
|
|
114
|
+
/** {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones Time zone identifier} to use (excluding `'Factory'`). */
|
|
109
115
|
timeZone?: $TimeZoneIdentifier;
|
|
116
|
+
/** Locale calendar system to use. */
|
|
117
|
+
calendar?: LocaleCalendar;
|
|
118
|
+
/** Locale numbering system to use. */
|
|
119
|
+
numberingSystem?: NumberingSystem;
|
|
110
120
|
}
|
|
111
121
|
/** Iterable `Chronos` object properties */
|
|
112
122
|
export interface ChronosObject {
|
|
@@ -45,6 +45,18 @@ export declare function isURL(value: unknown): value is string;
|
|
|
45
45
|
* @returns `true` if the value is a valid Base64 string, otherwise `false`.
|
|
46
46
|
*/
|
|
47
47
|
export declare function isBase64(value: unknown): value is string;
|
|
48
|
+
/**
|
|
49
|
+
* * Type guard to check if a value is a valid hexadecimal byte sequence.
|
|
50
|
+
* @param value - The value to check, spaced between bytes or un-spaced.
|
|
51
|
+
* @returns `true` if the value is a valid hexadecimal byte sequence, otherwise `false`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isHexString(value: unknown): value is string;
|
|
54
|
+
/**
|
|
55
|
+
* * Type guard to check if a value is a valid binary byte sequence.
|
|
56
|
+
* @param value - The value to check, spaced between bytes or un-spaced.
|
|
57
|
+
* @returns `true` if the value is a valid binary byte sequence, otherwise `false`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isBinaryString(value: unknown): value is string;
|
|
48
60
|
/**
|
|
49
61
|
* * Type guard to check if a value is a valid phone number.
|
|
50
62
|
* @param value - The value to check.
|
|
@@ -66,8 +78,9 @@ export declare function isEnvironment(env: string): boolean;
|
|
|
66
78
|
/**
|
|
67
79
|
* * Type guard to check if a value is a string representing a finite number.
|
|
68
80
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* - Accepts strings like: `"42"`, `" -5.5 "`, `"0.123"`, `"-0"`, `"1e5"`.
|
|
83
|
+
* - Rejects strings like: `"NaN"`, `"Infinity"`, `"-Infinity"`, `"abc"`, `""`, `"42abc"`.
|
|
71
84
|
*
|
|
72
85
|
* @param value - The value to test.
|
|
73
86
|
* @returns `true` if the value is a string that fully represents a finite number.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class `TextCodec` provides **UTF-8–safe** conversions between `text`, `hex`, `binary`, and `Base64` representations using byte-level transformations.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* TextCodec.utf8ToHex('ভাষা'); // 'e0 a6 ad e0 a6 be e0 a6 b7 e0 a6 be'
|
|
6
|
+
* TextCodec.hexToUtf8('e0 a6 ad e0 a6 be'); // 'ভা'
|
|
7
|
+
*/
|
|
8
|
+
export declare class TextCodec {
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* @static Validates whether a string represents a valid hexadecimal byte sequence.
|
|
12
|
+
*
|
|
13
|
+
* @param hex - Hex string, spaced or un-spaced (e.g. "ff 0a" or "ff0a")
|
|
14
|
+
* @returns `true` if the input is valid hex byte string
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* TextCodec.isValidHex('ff 0a');
|
|
18
|
+
*/
|
|
19
|
+
static isValidHex(hex: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @static Validates whether a string represents a valid binary byte sequence.
|
|
22
|
+
*
|
|
23
|
+
* @param binary - Binary string, spaced or un-spaced
|
|
24
|
+
* @returns `true` if the input is valid binary byte string
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* TextCodec.isValidBinary('01000001');
|
|
28
|
+
*/
|
|
29
|
+
static isValidBinary(binary: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @static Validates whether a string represents a valid Base64-encoded string.
|
|
32
|
+
*
|
|
33
|
+
* @param b64 - Base64 string to check
|
|
34
|
+
* @returns `true` if the input is valid Base64-encoded string
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* TextCodec.isValidBase64('SGVsbG8=');
|
|
38
|
+
*/
|
|
39
|
+
static isValidBase64(b64: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @static Converts UTF-8 text into hexadecimal byte representation.
|
|
42
|
+
*
|
|
43
|
+
* @param text - UTF-8 text to convert
|
|
44
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
45
|
+
* @returns Hexadecimal byte string
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* TextCodec.utf8ToHex('Hi');
|
|
49
|
+
*/
|
|
50
|
+
static utf8ToHex(text: string, spaced?: boolean): string;
|
|
51
|
+
/**
|
|
52
|
+
* @static Converts UTF-8 text into binary byte representation.
|
|
53
|
+
*
|
|
54
|
+
* @param text - UTF-8 text to convert
|
|
55
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
56
|
+
* @returns Binary byte string
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* TextCodec.utf8ToBinary('A');
|
|
60
|
+
*/
|
|
61
|
+
static utf8ToBinary(text: string, spaced?: boolean): string;
|
|
62
|
+
/**
|
|
63
|
+
* @static Converts hexadecimal byte string into UTF-8 text.
|
|
64
|
+
*
|
|
65
|
+
* @param hex - Hexadecimal byte string
|
|
66
|
+
* @returns Decoded UTF-8 text
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* TextCodec.hexToUtf8('48 69');
|
|
70
|
+
*/
|
|
71
|
+
static hexToUtf8(hex: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* @static Converts binary byte string into UTF-8 text.
|
|
74
|
+
*
|
|
75
|
+
* @param binary - Binary byte string
|
|
76
|
+
* @returns Decoded UTF-8 text
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* TextCodec.binaryToUtf8('01001000 01101001');
|
|
80
|
+
*/
|
|
81
|
+
static binaryToUtf8(binary: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* @static Converts hexadecimal byte string into binary byte string.
|
|
84
|
+
*
|
|
85
|
+
* @param hex - Hexadecimal byte string
|
|
86
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
87
|
+
* @returns Binary byte string
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* TextCodec.hexToBinary('ff');
|
|
91
|
+
*/
|
|
92
|
+
static hexToBinary(hex: string, spaced?: boolean): string;
|
|
93
|
+
/**
|
|
94
|
+
* @static Converts binary byte string into hexadecimal byte string.
|
|
95
|
+
*
|
|
96
|
+
* @param binary - Binary byte string
|
|
97
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
98
|
+
* @returns Hexadecimal byte string
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* TextCodec.binaryToHex('00000001');
|
|
102
|
+
*/
|
|
103
|
+
static binaryToHex(binary: string, spaced?: boolean): string;
|
|
104
|
+
/**
|
|
105
|
+
* @static Converts a Base64-encoded string into UTF-8 text.
|
|
106
|
+
*
|
|
107
|
+
* @param b64 - Base64 encoded string
|
|
108
|
+
* @returns Decoded UTF-8 text
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* TextCodec.base64ToUtf8('SGVsbG8=');
|
|
112
|
+
*/
|
|
113
|
+
static base64ToUtf8(b64: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* @static Converts UTF-8 text into a Base64-encoded string.
|
|
116
|
+
*
|
|
117
|
+
* @param text - UTF-8 text to encode
|
|
118
|
+
* @returns Base64 encoded string
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* TextCodec.utf8ToBase64('Hello');
|
|
122
|
+
*/
|
|
123
|
+
static utf8ToBase64(text: string): string;
|
|
124
|
+
/**
|
|
125
|
+
* @static Converts Base64 directly into hexadecimal byte string.
|
|
126
|
+
*
|
|
127
|
+
* @param b64 - Base64 encoded string
|
|
128
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
129
|
+
* @returns Hexadecimal byte string
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* TextCodec.base64ToHex('SGVsbG8=');
|
|
133
|
+
*/
|
|
134
|
+
static base64ToHex(b64: string, spaced?: boolean): string;
|
|
135
|
+
/**
|
|
136
|
+
* @static Converts Base64 directly into binary byte string.
|
|
137
|
+
*
|
|
138
|
+
* @param b64 - Base64 encoded string
|
|
139
|
+
* @param spaced - Whether to separate bytes with spaces, defaults to `true`
|
|
140
|
+
* @returns Binary byte string
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* TextCodec.base64ToBinary('SGVsbG8=');
|
|
144
|
+
*/
|
|
145
|
+
static base64ToBinary(b64: string, spaced?: boolean): string;
|
|
146
|
+
/**
|
|
147
|
+
* @static Converts hexadecimal byte string into a Base64 string.
|
|
148
|
+
*
|
|
149
|
+
* @param hex - Hexadecimal byte string
|
|
150
|
+
* @returns Base64 encoded string
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* TextCodec.hexToBase64('48 69');
|
|
154
|
+
*/
|
|
155
|
+
static hexToBase64(hex: string): string;
|
|
156
|
+
/**
|
|
157
|
+
* @static Converts binary byte string into a Base64 string.
|
|
158
|
+
*
|
|
159
|
+
* @param binary - Binary byte string
|
|
160
|
+
* @returns Base64 encoded string
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* TextCodec.binaryToBase64('01001000 01101001');
|
|
164
|
+
*/
|
|
165
|
+
static binaryToBase64(binary: string): string;
|
|
166
|
+
}
|
|
@@ -28,3 +28,7 @@ export declare function _checkUUIDVersion(value: unknown, v: `${$UUIDVersion}`):
|
|
|
28
28
|
* Prevents timing attacks by ensuring equal-time checks regardless of data differences.
|
|
29
29
|
*/
|
|
30
30
|
export declare function _constantTimeEquals(a: string | Uint8Array, b: string | Uint8Array): boolean;
|
|
31
|
+
/** Split string by substring length, intended to be used internally for hex and binary converters only */
|
|
32
|
+
export declare function _splitByCharLength(str: string, splitByChars?: number): string[];
|
|
33
|
+
/** Pad start of a byte with 0 for `hex` or `binary` */
|
|
34
|
+
export declare function _padStartWith0(byte: number, type: 'hex' | 'binary'): string;
|
package/dist/dts/hash/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { generateRandomID, generateRandomID as randomID } from '../string/basics
|
|
|
3
3
|
export { Cipher } from './Cipher';
|
|
4
4
|
export { md5, sha1, sha256 } from './core';
|
|
5
5
|
export { Signet } from './Signet';
|
|
6
|
-
export {
|
|
6
|
+
export { TextCodec } from './TextCodec';
|
|
7
|
+
export { base64ToBytes, bytesToBase64, bytesToHex, bytesToUtf8, concatBytes, hexToBytes, hmacSha256, intTo4BytesBE, randomHex, sha256Bytes, uint8To32ArrayBE, utf8ToBytes, } from './utils';
|
|
7
8
|
export { decodeUUID, isUUIDv1, isUUIDv2, isUUIDv3, isUUIDv4, isUUIDv5, isUUIDv6, isUUIDv7, isUUIDv8, uuid, } from './uuid';
|
package/dist/dts/hash/utils.d.ts
CHANGED
|
@@ -343,6 +343,45 @@ export declare function intTo4BytesBE(n: number): Uint8Array;
|
|
|
343
343
|
* - Converting binary data for JSON serialization
|
|
344
344
|
* - Creating hex-encoded strings for APIs and protocols
|
|
345
345
|
*
|
|
346
|
-
* @see {@link
|
|
346
|
+
* @see {@link hexToBytes} for reverse process
|
|
347
347
|
*/
|
|
348
348
|
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
349
|
+
/**
|
|
350
|
+
* * Converts a hexadecimal string to a `Uint8Array`.
|
|
351
|
+
* - This function decodes a hexadecimal-encoded string into its raw byte representation, where every two hexadecimal characters (00–ff) are converted into one byte.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* // Convert hex to bytes
|
|
356
|
+
* const hex = '12abff00';
|
|
357
|
+
* const bytes = hexToBytes(hex);
|
|
358
|
+
* // Returns: Uint8Array(4) [18, 171, 255, 0]
|
|
359
|
+
*
|
|
360
|
+
* // Empty string
|
|
361
|
+
* const emptyBytes = hexToBytes('');
|
|
362
|
+
* // Returns: Uint8Array []
|
|
363
|
+
*
|
|
364
|
+
* // Decode SHA-256 hash from hex
|
|
365
|
+
* const hashHex = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824';
|
|
366
|
+
* const hashBytes = hexToBytes(hashHex);
|
|
367
|
+
* // Returns: Uint8Array(32)
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @param hex - A hexadecimal string where each byte is represented by two characters (00–ff).
|
|
371
|
+
* @returns A `Uint8Array` containing the decoded bytes. Returns an empty array for invalid input.
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* - Accepts lowercase and uppercase hexadecimal characters (0–9, a–f, A–F) with or without space between bytes
|
|
375
|
+
* - Ignores no prefixes (e.g., does not support "0x")
|
|
376
|
+
* - Requires an even number of hexadecimal characters
|
|
377
|
+
* - Efficient O(n) implementation with direct byte parsing
|
|
378
|
+
*
|
|
379
|
+
* **Common use cases:**
|
|
380
|
+
* - Decoding cryptographic hashes and signatures
|
|
381
|
+
* - Parsing hex-encoded binary payloads
|
|
382
|
+
* - Reconstructing binary data from storage or transport formats
|
|
383
|
+
* - Working with low-level protocols and binary APIs
|
|
384
|
+
*
|
|
385
|
+
* @see {@link bytesToHex} for the reverse process
|
|
386
|
+
*/
|
|
387
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -65,4 +65,4 @@ export { Paginator } from './utils/Paginator';
|
|
|
65
65
|
export { isBigInt, isBoolean, isFalsy, isInteger, isNonEmptyString, isNormalPrimitive, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives';
|
|
66
66
|
export { isReturningPromise as doesReturnPromise, isArray, isArrayOfType, isValidArray as isArrayWithLength, isDate, isEmptyObject, isEmptyObject as isEmptyObjectGuard, isError, isFunction, isJSON, isJSON as isJSONObject, isMap, isMethodDescriptor as isMethod, isMethodDescriptor, isNotEmptyObject, isObject, isEmptyObject as isObjectEmpty, isObjectWithKeys, isPromise, isRegExp, isRegExp as isRegularExpression, isReturningPromise, isSet, isValidArray, isJSON as isValidJSON, isMap as isValidMap, isNotEmptyObject as isValidObject, isSet as isValidSet, } from './guards/non-primitives';
|
|
67
67
|
export { HttpStatus, httpStatus } from './http-status/HttpStatus';
|
|
68
|
-
export { isBase64, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials';
|
|
68
|
+
export { isBase64, isBinaryString, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isHexString, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials';
|
|
@@ -7,10 +7,10 @@ export declare const ORDINAL_UNDER_TEEN: Readonly<Record<string, string>>;
|
|
|
7
7
|
/** Ordinals that don't cleanly map by suffix alone */
|
|
8
8
|
export declare const ORDINAL_TO_CARDINAL: Readonly<Record<string, string>>;
|
|
9
9
|
/** List of ISO 4217 currency codes */
|
|
10
|
-
export declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "
|
|
10
|
+
export declare const CURRENCY_CODES: readonly ["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "YER", "ZAR", "ZMW", "ZWL"];
|
|
11
11
|
/** List of all supported BCP 47 locales */
|
|
12
12
|
export declare const LOCALE_CODES: readonly ["af-ZA", "am-ET", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SD", "ar-SY", "ar-TN", "ar-YE", "az-AZ", "be-BY", "bg-BG", "bn-BD", "bn-IN", "bs-BA", "ca-ES", "cs-CZ", "cy-GB", "da-DK", "de-AT", "de-CH", "de-DE", "el-GR", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN", "en-NZ", "en-PH", "en-SG", "en-US", "en-ZA", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV", "es-US", "es-UY", "es-VE", "et-EE", "eu-ES", "fa-IR", "fi-FI", "fil-PH", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "ga-IE", "gl-ES", "gu-IN", "he-IL", "hi-IN", "hr-HR", "hu-HU", "hy-AM", "id-ID", "is-IS", "it-CH", "it-IT", "ja-JP", "ka-GE", "kk-KZ", "km-KH", "kn-IN", "ko-KR", "ky-KG", "lt-LT", "lv-LV", "mk-MK", "ml-IN", "mn-MN", "mr-IN", "ms-MY", "mt-MT", "nb-NO", "ne-NP", "nl-BE", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sk-SK", "sl-SI", "sq-AL", "sr-Latn", "sv-SE", "sw-KE", "ta-IN", "te-IN", "th-TH", "tr-TR", "uk-UA", "ur-PK", "uz-UZ", "vi-VN", "zh-CN", "zh-HK", "zh-TW"];
|
|
13
|
-
/** Mapping of CurrencyCodes to LocaleCodes */
|
|
13
|
+
/** Mapping of CurrencyCodes to `LocaleCodes` */
|
|
14
14
|
export declare const CURRENCY_LOCALES: Readonly<{
|
|
15
15
|
readonly AED: "ar-AE";
|
|
16
16
|
readonly AFN: "fa-IR";
|
|
@@ -164,10 +164,6 @@ export declare const CURRENCY_LOCALES: Readonly<{
|
|
|
164
164
|
readonly VND: "vi-VN";
|
|
165
165
|
readonly VUV: "en-VU";
|
|
166
166
|
readonly WST: "en-WS";
|
|
167
|
-
readonly XAF: "fr-XAF";
|
|
168
|
-
readonly XCD: "en-XCD";
|
|
169
|
-
readonly XOF: "fr-XOF";
|
|
170
|
-
readonly XPF: "fr-XPF";
|
|
171
167
|
readonly YER: "ar-YE";
|
|
172
168
|
readonly ZAR: "en-ZA";
|
|
173
169
|
readonly ZMW: "en-ZM";
|
package/dist/esm/date/Chronos.js
CHANGED
|
@@ -213,7 +213,7 @@ export class Chronos {
|
|
|
213
213
|
return this.toDate().toISOString();
|
|
214
214
|
}
|
|
215
215
|
toLocaleString(locales, options) {
|
|
216
|
-
return this.
|
|
216
|
+
return this.#date.toLocaleString(locales, options);
|
|
217
217
|
}
|
|
218
218
|
getTimeStamp() {
|
|
219
219
|
return this.toDate().getTime();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chronos } from './Chronos.js';
|
|
2
|
-
const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
2
|
+
const $chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
3
3
|
if (typeof valueOrYear === 'number' && typeof month === 'number') {
|
|
4
4
|
return new Chronos(valueOrYear, month, date ?? 1, hours ?? 0, minutes ?? 0, seconds ?? 0, ms ?? 0);
|
|
5
5
|
}
|
|
@@ -7,27 +7,25 @@ const chronos = (valueOrYear, month, date, hours, minutes, seconds, ms) => {
|
|
|
7
7
|
return new Chronos(valueOrYear);
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
function _isChronosStaticKey(prop) {
|
|
11
|
+
return (prop in Chronos &&
|
|
12
|
+
prop !== 'prototype' &&
|
|
13
|
+
prop !== 'name' &&
|
|
14
|
+
prop !== 'length' &&
|
|
15
|
+
typeof Chronos[prop] === 'function');
|
|
16
|
+
}
|
|
17
|
+
const chronosStatics = new Proxy($chronos, {
|
|
11
18
|
get(target, prop, receiver) {
|
|
12
19
|
if (prop in target) {
|
|
13
20
|
return Reflect.get(target, prop, receiver);
|
|
14
21
|
}
|
|
15
|
-
if (prop
|
|
16
|
-
prop !== 'prototype' &&
|
|
17
|
-
prop !== 'name' &&
|
|
18
|
-
prop !== 'length' &&
|
|
19
|
-
typeof Chronos[prop] === 'function') {
|
|
22
|
+
if (_isChronosStaticKey(prop)) {
|
|
20
23
|
return Chronos[prop];
|
|
21
24
|
}
|
|
22
25
|
return Reflect.get(target, prop, receiver);
|
|
23
26
|
},
|
|
24
27
|
has(target, prop) {
|
|
25
|
-
return
|
|
26
|
-
(prop in Chronos &&
|
|
27
|
-
prop !== 'prototype' &&
|
|
28
|
-
prop !== 'name' &&
|
|
29
|
-
prop !== 'length' &&
|
|
30
|
-
typeof Chronos[prop] === 'function'));
|
|
28
|
+
return prop in target || _isChronosStaticKey(prop);
|
|
31
29
|
},
|
|
32
30
|
});
|
|
33
31
|
export { chronosStatics as chronos };
|
|
@@ -148,3 +148,102 @@ export const MS_MAP = /* @__PURE__ */ Object.freeze((() => {
|
|
|
148
148
|
milliseconds: 1,
|
|
149
149
|
};
|
|
150
150
|
})());
|
|
151
|
+
export const LOCALE_CALENDARS = /* @__PURE__ */ Object.freeze([
|
|
152
|
+
'buddhist',
|
|
153
|
+
'chinese',
|
|
154
|
+
'coptic',
|
|
155
|
+
'dangi',
|
|
156
|
+
'ethioaa',
|
|
157
|
+
'ethiopic',
|
|
158
|
+
'gregory',
|
|
159
|
+
'hebrew',
|
|
160
|
+
'indian',
|
|
161
|
+
'islamic',
|
|
162
|
+
'islamic-civil',
|
|
163
|
+
'islamic-rgsa',
|
|
164
|
+
'islamic-tbla',
|
|
165
|
+
'islamic-umalqura',
|
|
166
|
+
'iso8601',
|
|
167
|
+
'japanese',
|
|
168
|
+
'persian',
|
|
169
|
+
'roc',
|
|
170
|
+
]);
|
|
171
|
+
export const LOCALE_NUMBERING_SYSTEMS = /* @__PURE__ */ Object.freeze([
|
|
172
|
+
'adlm',
|
|
173
|
+
'ahom',
|
|
174
|
+
'arab',
|
|
175
|
+
'arabext',
|
|
176
|
+
'bali',
|
|
177
|
+
'beng',
|
|
178
|
+
'bhks',
|
|
179
|
+
'brah',
|
|
180
|
+
'cakm',
|
|
181
|
+
'cham',
|
|
182
|
+
'deva',
|
|
183
|
+
'diak',
|
|
184
|
+
'fullwide',
|
|
185
|
+
'gara',
|
|
186
|
+
'gong',
|
|
187
|
+
'gonm',
|
|
188
|
+
'gujr',
|
|
189
|
+
'gukh',
|
|
190
|
+
'guru',
|
|
191
|
+
'hanidec',
|
|
192
|
+
'hmng',
|
|
193
|
+
'hmnp',
|
|
194
|
+
'java',
|
|
195
|
+
'kali',
|
|
196
|
+
'kawi',
|
|
197
|
+
'khmr',
|
|
198
|
+
'knda',
|
|
199
|
+
'krai',
|
|
200
|
+
'lana',
|
|
201
|
+
'lanatham',
|
|
202
|
+
'laoo',
|
|
203
|
+
'latn',
|
|
204
|
+
'lepc',
|
|
205
|
+
'limb',
|
|
206
|
+
'mathbold',
|
|
207
|
+
'mathdbl',
|
|
208
|
+
'mathmono',
|
|
209
|
+
'mathsanb',
|
|
210
|
+
'mathsans',
|
|
211
|
+
'mlym',
|
|
212
|
+
'modi',
|
|
213
|
+
'mong',
|
|
214
|
+
'mroo',
|
|
215
|
+
'mtei',
|
|
216
|
+
'mymr',
|
|
217
|
+
'mymrepka',
|
|
218
|
+
'mymrpao',
|
|
219
|
+
'mymrshan',
|
|
220
|
+
'mymrtlng',
|
|
221
|
+
'nagm',
|
|
222
|
+
'newa',
|
|
223
|
+
'nkoo',
|
|
224
|
+
'olck',
|
|
225
|
+
'onao',
|
|
226
|
+
'orya',
|
|
227
|
+
'osma',
|
|
228
|
+
'outlined',
|
|
229
|
+
'rohg',
|
|
230
|
+
'saur',
|
|
231
|
+
'segment',
|
|
232
|
+
'shrd',
|
|
233
|
+
'sind',
|
|
234
|
+
'sinh',
|
|
235
|
+
'sora',
|
|
236
|
+
'sund',
|
|
237
|
+
'sunu',
|
|
238
|
+
'takr',
|
|
239
|
+
'talu',
|
|
240
|
+
'tamldec',
|
|
241
|
+
'telu',
|
|
242
|
+
'thai',
|
|
243
|
+
'tibt',
|
|
244
|
+
'tirh',
|
|
245
|
+
'tnsa',
|
|
246
|
+
'vaii',
|
|
247
|
+
'wara',
|
|
248
|
+
'wcho',
|
|
249
|
+
]);
|
|
@@ -35,6 +35,14 @@ export function isBase64(value) {
|
|
|
35
35
|
return (isString(value) &&
|
|
36
36
|
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value));
|
|
37
37
|
}
|
|
38
|
+
export function isHexString(value) {
|
|
39
|
+
return (isString(value) &&
|
|
40
|
+
/^[\da-fA-F\s]+$/.test(value) &&
|
|
41
|
+
value.replace(/\s+/g, '').length % 2 === 0);
|
|
42
|
+
}
|
|
43
|
+
export function isBinaryString(value) {
|
|
44
|
+
return (isString(value) && /^[01\s]+$/.test(value) && value.replace(/\s+/g, '').length % 8 === 0);
|
|
45
|
+
}
|
|
38
46
|
export function isPhoneNumber(value) {
|
|
39
47
|
return isString(value) && /^\+?[1-9]\d{1,14}$/.test(value);
|
|
40
48
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isNonEmptyString } from '../guards/primitives.js';
|
|
2
|
+
import { isBase64, isBinaryString, isHexString } from '../guards/specials.js';
|
|
3
|
+
import { _padStartWith0, _splitByCharLength } from './helpers.js';
|
|
4
|
+
import { base64ToBytes, bytesToBase64, bytesToUtf8, hexToBytes, utf8ToBytes } from './utils.js';
|
|
5
|
+
export class TextCodec {
|
|
6
|
+
constructor() { }
|
|
7
|
+
static isValidHex(hex) {
|
|
8
|
+
return isHexString(hex);
|
|
9
|
+
}
|
|
10
|
+
static isValidBinary(binary) {
|
|
11
|
+
return isBinaryString(binary);
|
|
12
|
+
}
|
|
13
|
+
static isValidBase64(b64) {
|
|
14
|
+
return isBase64(b64);
|
|
15
|
+
}
|
|
16
|
+
static utf8ToHex(text, spaced = true) {
|
|
17
|
+
return [...utf8ToBytes(text)]
|
|
18
|
+
.map((b) => _padStartWith0(b, 'hex'))
|
|
19
|
+
.join(spaced ? ' ' : '');
|
|
20
|
+
}
|
|
21
|
+
static utf8ToBinary(text, spaced = true) {
|
|
22
|
+
return [...utf8ToBytes(text)]
|
|
23
|
+
.map((b) => _padStartWith0(b, 'binary'))
|
|
24
|
+
.join(spaced ? ' ' : '');
|
|
25
|
+
}
|
|
26
|
+
static hexToUtf8(hex) {
|
|
27
|
+
return bytesToUtf8(hexToBytes(hex));
|
|
28
|
+
}
|
|
29
|
+
static binaryToUtf8(binary) {
|
|
30
|
+
if (!isBinaryString(binary))
|
|
31
|
+
return '';
|
|
32
|
+
const bytes = _splitByCharLength(binary, 8).map((b) => parseInt(b, 2));
|
|
33
|
+
return bytesToUtf8(new Uint8Array(bytes));
|
|
34
|
+
}
|
|
35
|
+
static hexToBinary(hex, spaced = true) {
|
|
36
|
+
if (!isHexString(hex))
|
|
37
|
+
return '';
|
|
38
|
+
return _splitByCharLength(hex, 2)
|
|
39
|
+
.map((h) => _padStartWith0(parseInt(h, 16), 'binary'))
|
|
40
|
+
.join(spaced ? ' ' : '');
|
|
41
|
+
}
|
|
42
|
+
static binaryToHex(binary, spaced = true) {
|
|
43
|
+
if (!isBinaryString(binary))
|
|
44
|
+
return '';
|
|
45
|
+
return _splitByCharLength(binary, 8)
|
|
46
|
+
.map((b) => _padStartWith0(parseInt(b, 2), 'hex'))
|
|
47
|
+
.join(spaced ? ' ' : '');
|
|
48
|
+
}
|
|
49
|
+
static base64ToUtf8(b64) {
|
|
50
|
+
if (!isBase64(b64))
|
|
51
|
+
return '';
|
|
52
|
+
return bytesToUtf8(base64ToBytes(b64));
|
|
53
|
+
}
|
|
54
|
+
static utf8ToBase64(text) {
|
|
55
|
+
if (!isNonEmptyString(text))
|
|
56
|
+
return '';
|
|
57
|
+
return bytesToBase64(utf8ToBytes(text));
|
|
58
|
+
}
|
|
59
|
+
static base64ToHex(b64, spaced = true) {
|
|
60
|
+
return this.utf8ToHex(this.base64ToUtf8(b64), spaced);
|
|
61
|
+
}
|
|
62
|
+
static base64ToBinary(b64, spaced = true) {
|
|
63
|
+
return this.utf8ToBinary(this.base64ToUtf8(b64), spaced);
|
|
64
|
+
}
|
|
65
|
+
static hexToBase64(hex) {
|
|
66
|
+
return this.utf8ToBase64(this.hexToUtf8(hex));
|
|
67
|
+
}
|
|
68
|
+
static binaryToBase64(binary) {
|
|
69
|
+
return this.utf8ToBase64(this.binaryToUtf8(binary));
|
|
70
|
+
}
|
|
71
|
+
}
|
package/dist/esm/hash/helpers.js
CHANGED
|
@@ -156,3 +156,16 @@ export function _constantTimeEquals(a, b) {
|
|
|
156
156
|
}
|
|
157
157
|
return res === 0;
|
|
158
158
|
}
|
|
159
|
+
export function _splitByCharLength(str, splitByChars = 2) {
|
|
160
|
+
if (!isNonEmptyString(str))
|
|
161
|
+
return [];
|
|
162
|
+
const sanitized = str.replace(/\s+/g, '');
|
|
163
|
+
const result = [];
|
|
164
|
+
for (let i = 0; i < sanitized.length; i += splitByChars) {
|
|
165
|
+
result.push(sanitized.slice(i, i + splitByChars));
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
export function _padStartWith0(byte, type) {
|
|
170
|
+
return byte.toString(type === 'hex' ? 16 : 2).padStart(type === 'hex' ? 2 : 8, '0');
|
|
171
|
+
}
|
package/dist/esm/hash/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export { generateRandomID, generateRandomID as randomID } from '../string/basics
|
|
|
3
3
|
export { Cipher } from './Cipher.js';
|
|
4
4
|
export { md5, sha1, sha256 } from './core.js';
|
|
5
5
|
export { Signet } from './Signet.js';
|
|
6
|
-
export {
|
|
6
|
+
export { TextCodec } from './TextCodec.js';
|
|
7
|
+
export { base64ToBytes, bytesToBase64, bytesToHex, bytesToUtf8, concatBytes, hexToBytes, hmacSha256, intTo4BytesBE, randomHex, sha256Bytes, uint8To32ArrayBE, utf8ToBytes, } from './utils.js';
|
|
7
8
|
export { decodeUUID, isUUIDv1, isUUIDv2, isUUIDv3, isUUIDv4, isUUIDv5, isUUIDv6, isUUIDv7, isUUIDv8, uuid, } from './uuid.js';
|
package/dist/esm/hash/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isHexString } from '../guards/specials.js';
|
|
2
|
+
import { _splitByCharLength } from './helpers.js';
|
|
1
3
|
export function randomHex(length, uppercase = false) {
|
|
2
4
|
const genHex = () => Math.floor(Math.random() * 16).toString(16);
|
|
3
5
|
const hex = Array.from({ length }, genHex).join('');
|
|
@@ -237,3 +239,9 @@ export function bytesToHex(bytes) {
|
|
|
237
239
|
}
|
|
238
240
|
return hex;
|
|
239
241
|
}
|
|
242
|
+
export function hexToBytes(hex) {
|
|
243
|
+
if (!isHexString(hex))
|
|
244
|
+
return new Uint8Array();
|
|
245
|
+
const bytes = _splitByCharLength(hex, 2).map((h) => parseInt(h, 16));
|
|
246
|
+
return new Uint8Array(bytes);
|
|
247
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -50,4 +50,4 @@ export { Paginator } from './utils/Paginator.js';
|
|
|
50
50
|
export { isBigInt, isBoolean, isFalsy, isInteger, isNonEmptyString, isNormalPrimitive, isNull, isNumber, isPositiveInteger, isPrimitive, isString, isSymbol, isTruthy, isUndefined, } from './guards/primitives.js';
|
|
51
51
|
export { isReturningPromise as doesReturnPromise, isArray, isArrayOfType, isValidArray as isArrayWithLength, isDate, isEmptyObject, isEmptyObject as isEmptyObjectGuard, isError, isFunction, isJSON, isJSON as isJSONObject, isMap, isMethodDescriptor as isMethod, isMethodDescriptor, isNotEmptyObject, isObject, isEmptyObject as isObjectEmpty, isObjectWithKeys, isPromise, isRegExp, isRegExp as isRegularExpression, isReturningPromise, isSet, isValidArray, isJSON as isValidJSON, isMap as isValidMap, isNotEmptyObject as isValidObject, isSet as isValidSet, } from './guards/non-primitives.js';
|
|
52
52
|
export { HttpStatus, httpStatus } from './http-status/HttpStatus.js';
|
|
53
|
-
export { isBase64, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials.js';
|
|
53
|
+
export { isBase64, isBinaryString, isBrowser, isDateString, isEmail, isEmailArray, isEnvironment, isEnvironment as isExpectedNodeENV, isHexString, isIPAddress, isNode, isEnvironment as isNodeENV, isEnvironment as isNodeEnvironment, isNumericString, isPhoneNumber, isURL, isUUID, isEmail as isValidEmail, isURL as isValidURL, } from './guards/specials.js';
|
|
@@ -240,10 +240,6 @@ export const CURRENCY_CODES = /* @__PURE__ */ Object.freeze([
|
|
|
240
240
|
'VND',
|
|
241
241
|
'VUV',
|
|
242
242
|
'WST',
|
|
243
|
-
'XAF',
|
|
244
|
-
'XCD',
|
|
245
|
-
'XOF',
|
|
246
|
-
'XPF',
|
|
247
243
|
'YER',
|
|
248
244
|
'ZAR',
|
|
249
245
|
'ZMW',
|
|
@@ -529,10 +525,6 @@ export const CURRENCY_LOCALES = /* @__PURE__ */ Object.freeze({
|
|
|
529
525
|
VND: 'vi-VN',
|
|
530
526
|
VUV: 'en-VU',
|
|
531
527
|
WST: 'en-WS',
|
|
532
|
-
XAF: 'fr-XAF',
|
|
533
|
-
XCD: 'en-XCD',
|
|
534
|
-
XOF: 'fr-XOF',
|
|
535
|
-
XPF: 'fr-XPF',
|
|
536
528
|
YER: 'ar-YE',
|
|
537
529
|
ZAR: 'en-ZA',
|
|
538
530
|
ZMW: 'en-ZM',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.28.
|
|
3
|
+
"version": "4.28.44",
|
|
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",
|
|
@@ -29,8 +29,13 @@
|
|
|
29
29
|
"contributors": [
|
|
30
30
|
{
|
|
31
31
|
"name": "Nazmul Hassan",
|
|
32
|
-
"email": "
|
|
32
|
+
"email": "nazmulnhb007@yahoo.com",
|
|
33
33
|
"url": "https://github.com/nazmul-nhb"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Nazmul Hassan",
|
|
37
|
+
"email": "nazmulnhb@gmail.com",
|
|
38
|
+
"url": "https://github.com/nhb-nazmul"
|
|
34
39
|
}
|
|
35
40
|
],
|
|
36
41
|
"bugs": {
|
|
@@ -41,9 +46,9 @@
|
|
|
41
46
|
"devDependencies": {
|
|
42
47
|
"@eslint/js": "^9.39.2",
|
|
43
48
|
"@types/jest": "^30.0.0",
|
|
44
|
-
"@types/node": "^25.0.
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
46
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
+
"@types/node": "^25.0.3",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^8.50.0",
|
|
51
|
+
"@typescript-eslint/parser": "^8.50.0",
|
|
47
52
|
"eslint": "^9.39.2",
|
|
48
53
|
"eslint-config-prettier": "^10.1.8",
|
|
49
54
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -51,11 +56,11 @@
|
|
|
51
56
|
"husky": "^9.1.7",
|
|
52
57
|
"jest": "^30.2.0",
|
|
53
58
|
"lint-staged": "^16.2.7",
|
|
54
|
-
"nhb-scripts": "^1.9.
|
|
59
|
+
"nhb-scripts": "^1.9.2",
|
|
55
60
|
"prettier": "^3.7.4",
|
|
56
61
|
"ts-jest": "^29.4.6",
|
|
57
62
|
"typescript": "^5.9.3",
|
|
58
|
-
"typescript-eslint": "^8.
|
|
63
|
+
"typescript-eslint": "^8.50.0"
|
|
59
64
|
},
|
|
60
65
|
"keywords": [
|
|
61
66
|
"toolbox",
|