@salespark/toolkit 2.1.10 → 2.1.12
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 +40 -2
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -437,7 +437,7 @@ declare const toInteger: typeof safeParseInt;
|
|
|
437
437
|
* Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
|
|
438
438
|
* Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42
|
|
439
439
|
* @param {unknown} value - Value to convert
|
|
440
|
-
* @param {number} decimals - Number of decimal places
|
|
440
|
+
* @param {number} decimals - Number of decimal places (default 6)
|
|
441
441
|
* History:
|
|
442
442
|
* 21-08-2025: Created
|
|
443
443
|
* 29-10-2025: Renamed from toNumber to safeParseFloat
|
|
@@ -489,12 +489,12 @@ declare const formatDecimalNumber: (value: number | string | null | undefined, d
|
|
|
489
489
|
* ##: Safe JSON Parse
|
|
490
490
|
* Safely parses a JSON string or returns the object if already parsed. Falls back to default value on failure.
|
|
491
491
|
* @param {unknown} input - The value to parse (string or object)
|
|
492
|
-
* @param {T} defaultValue - The default value to return if parsing fails or input is invalid
|
|
492
|
+
* @param {T} [defaultValue] - The default value to return if parsing fails or input is invalid, defaults to {}
|
|
493
493
|
* @returns {T} The parsed object or default value
|
|
494
494
|
* History:
|
|
495
495
|
* 21-12-2025: Created
|
|
496
|
-
|
|
497
|
-
declare function safeJSONParse<T>(input: unknown, defaultValue
|
|
496
|
+
******************************************************/
|
|
497
|
+
declare function safeJSONParse<T>(input: unknown, defaultValue?: T): T;
|
|
498
498
|
/******************************************************
|
|
499
499
|
* ##: Debounce Function
|
|
500
500
|
* Returns a debounced version of a function that delays execution until after wait ms
|
package/dist/index.d.ts
CHANGED
|
@@ -437,7 +437,7 @@ declare const toInteger: typeof safeParseInt;
|
|
|
437
437
|
* Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
|
|
438
438
|
* Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42
|
|
439
439
|
* @param {unknown} value - Value to convert
|
|
440
|
-
* @param {number} decimals - Number of decimal places
|
|
440
|
+
* @param {number} decimals - Number of decimal places (default 6)
|
|
441
441
|
* History:
|
|
442
442
|
* 21-08-2025: Created
|
|
443
443
|
* 29-10-2025: Renamed from toNumber to safeParseFloat
|
|
@@ -489,12 +489,12 @@ declare const formatDecimalNumber: (value: number | string | null | undefined, d
|
|
|
489
489
|
* ##: Safe JSON Parse
|
|
490
490
|
* Safely parses a JSON string or returns the object if already parsed. Falls back to default value on failure.
|
|
491
491
|
* @param {unknown} input - The value to parse (string or object)
|
|
492
|
-
* @param {T} defaultValue - The default value to return if parsing fails or input is invalid
|
|
492
|
+
* @param {T} [defaultValue] - The default value to return if parsing fails or input is invalid, defaults to {}
|
|
493
493
|
* @returns {T} The parsed object or default value
|
|
494
494
|
* History:
|
|
495
495
|
* 21-12-2025: Created
|
|
496
|
-
|
|
497
|
-
declare function safeJSONParse<T>(input: unknown, defaultValue
|
|
496
|
+
******************************************************/
|
|
497
|
+
declare function safeJSONParse<T>(input: unknown, defaultValue?: T): T;
|
|
498
498
|
/******************************************************
|
|
499
499
|
* ##: Debounce Function
|
|
500
500
|
* Returns a debounced version of a function that delays execution until after wait ms
|
package/dist/index.js
CHANGED
|
@@ -449,6 +449,7 @@ var formatDecimalNumber = (value, decimals = 2) => {
|
|
|
449
449
|
|
|
450
450
|
// src/utils/func.ts
|
|
451
451
|
function safeJSONParse(input, defaultValue) {
|
|
452
|
+
const def = isNilOrEmpty(defaultValue) === false ? defaultValue : {};
|
|
452
453
|
if (typeof input === "object" && input !== null) {
|
|
453
454
|
return input;
|
|
454
455
|
}
|
|
@@ -457,10 +458,10 @@ function safeJSONParse(input, defaultValue) {
|
|
|
457
458
|
const parsed = JSON.parse(input);
|
|
458
459
|
return parsed;
|
|
459
460
|
} catch {
|
|
460
|
-
return
|
|
461
|
+
return def;
|
|
461
462
|
}
|
|
462
463
|
}
|
|
463
|
-
return
|
|
464
|
+
return def;
|
|
464
465
|
}
|
|
465
466
|
function debounce(fn, wait = 250) {
|
|
466
467
|
let t;
|