@salespark/toolkit 2.1.22 → 2.1.26
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 +57 -2
- package/dist/index.cjs +45 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +38 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> **npm registry notice:** On **2 May 2026** (timezone **Europe/Lisbon**), this package will no longer be **publicly** installable from the npm registry and will become **restricted to the SalesPark npm organization**. Until then, already-published versions remain public. **No further public releases** or support for external consumers is planned — if you depend on this package, **fork** before that date.
|
|
2
|
+
|
|
1
3
|
# SalesPark Toolkit v2 - Documentation
|
|
2
4
|
|
|
3
5
|
## @salespark/toolkit
|
|
@@ -28,6 +30,7 @@ npm i @salespark/toolkit
|
|
|
28
30
|
- **Object utilities**: pick, omit, clean objects, deep merge, etc.
|
|
29
31
|
- **String utilities**: slugify, template fill, deburr, sanitize, capitalize words/sentences, SMS length.
|
|
30
32
|
- **Number utilities**: clamp, round, safe arithmetic/comparisons, safe parse (locale-aware), random digits, etc.
|
|
33
|
+
- **Random utilities**: token generation helpers (non-crypto), random IDs, shuffle helpers
|
|
31
34
|
- **Function utilities**: debounce, throttle, safeJSONParse, formatCurrency, parseName, currency conversions, etc.
|
|
32
35
|
- **Defer utilities**: post-return microtask scheduling, non-critical timers, after-response hooks.
|
|
33
36
|
- **Boolean utilities**: safe boolean conversion with common representations
|
|
@@ -482,6 +485,58 @@ formatDecimalNumber("invalid", 2); // "0.00"
|
|
|
482
485
|
- **`parseToNumber`** → Use `safeParseFloat` instead
|
|
483
486
|
- **`otp`** → Use `randomDigits` instead
|
|
484
487
|
|
|
488
|
+
### 🎲 Random Utilities
|
|
489
|
+
|
|
490
|
+
**`createToken(options?: { withUppercase?: boolean; withLowercase?: boolean; withNumbers?: boolean; withSymbols?: boolean; length?: number; alphabet?: string }): string`** — Generates a random token string using Math.random (non-crypto) and a configurable alphabet.
|
|
491
|
+
|
|
492
|
+
```javascript
|
|
493
|
+
createToken(); // 64-char token (letters + numbers)
|
|
494
|
+
createToken({ length: 16, withSymbols: true });
|
|
495
|
+
createToken({ alphabet: "ABCDEF0123456789", length: 24 }); // custom alphabet
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
**`random(): number`** — Returns a random float in the range [0, 1) using Math.random (non-crypto).
|
|
499
|
+
|
|
500
|
+
```javascript
|
|
501
|
+
random(); // 0.123456...
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
**`randFromArray<T>(array: T[]): T`** — Picks a random element from an array.
|
|
505
|
+
|
|
506
|
+
```javascript
|
|
507
|
+
randFromArray(["a", "b", "c"]); // random element
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
**`randIntFromInterval(min: number, max: number): number`** — Returns a random integer in [min, max).
|
|
511
|
+
|
|
512
|
+
```javascript
|
|
513
|
+
randIntFromInterval(10, 20); // 10..19
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
**`shuffleArray<T>(array: T[]): T[]`** — Returns a shuffled copy of the input array.
|
|
517
|
+
|
|
518
|
+
```javascript
|
|
519
|
+
shuffleArray([1, 2, 3]); // new shuffled array
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**`shuffleArrayMutate<T>(array: T[]): T[]`** — Shuffles an array in place (mutates input).
|
|
523
|
+
|
|
524
|
+
```javascript
|
|
525
|
+
shuffleArrayMutate([1, 2, 3]); // same array instance, shuffled
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
**`shuffleString(str: string, delimiter?: string): string`** — Shuffles a string by splitting and rejoining.
|
|
529
|
+
|
|
530
|
+
```javascript
|
|
531
|
+
shuffleString("abc"); // "bca" (random order)
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
**`generateRandomId(): string`** — Generates a short id with prefix "id-" and a base36 segment.
|
|
535
|
+
|
|
536
|
+
```javascript
|
|
537
|
+
generateRandomId(); // "id-5gk9x1c2qz" (random)
|
|
538
|
+
```
|
|
539
|
+
|
|
485
540
|
### ✅ Boolean Utilities
|
|
486
541
|
|
|
487
542
|
**`toBool(value: unknown, def?: boolean): boolean`** — Converts a value to boolean, supporting common string/number representations.
|
|
@@ -1114,5 +1169,5 @@ MIT © [SalesPark](https://salespark.io)
|
|
|
1114
1169
|
|
|
1115
1170
|
---
|
|
1116
1171
|
|
|
1117
|
-
_Document version:
|
|
1118
|
-
_Last update:
|
|
1172
|
+
_Document version: 19_
|
|
1173
|
+
_Last update: 04-04-2026_
|
package/dist/index.cjs
CHANGED
|
@@ -2677,6 +2677,43 @@ var smsLength = (text, singleOverrides, multiOverrides) => {
|
|
|
2677
2677
|
};
|
|
2678
2678
|
};
|
|
2679
2679
|
|
|
2680
|
+
// src/utils/random.ts
|
|
2681
|
+
var random = () => Math.random();
|
|
2682
|
+
var randFromArray = (array) => array[Math.floor(random() * array.length)];
|
|
2683
|
+
var randIntFromInterval = (min, max) => Math.floor(random() * (max - min) + min);
|
|
2684
|
+
function shuffleArrayMutate(array) {
|
|
2685
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
2686
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
2687
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
2688
|
+
}
|
|
2689
|
+
return array;
|
|
2690
|
+
}
|
|
2691
|
+
var shuffleArray = (array) => shuffleArrayMutate([...array]);
|
|
2692
|
+
var shuffleString = (str, delimiter = "") => shuffleArrayMutate(str.split(delimiter)).join(delimiter);
|
|
2693
|
+
function createToken({
|
|
2694
|
+
withUppercase = true,
|
|
2695
|
+
withLowercase = true,
|
|
2696
|
+
withNumbers = true,
|
|
2697
|
+
withSymbols = false,
|
|
2698
|
+
length = 64,
|
|
2699
|
+
alphabet
|
|
2700
|
+
} = {}) {
|
|
2701
|
+
const allAlphabet = alphabet ?? [
|
|
2702
|
+
withUppercase ? "ABCDEFGHIJKLMOPQRSTUVWXYZ" : "",
|
|
2703
|
+
withLowercase ? "abcdefghijklmopqrstuvwxyz" : "",
|
|
2704
|
+
withNumbers ? "0123456789" : "",
|
|
2705
|
+
withSymbols ? `.,;:!?./-"'#{([-|\\@)]=}*+` : ""
|
|
2706
|
+
].join("");
|
|
2707
|
+
const safeLength = Number.isFinite(length) ? Math.max(0, Math.floor(length)) : 0;
|
|
2708
|
+
if (!allAlphabet || safeLength === 0) return "";
|
|
2709
|
+
let token = "";
|
|
2710
|
+
for (let i = 0; i < safeLength; i++) {
|
|
2711
|
+
token += allAlphabet[Math.floor(random() * allAlphabet.length)];
|
|
2712
|
+
}
|
|
2713
|
+
return token;
|
|
2714
|
+
}
|
|
2715
|
+
var generateRandomId = () => `id-${random().toString(36).substring(2, 12)}`;
|
|
2716
|
+
|
|
2680
2717
|
// src/index.ts
|
|
2681
2718
|
var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
2682
2719
|
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
@@ -2701,6 +2738,7 @@ exports.chunk = chunk;
|
|
|
2701
2738
|
exports.clamp = clamp;
|
|
2702
2739
|
exports.cleanObject = cleanObject;
|
|
2703
2740
|
exports.compact = compact;
|
|
2741
|
+
exports.createToken = createToken;
|
|
2704
2742
|
exports.currencyToSymbol = currencyToSymbol;
|
|
2705
2743
|
exports.debounce = debounce;
|
|
2706
2744
|
exports.deburr = deburr;
|
|
@@ -2727,6 +2765,7 @@ exports.formatCurrencyPro = formatCurrencyPro;
|
|
|
2727
2765
|
exports.formatDecimalNumber = formatDecimalNumber;
|
|
2728
2766
|
exports.generatePassword = generatePassword;
|
|
2729
2767
|
exports.generatePasswordWithOptions = generatePasswordWithOptions;
|
|
2768
|
+
exports.generateRandomId = generateRandomId;
|
|
2730
2769
|
exports.getStringSimilarity = getStringSimilarity;
|
|
2731
2770
|
exports.groupBy = groupBy;
|
|
2732
2771
|
exports.hasNilOrEmpty = hasNilOrEmpty;
|
|
@@ -2766,6 +2805,9 @@ exports.parseToNumber = parseToNumber;
|
|
|
2766
2805
|
exports.pick = pick;
|
|
2767
2806
|
exports.pluck = pluck;
|
|
2768
2807
|
exports.pushAll = pushAll;
|
|
2808
|
+
exports.randFromArray = randFromArray;
|
|
2809
|
+
exports.randIntFromInterval = randIntFromInterval;
|
|
2810
|
+
exports.random = random;
|
|
2769
2811
|
exports.randomDigits = randomDigits;
|
|
2770
2812
|
exports.removeDiacritics = removeDiacritics;
|
|
2771
2813
|
exports.round = round;
|
|
@@ -2780,6 +2822,9 @@ exports.sanitize = sanitize;
|
|
|
2780
2822
|
exports.sanitizeMarkdown = sanitizeMarkdown;
|
|
2781
2823
|
exports.sentenceCase = sentenceCase;
|
|
2782
2824
|
exports.shuffle = shuffle;
|
|
2825
|
+
exports.shuffleArray = shuffleArray;
|
|
2826
|
+
exports.shuffleArrayMutate = shuffleArrayMutate;
|
|
2827
|
+
exports.shuffleString = shuffleString;
|
|
2783
2828
|
exports.slugify = slugify;
|
|
2784
2829
|
exports.smsLength = smsLength;
|
|
2785
2830
|
exports.sortBy = sortBy;
|