@salespark/toolkit 2.1.20 → 2.1.22

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 CHANGED
@@ -26,7 +26,7 @@ npm i @salespark/toolkit
26
26
 
27
27
  - **Array utilities**: chunk, uniqBy, deep equality, flatten, groupBy, etc.
28
28
  - **Object utilities**: pick, omit, clean objects, deep merge, etc.
29
- - **String utilities**: slugify, template fill, deburr, sanitize, capitalize words/sentences.
29
+ - **String utilities**: slugify, template fill, deburr, sanitize, capitalize words/sentences, SMS length.
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
32
  - **Defer utilities**: post-return microtask scheduling, non-critical timers, after-response hooks.
@@ -54,6 +54,7 @@ import {
54
54
  isBrowser,
55
55
  toBool,
56
56
  generatePassword,
57
+ smsLength,
57
58
  uuidv4,
58
59
  } from "@salespark/toolkit";
59
60
 
@@ -80,6 +81,9 @@ const bool = toBool("yes"); // true
80
81
  // Generate a password (sync by default)
81
82
  const recoveryToken = generatePassword(96, false);
82
83
 
84
+ // SMS length and segmentation
85
+ const sms = smsLength("hello");
86
+
83
87
  // Generate UUID v4
84
88
  const id = uuidv4();
85
89
 
@@ -361,6 +365,16 @@ sanitize("<script>alert('hack')</script>Hello World!", 20);
361
365
  // Result: "Hello World!"
362
366
  ```
363
367
 
368
+ **`smsLength(text: string, singleOverrides?, multiOverrides?): SmsLengthResult`** — Calculates SMS encoding, length, and segmentation details (overrides are optional).
369
+
370
+ ```javascript
371
+ const sms = smsLength("hello");
372
+ // Result: { encoding: "GSM_7BIT", length: 5, messages: 1, remaining: 155, ... }
373
+
374
+ const custom = smsLength("hello", { GSM_7BIT: 10 }, { GSM_7BIT: 5 });
375
+ // Result: characterPerMessage uses overrides
376
+ ```
377
+
364
378
  ### 🔢 Number Utilities
365
379
 
366
380
  **`clamp(n: number, min: number, max: number): number`** — Restricts a number to be within the min and max bounds.
@@ -869,9 +883,16 @@ assessSecurityRisks([]);
869
883
  ```typescript
870
884
  import { generatePassword } from "@salespark/toolkit";
871
885
 
872
- // Sync usage (current default behavior)
886
+ // Sync usage (positional signature skips security recommendations)
873
887
  const recoveryToken = generatePassword(96, false);
874
888
 
889
+ // Enforce security recommendations by using options
890
+ const strict = generatePassword({
891
+ length: 12,
892
+ memorable: true,
893
+ ignoreSecurityRecommendations: false,
894
+ });
895
+
875
896
  // Memorable password (override security recommendations if needed)
876
897
  const memorable = generatePassword({
877
898
  length: 12,
@@ -1093,5 +1114,5 @@ MIT © [SalesPark](https://salespark.io)
1093
1114
 
1094
1115
  ---
1095
1116
 
1096
- _Document version: 17_
1117
+ _Document version: 18_
1097
1118
  _Last update: 14-03-2026_
package/dist/index.cjs CHANGED
@@ -2613,6 +2613,7 @@ function generatePassword(lengthOrOptions, memorable, pattern, prefix) {
2613
2613
  if (memorable !== void 0) options.memorable = memorable;
2614
2614
  if (pattern !== void 0) options.pattern = pattern;
2615
2615
  if (prefix !== void 0) options.prefix = prefix;
2616
+ options.ignoreSecurityRecommendations = true;
2616
2617
  return generatePasswordSync(options);
2617
2618
  }
2618
2619
  var generatePasswordWithOptions = (options) => {
@@ -2620,6 +2621,62 @@ var generatePasswordWithOptions = (options) => {
2620
2621
  return requiresAsync ? generatePasswordAsync(options) : generatePasswordSync(options);
2621
2622
  };
2622
2623
 
2624
+ // src/utils/sms.ts
2625
+ var GSM_7BIT_REGEXP = /^[@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'()*+,\-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà]*$/;
2626
+ var GSM_7BIT_EXT_REGEXP = /^[@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'()*+,\-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà\^{}\\\[\]~|€]*$/;
2627
+ var GSM_7BIT_EXT_CHAR_REGEXP = /[\^{}\\\[\]~|€]/g;
2628
+ var messageLength = {
2629
+ GSM_7BIT: 160,
2630
+ GSM_7BIT_EXT: 160,
2631
+ UTF16: 70
2632
+ };
2633
+ var multiMessageLength = {
2634
+ GSM_7BIT: 153,
2635
+ GSM_7BIT_EXT: 153,
2636
+ UTF16: 67
2637
+ };
2638
+ var detectEncoding = (text) => {
2639
+ if (GSM_7BIT_REGEXP.test(text)) {
2640
+ return "GSM_7BIT";
2641
+ }
2642
+ if (GSM_7BIT_EXT_REGEXP.test(text)) {
2643
+ return "GSM_7BIT_EXT";
2644
+ }
2645
+ return "UTF16";
2646
+ };
2647
+ var smsLength = (text, singleOverrides, multiOverrides) => {
2648
+ const singleLengths = { ...messageLength, ...singleOverrides };
2649
+ const multiLengths = { ...multiMessageLength, ...multiOverrides };
2650
+ if (text.length === 0) {
2651
+ return {
2652
+ encoding: "GSM_7BIT",
2653
+ length: 0,
2654
+ characterPerMessage: singleLengths.GSM_7BIT,
2655
+ inCurrentMessage: 0,
2656
+ remaining: singleLengths.GSM_7BIT,
2657
+ messages: 0
2658
+ };
2659
+ }
2660
+ const encoding = detectEncoding(text);
2661
+ const extCharCount = encoding === "GSM_7BIT_EXT" ? (text.match(GSM_7BIT_EXT_CHAR_REGEXP) ?? []).length : 0;
2662
+ const length = text.length + extCharCount;
2663
+ let characterPerMessage = singleLengths[encoding];
2664
+ if (length > characterPerMessage) {
2665
+ characterPerMessage = multiLengths[encoding];
2666
+ }
2667
+ const messages = Math.ceil(length / characterPerMessage);
2668
+ const inCurrentMessage = length - characterPerMessage * (messages - 1);
2669
+ const remaining = characterPerMessage * messages - length;
2670
+ return {
2671
+ encoding,
2672
+ length,
2673
+ characterPerMessage,
2674
+ inCurrentMessage,
2675
+ remaining,
2676
+ messages
2677
+ };
2678
+ };
2679
+
2623
2680
  // src/index.ts
2624
2681
  var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
2625
2682
  var isNode = typeof process !== "undefined" && !!process.versions?.node;
@@ -2628,6 +2685,9 @@ Object.defineProperty(exports, "uuidv4", {
2628
2685
  enumerable: true,
2629
2686
  get: function () { return uuid.v4; }
2630
2687
  });
2688
+ exports.GSM_7BIT_EXT_CHAR_REGEXP = GSM_7BIT_EXT_CHAR_REGEXP;
2689
+ exports.GSM_7BIT_EXT_REGEXP = GSM_7BIT_EXT_REGEXP;
2690
+ exports.GSM_7BIT_REGEXP = GSM_7BIT_REGEXP;
2631
2691
  exports.addSpaceBetweenNumbers = addSpaceBetweenNumbers;
2632
2692
  exports.addThousandsSpace = addThousandsSpace;
2633
2693
  exports.areArraysDeepEqualUnordered = areArraysDeepEqualUnordered;
@@ -2721,6 +2781,7 @@ exports.sanitizeMarkdown = sanitizeMarkdown;
2721
2781
  exports.sentenceCase = sentenceCase;
2722
2782
  exports.shuffle = shuffle;
2723
2783
  exports.slugify = slugify;
2784
+ exports.smsLength = smsLength;
2724
2785
  exports.sortBy = sortBy;
2725
2786
  exports.stringSimilarity = stringSimilarity;
2726
2787
  exports.symbolToCurrency = symbolToCurrency;