@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/README.md
CHANGED
|
@@ -29,6 +29,7 @@ npm i @salespark/toolkit
|
|
|
29
29
|
- **String utilities**: slugify, template fill, deburr, sanitize, capitalize words/sentences.
|
|
30
30
|
- **Number utilities**: clamp, round, safe arithmetic/comparisons, safe parse (locale-aware), random digits, etc.
|
|
31
31
|
- **Function utilities**: debounce, throttle, safeJSONParse, formatCurrency, parseName, currency conversions, etc.
|
|
32
|
+
- **Defer utilities**: post-return microtask scheduling, non-critical timers, after-response hooks.
|
|
32
33
|
- **Boolean utilities**: safe boolean conversion with common representations
|
|
33
34
|
- **Validation utilities**: IBAN validator (ISO 13616), Portuguese tax ID validator
|
|
34
35
|
- **Security utilities**: Markdown XSS protection, content sanitization, risk assessment
|
|
@@ -704,6 +705,43 @@ currencyToSymbol("UNKNOWN");
|
|
|
704
705
|
// Result: "€" (fallback)
|
|
705
706
|
```
|
|
706
707
|
|
|
708
|
+
### 🕒 Defer Utilities
|
|
709
|
+
|
|
710
|
+
**`deferPostReturn(fn: () => void | Promise<void>): void`** — Runs a function right after the current call stack completes (microtask), without blocking the caller.
|
|
711
|
+
|
|
712
|
+
```javascript
|
|
713
|
+
const order = [];
|
|
714
|
+
order.push("a");
|
|
715
|
+
deferPostReturn(() => order.push("b"));
|
|
716
|
+
order.push("c");
|
|
717
|
+
// After the current stack finishes (microtask): order = ["a", "c", "b"]
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
**`deferNonCritical(fn: () => void | Promise<void>): void`** — Schedules a function as late as possible (low priority) for non-critical work.
|
|
721
|
+
|
|
722
|
+
```javascript
|
|
723
|
+
deferNonCritical(() => {
|
|
724
|
+
// logs, metrics, cleanup — runs later without competing with main work
|
|
725
|
+
});
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
**`deferAfterResponse(res: { once: (event: "finish" | "close", listener: (...args: any[]) => void) => void; writableEnded?: boolean }, fn: () => void | Promise<void>): void`** — Runs a function after the HTTP response is finished (sent to the client), scheduled soon (microtask).
|
|
729
|
+
|
|
730
|
+
```javascript
|
|
731
|
+
// Example with a response-like object
|
|
732
|
+
deferAfterResponse(res, () => {
|
|
733
|
+
// post-response tasks — lightweight, run shortly after sending
|
|
734
|
+
});
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
**`deferAfterResponseNonCritical(res: { once: (event: "finish" | "close", listener: (...args: any[]) => void) => void; writableEnded?: boolean }, fn: () => void | Promise<void>): void`** — Runs a function after the HTTP response is finished, scheduled as low priority (as late as possible).
|
|
738
|
+
|
|
739
|
+
```javascript
|
|
740
|
+
deferAfterResponseNonCritical(res, () => {
|
|
741
|
+
// non-critical post-response work — scheduled with low priority
|
|
742
|
+
});
|
|
743
|
+
```
|
|
744
|
+
|
|
707
745
|
### 🔒 Security Utilities
|
|
708
746
|
|
|
709
747
|
**`checkMarkdownSecurity(text: string | null | undefined): SecurityCheckResult`** — Comprehensive markdown security validation with XSS protection, threat detection, and automatic sanitization.
|
|
@@ -908,5 +946,5 @@ MIT © [SalesPark](https://salespark.io)
|
|
|
908
946
|
|
|
909
947
|
---
|
|
910
948
|
|
|
911
|
-
_Document version:
|
|
912
|
-
_Last update:
|
|
949
|
+
_Document version: 13_
|
|
950
|
+
_Last update: 09-01-2026_
|
package/dist/index.cjs
CHANGED
|
@@ -451,6 +451,7 @@ var formatDecimalNumber = (value, decimals = 2) => {
|
|
|
451
451
|
|
|
452
452
|
// src/utils/func.ts
|
|
453
453
|
function safeJSONParse(input, defaultValue) {
|
|
454
|
+
const def = isNilOrEmpty(defaultValue) === false ? defaultValue : {};
|
|
454
455
|
if (typeof input === "object" && input !== null) {
|
|
455
456
|
return input;
|
|
456
457
|
}
|
|
@@ -459,10 +460,10 @@ function safeJSONParse(input, defaultValue) {
|
|
|
459
460
|
const parsed = JSON.parse(input);
|
|
460
461
|
return parsed;
|
|
461
462
|
} catch {
|
|
462
|
-
return
|
|
463
|
+
return def;
|
|
463
464
|
}
|
|
464
465
|
}
|
|
465
|
-
return
|
|
466
|
+
return def;
|
|
466
467
|
}
|
|
467
468
|
function debounce(fn, wait = 250) {
|
|
468
469
|
let t;
|