@salespark/toolkit 2.1.0 → 2.1.2

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/dist/index.d.cts CHANGED
@@ -181,6 +181,24 @@ declare function flattenDepth<T = unknown>(array: readonly unknown[], depth?: nu
181
181
  isStrict?: boolean;
182
182
  }): T[];
183
183
 
184
+ /****************************************************
185
+ * ##: Boolean Parser
186
+ * Converts a value to boolean, supporting common string/number representations
187
+ *
188
+ * Notes:
189
+ * - Accepts "true", "yes", "1", "false", "no", "0" (case/whitespace-insensitive)
190
+ * - Returns default value if not recognized or on error
191
+ * @param {unknown} value - Input value (string | number | boolean | null | undefined)
192
+ * @param {Boolean} def - Default value if input cannot be parsed (default: false)
193
+ * History:
194
+ * 21-08-2025: Created
195
+ ****************************************************/
196
+ declare const toBool: (value: unknown, def?: boolean) => boolean;
197
+ /**
198
+ * @deprecated Use `toBool` instead.
199
+ */
200
+ declare const parseToBool: (value: unknown, def?: boolean) => boolean;
201
+
184
202
  /**
185
203
  ****************************************************
186
204
  * ##: Object Property Picker
@@ -340,6 +358,19 @@ declare function randomDigits(length?: number, options?: {
340
358
  * @deprecated Use `randomDigits` instead.
341
359
  */
342
360
  declare const otp: typeof randomDigits;
361
+ /******************************************************
362
+ * ##: Decimal Number Formatter
363
+ * Formats a number with specified decimal places, handling comma/dot normalization.
364
+ *
365
+ * Intelligently handles European number formats (1.234,56) and US formats (1,234.56).
366
+ * Converts strings to numbers and applies decimal formatting.
367
+ * @param {number|string|null|undefined} value Number value to format
368
+ * @param {number} decimals Number of decimal places (default: 2)
369
+ * @returns {string} Formatted number string with specified decimals
370
+ * History:
371
+ * 16-10-2025: Created
372
+ ****************************************************/
373
+ declare const formatDecimalNumber: (value: number | string | null | undefined, decimals?: number) => string;
343
374
 
344
375
  /******************************************************
345
376
  * ##: Debounce Function
@@ -663,4 +694,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
663
694
  declare const isBrowser: boolean;
664
695
  declare const isNode: boolean;
665
696
 
666
- export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toInteger, toNumber, uniq, uniqBy };
697
+ export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
package/dist/index.d.ts CHANGED
@@ -181,6 +181,24 @@ declare function flattenDepth<T = unknown>(array: readonly unknown[], depth?: nu
181
181
  isStrict?: boolean;
182
182
  }): T[];
183
183
 
184
+ /****************************************************
185
+ * ##: Boolean Parser
186
+ * Converts a value to boolean, supporting common string/number representations
187
+ *
188
+ * Notes:
189
+ * - Accepts "true", "yes", "1", "false", "no", "0" (case/whitespace-insensitive)
190
+ * - Returns default value if not recognized or on error
191
+ * @param {unknown} value - Input value (string | number | boolean | null | undefined)
192
+ * @param {Boolean} def - Default value if input cannot be parsed (default: false)
193
+ * History:
194
+ * 21-08-2025: Created
195
+ ****************************************************/
196
+ declare const toBool: (value: unknown, def?: boolean) => boolean;
197
+ /**
198
+ * @deprecated Use `toBool` instead.
199
+ */
200
+ declare const parseToBool: (value: unknown, def?: boolean) => boolean;
201
+
184
202
  /**
185
203
  ****************************************************
186
204
  * ##: Object Property Picker
@@ -340,6 +358,19 @@ declare function randomDigits(length?: number, options?: {
340
358
  * @deprecated Use `randomDigits` instead.
341
359
  */
342
360
  declare const otp: typeof randomDigits;
361
+ /******************************************************
362
+ * ##: Decimal Number Formatter
363
+ * Formats a number with specified decimal places, handling comma/dot normalization.
364
+ *
365
+ * Intelligently handles European number formats (1.234,56) and US formats (1,234.56).
366
+ * Converts strings to numbers and applies decimal formatting.
367
+ * @param {number|string|null|undefined} value Number value to format
368
+ * @param {number} decimals Number of decimal places (default: 2)
369
+ * @returns {string} Formatted number string with specified decimals
370
+ * History:
371
+ * 16-10-2025: Created
372
+ ****************************************************/
373
+ declare const formatDecimalNumber: (value: number | string | null | undefined, decimals?: number) => string;
343
374
 
344
375
  /******************************************************
345
376
  * ##: Debounce Function
@@ -663,4 +694,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
663
694
  declare const isBrowser: boolean;
664
695
  declare const isNode: boolean;
665
696
 
666
- export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toInteger, toNumber, uniq, uniqBy };
697
+ export { type SecurityCheckResult, type SecurityRisk, addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
package/dist/index.js CHANGED
@@ -133,6 +133,33 @@ function flattenDepth(array, depth = 1, options) {
133
133
  return flattenDepthBase(array, depth, predicate, isStrict);
134
134
  }
135
135
 
136
+ // src/utils/bool.ts
137
+ var toBool = (value, def = false) => {
138
+ try {
139
+ if (value === null || value === void 0) return def;
140
+ if (typeof value === "boolean") return value;
141
+ if (typeof value === "number") return value === 1;
142
+ if (typeof value === "string") {
143
+ switch (value.toLowerCase().trim()) {
144
+ case "true":
145
+ case "yes":
146
+ case "1":
147
+ return true;
148
+ case "false":
149
+ case "no":
150
+ case "0":
151
+ return false;
152
+ default:
153
+ return def;
154
+ }
155
+ }
156
+ return def;
157
+ } catch {
158
+ return false;
159
+ }
160
+ };
161
+ var parseToBool = toBool;
162
+
136
163
  // src/utils/object.ts
137
164
  function pick(obj, keys) {
138
165
  const out = {};
@@ -281,6 +308,30 @@ function randomDigits(length = 6, options) {
281
308
  return out;
282
309
  }
283
310
  var otp = randomDigits;
311
+ var formatDecimalNumber = (value, decimals = 2) => {
312
+ try {
313
+ let processedValue = value ?? 0;
314
+ if (typeof processedValue === "string") {
315
+ const trimmed = processedValue.trim();
316
+ if (trimmed.includes(",") && trimmed.includes(".")) {
317
+ const lastComma = trimmed.lastIndexOf(",");
318
+ const lastDot = trimmed.lastIndexOf(".");
319
+ processedValue = lastComma > lastDot ? trimmed.replace(/\./g, "").replace(",", ".") : trimmed.replace(/,/g, "");
320
+ } else if (trimmed.includes(",")) {
321
+ processedValue = trimmed.replace(/,/g, ".");
322
+ } else {
323
+ processedValue = trimmed;
324
+ }
325
+ }
326
+ const numValue = parseFloat(String(processedValue));
327
+ if (isNaN(numValue)) {
328
+ return 0 .toFixed(Math.max(0, Math.floor(decimals)));
329
+ }
330
+ return numValue.toFixed(Math.max(0, Math.floor(decimals)));
331
+ } catch (error) {
332
+ return 0 .toFixed(Math.max(0, Math.floor(decimals)));
333
+ }
334
+ };
284
335
 
285
336
  // src/utils/func.ts
286
337
  function debounce(fn, wait = 250) {
@@ -1563,6 +1614,6 @@ var assessSecurityRisks = (risks) => {
1563
1614
  var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
1564
1615
  var isNode = typeof process !== "undefined" && !!process.versions?.node;
1565
1616
 
1566
- export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toInteger, toNumber, uniq, uniqBy };
1617
+ export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, assessSecurityRisks, basicSanitize, checkMarkdownSecurity, chunk, clamp, cleanObject, compact, currencyToSymbol, debounce, deburr, delay, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, formatCurrency, formatDecimalNumber, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNilTextOrEmpty, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrEmptyEnforced, isNullUndefinedOrZero, isPTTaxId, isValidIBAN, isValidPTTaxId, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
1567
1618
  //# sourceMappingURL=index.js.map
1568
1619
  //# sourceMappingURL=index.js.map