@simplysm/core-common 13.0.69 → 13.0.71
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/README.md +66 -267
- package/dist/common.types.d.ts +14 -14
- package/dist/errors/argument-error.d.ts +10 -10
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +2 -2
- package/dist/errors/argument-error.js.map +1 -1
- package/dist/errors/not-implemented-error.d.ts +8 -8
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/not-implemented-error.js.map +1 -1
- package/dist/errors/sd-error.d.ts +10 -10
- package/dist/errors/sd-error.d.ts.map +1 -1
- package/dist/errors/timeout-error.d.ts +10 -10
- package/dist/errors/timeout-error.js +3 -3
- package/dist/errors/timeout-error.js.map +1 -1
- package/dist/extensions/arr-ext.d.ts +2 -2
- package/dist/extensions/arr-ext.helpers.d.ts +8 -8
- package/dist/extensions/arr-ext.helpers.js +1 -1
- package/dist/extensions/arr-ext.helpers.js.map +1 -1
- package/dist/extensions/arr-ext.js +13 -13
- package/dist/extensions/arr-ext.js.map +1 -1
- package/dist/extensions/arr-ext.types.d.ts +57 -57
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/map-ext.d.ts +16 -16
- package/dist/extensions/set-ext.d.ts +11 -11
- package/dist/features/debounce-queue.d.ts +17 -15
- package/dist/features/debounce-queue.d.ts.map +1 -1
- package/dist/features/debounce-queue.js +6 -6
- package/dist/features/debounce-queue.js.map +1 -1
- package/dist/features/event-emitter.d.ts +20 -20
- package/dist/features/event-emitter.js +17 -17
- package/dist/features/serial-queue.d.ts +11 -11
- package/dist/features/serial-queue.js +5 -5
- package/dist/features/serial-queue.js.map +1 -1
- package/dist/globals.d.ts +4 -4
- package/dist/types/date-only.d.ts +64 -64
- package/dist/types/date-only.d.ts.map +1 -1
- package/dist/types/date-only.js +63 -63
- package/dist/types/date-time.d.ts +37 -37
- package/dist/types/date-time.d.ts.map +1 -1
- package/dist/types/date-time.js +54 -37
- package/dist/types/date-time.js.map +1 -1
- package/dist/types/lazy-gc-map.d.ts +26 -26
- package/dist/types/lazy-gc-map.d.ts.map +1 -1
- package/dist/types/lazy-gc-map.js +26 -26
- package/dist/types/lazy-gc-map.js.map +1 -1
- package/dist/types/time.d.ts +25 -25
- package/dist/types/time.d.ts.map +1 -1
- package/dist/types/time.js +25 -25
- package/dist/types/time.js.map +1 -1
- package/dist/types/uuid.d.ts +11 -11
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +12 -12
- package/dist/types/uuid.js.map +1 -1
- package/dist/utils/bytes.d.ts +17 -17
- package/dist/utils/bytes.js +4 -4
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/date-format.d.ts +45 -45
- package/dist/utils/date-format.js +1 -1
- package/dist/utils/date-format.js.map +1 -1
- package/dist/utils/error.d.ts +4 -4
- package/dist/utils/json.d.ts +17 -17
- package/dist/utils/json.js +3 -3
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/num.d.ts +23 -23
- package/dist/utils/obj.d.ts +111 -111
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +3 -3
- package/dist/utils/obj.js.map +1 -1
- package/dist/utils/path.d.ts +10 -10
- package/dist/utils/primitive.d.ts +5 -5
- package/dist/utils/primitive.js +1 -1
- package/dist/utils/primitive.js.map +1 -1
- package/dist/utils/str.d.ts +46 -46
- package/dist/utils/str.d.ts.map +1 -1
- package/dist/utils/str.js +5 -5
- package/dist/utils/str.js.map +1 -1
- package/dist/utils/template-strings.d.ts +26 -26
- package/dist/utils/transferable.d.ts +18 -18
- package/dist/utils/transferable.js +1 -1
- package/dist/utils/transferable.js.map +1 -1
- package/dist/utils/wait.d.ts +9 -9
- package/dist/utils/xml.d.ts +13 -13
- package/dist/utils/xml.d.ts.map +1 -1
- package/dist/utils/xml.js +1 -0
- package/dist/utils/xml.js.map +1 -1
- package/dist/zip/sd-zip.d.ts +22 -22
- package/dist/zip/sd-zip.js +16 -16
- package/package.json +4 -4
- package/src/common.types.ts +17 -17
- package/src/errors/argument-error.ts +15 -15
- package/src/errors/not-implemented-error.ts +9 -9
- package/src/errors/sd-error.ts +12 -12
- package/src/errors/timeout-error.ts +12 -12
- package/src/extensions/arr-ext.helpers.ts +10 -10
- package/src/extensions/arr-ext.ts +57 -57
- package/src/extensions/arr-ext.types.ts +59 -59
- package/src/extensions/map-ext.ts +16 -16
- package/src/extensions/set-ext.ts +11 -11
- package/src/features/debounce-queue.ts +21 -19
- package/src/features/event-emitter.ts +25 -25
- package/src/features/serial-queue.ts +13 -13
- package/src/globals.ts +4 -4
- package/src/index.ts +1 -1
- package/src/types/date-only.ts +83 -83
- package/src/types/date-time.ts +64 -44
- package/src/types/lazy-gc-map.ts +45 -45
- package/src/types/time.ts +34 -34
- package/src/types/uuid.ts +17 -17
- package/src/utils/bytes.ts +35 -35
- package/src/utils/date-format.ts +65 -65
- package/src/utils/error.ts +4 -4
- package/src/utils/json.ts +39 -39
- package/src/utils/num.ts +23 -23
- package/src/utils/obj.ts +138 -138
- package/src/utils/path.ts +10 -10
- package/src/utils/primitive.ts +6 -6
- package/src/utils/str.ts +260 -261
- package/src/utils/template-strings.ts +29 -29
- package/src/utils/transferable.ts +284 -284
- package/src/utils/wait.ts +10 -10
- package/src/utils/xml.ts +20 -19
- package/src/zip/sd-zip.ts +25 -25
- package/tests/errors/errors.spec.ts +80 -0
- package/tests/extensions/array-extension.spec.ts +796 -0
- package/tests/extensions/map-extension.spec.ts +147 -0
- package/tests/extensions/set-extension.spec.ts +74 -0
- package/tests/types/date-only.spec.ts +638 -0
- package/tests/types/date-time.spec.ts +391 -0
- package/tests/types/lazy-gc-map.spec.ts +692 -0
- package/tests/types/time.spec.ts +559 -0
- package/tests/types/uuid.spec.ts +74 -0
- package/tests/utils/bytes-utils.spec.ts +230 -0
- package/tests/utils/date-format.spec.ts +373 -0
- package/tests/utils/debounce-queue.spec.ts +272 -0
- package/tests/utils/json.spec.ts +486 -0
- package/tests/utils/number.spec.ts +157 -0
- package/tests/utils/object.spec.ts +829 -0
- package/tests/utils/path.spec.ts +78 -0
- package/tests/utils/primitive.spec.ts +43 -0
- package/tests/utils/sd-event-emitter.spec.ts +216 -0
- package/tests/utils/serial-queue.spec.ts +365 -0
- package/tests/utils/string.spec.ts +281 -0
- package/tests/utils/template-strings.spec.ts +57 -0
- package/tests/utils/transferable.spec.ts +703 -0
- package/tests/utils/wait.spec.ts +145 -0
- package/tests/utils/xml.spec.ts +146 -0
- package/tests/zip/sd-zip.spec.ts +238 -0
- package/docs/extensions.md +0 -503
- package/docs/features.md +0 -109
- package/docs/types.md +0 -486
- package/docs/utils.md +0 -780
package/src/utils/num.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Number utility functions
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
//#region numParseInt / numParseFloat / numParseRoundedInt
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Parse string to integer
|
|
9
|
+
* Remove non-numeric characters (except 0-9, -, .) before parsing
|
|
10
10
|
*
|
|
11
|
-
* @note
|
|
12
|
-
*
|
|
13
|
-
* @note
|
|
14
|
-
*
|
|
11
|
+
* @note Strings with decimal points return only the integer part (e.g., '12.34' → 12).
|
|
12
|
+
* Use {@link numParseRoundedInt} if rounding is needed.
|
|
13
|
+
* @note Hyphens (-) in the middle of the string are preserved, which may result in unintended negative numbers.
|
|
14
|
+
* Example: `"가-123나"` → `-123`
|
|
15
15
|
*/
|
|
16
16
|
export function numParseInt(text: unknown): number | undefined {
|
|
17
17
|
if (typeof text === "number") return Math.trunc(text);
|
|
@@ -24,7 +24,7 @@ export function numParseInt(text: unknown): number | undefined {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Parse string to float, then round and return integer
|
|
28
28
|
*/
|
|
29
29
|
export function numParseRoundedInt(text: unknown): number | undefined {
|
|
30
30
|
const float = numParseFloat(text);
|
|
@@ -32,8 +32,8 @@ export function numParseRoundedInt(text: unknown): number | undefined {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* Parse string to float
|
|
36
|
+
* Remove non-numeric characters before parsing
|
|
37
37
|
*/
|
|
38
38
|
export function numParseFloat(text: unknown): number | undefined {
|
|
39
39
|
if (typeof text === "number") return text;
|
|
@@ -50,21 +50,21 @@ export function numParseFloat(text: unknown): number | undefined {
|
|
|
50
50
|
//#region numIsNullOrEmpty
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* undefined, null, 0
|
|
53
|
+
* Check undefined, null, 0 (type guard)
|
|
54
54
|
*
|
|
55
|
-
*
|
|
56
|
-
* false
|
|
55
|
+
* Acts as a type guard, guaranteeing that if true is returned, `val` is `0 | undefined`.
|
|
56
|
+
* If false is returned, `val` is guaranteed to be a valid non-zero number.
|
|
57
57
|
*
|
|
58
|
-
* @param val
|
|
59
|
-
* @returns undefined, null, 0
|
|
58
|
+
* @param val Value to check
|
|
59
|
+
* @returns true if undefined, null, or 0
|
|
60
60
|
* @example
|
|
61
61
|
* const count: number | undefined = getValue();
|
|
62
62
|
* if (numIsNullOrEmpty(count)) {
|
|
63
63
|
* // count: 0 | undefined
|
|
64
|
-
* console.log("
|
|
64
|
+
* console.log("Empty");
|
|
65
65
|
* } else {
|
|
66
|
-
* // count: number (
|
|
67
|
-
* console.log(
|
|
66
|
+
* // count: number (non-zero value)
|
|
67
|
+
* console.log(`Count: ${count}`);
|
|
68
68
|
* }
|
|
69
69
|
*/
|
|
70
70
|
export function numIsNullOrEmpty(val: number | undefined): val is 0 | undefined {
|
|
@@ -76,11 +76,11 @@ export function numIsNullOrEmpty(val: number | undefined): val is 0 | undefined
|
|
|
76
76
|
//#region numFormat
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param val
|
|
81
|
-
* @param digit
|
|
82
|
-
* @param digit.max
|
|
83
|
-
* @param digit.min
|
|
79
|
+
* Format number to string with thousand separators
|
|
80
|
+
* @param val Number to format
|
|
81
|
+
* @param digit Decimal place options
|
|
82
|
+
* @param digit.max Maximum decimal places
|
|
83
|
+
* @param digit.min Minimum decimal places (pad with 0 if insufficient)
|
|
84
84
|
* @example
|
|
85
85
|
* numFormat(1234.567, { max: 2 }) // "1,234.57"
|
|
86
86
|
* numFormat(1234, { min: 2 }) // "1,234.00"
|