@salespark/toolkit 2.1.2 → 2.1.4

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
@@ -306,39 +306,39 @@ declare function round(n: number, decimals?: number): number;
306
306
  * Safely converts a value to an integer. Returns defaultValue if parsing fails or results in NaN.
307
307
  *
308
308
  * Notes:
309
- * Examples: toInteger("42") -> 42, toInteger("abc", 10) -> 10, toInteger(undefined) -> 0, toInteger(3.9) -> 3
309
+ * Examples: safeParseInt("42") -> 42, safeParseInt("abc", 10) -> 10, safeParseInt(undefined) -> 0, safeParseInt(3.9) -> 3
310
310
  * @param {unknown} value - Value to convert
311
311
  * @param {Number} defaultValue - Default value if parsing fails
312
312
  * History:
313
313
  * 21-08-2025: Created
314
+ * 29-10-2025: Renamed from toInteger to safeParseInt
314
315
  ****************************************************/
315
- declare function toInteger(value: unknown, defaultValue?: number): number;
316
- /******************************************************
317
- * ##: Safe Parse Int (Alias)
318
- * Alias for safe integer conversion (for discoverability/backward naming)
319
- * @param {unknown} value - Value to convert
320
- * @param {Number} defaultValue - Default value if parsing fails
321
- * History:
322
- * 21-08-2025: Created
323
- ****************************************************/
324
- declare const safeParseInt: typeof toInteger;
316
+ declare function safeParseInt(value: unknown, defaultValue?: number): number;
317
+ /**
318
+ * @deprecated Use `safeParseFloat` instead.
319
+ */
320
+ declare const toInteger: typeof safeParseInt;
325
321
  /******************************************************
326
322
  * ##: Safe Number Conversion
327
323
  * Safely parses a value into a number with optional decimal precision
328
324
  *
329
325
  * Notes:
330
326
  * Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
331
- * Examples: toNumber("123.45") -> 123.45, toNumber("123,45") -> 123.45, toNumber("1,234.56") -> 1234.56, toNumber("abc", 2) -> 0, toNumber(42) -> 42
332
- * @param {unknown} value - Value to convert
327
+ * Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42 * @param {unknown} value - Value to convert
333
328
  * @param {Number} decimals - Number of decimal places
334
329
  * History:
335
330
  * 21-08-2025: Created
331
+ * * 29-10-2025: Renamed from toNumber to safeParseFloat
336
332
  ****************************************************/
337
- declare function toNumber(value: unknown, decimals?: number): number;
333
+ declare function safeParseFloat(value: unknown, decimals?: number): number;
334
+ /**
335
+ * @deprecated Use `safeParseFloat` instead.
336
+ */
337
+ declare const toNumber: typeof safeParseFloat;
338
338
  /**
339
- * @deprecated Use `toNumber` instead.
339
+ * @deprecated Use `safeParseFloat` instead.
340
340
  */
341
- declare const parseToNumber: typeof toNumber;
341
+ declare const parseToNumber: typeof safeParseFloat;
342
342
  /******************************************************
343
343
  * ##: Random Digits Generator
344
344
  * Generates a random string of digits with secure randomness when available
@@ -412,6 +412,7 @@ declare const isNilText: (value: unknown) => boolean;
412
412
  * @param {unknown} value - Value to check
413
413
  * History:
414
414
  * 21-08-2025: Created
415
+ * 18-10-2025: Trim before checking empty
415
416
  ****************************************************/
416
417
  declare const isNilOrEmpty: (value: unknown) => boolean;
417
418
  /******************************************************
@@ -428,7 +429,14 @@ declare const hasNilOrEmpty: (array: unknown) => boolean;
428
429
  * @param {unknown} value - Value to check
429
430
  * History:
430
431
  * 21-08-2025: Created
432
+ * 08-11-2025: Fixed type-safety and logic - added proper 'length' property check using 'in' operator,
433
+ * changed catch block to return false (don't assume error means empty), added explicit
434
+ * false return for values without length property
431
435
  ****************************************************/
436
+ declare const isNilEmptyOrZeroLength: (value: unknown) => boolean;
437
+ /**
438
+ * @deprecated Use `isNilEmptyOrZeroLength` instead.
439
+ */
432
440
  declare const isNilEmptyOrZeroLen: (value: unknown) => boolean;
433
441
  /******************************************************
434
442
  * ##: Nil or Zero Length Check
@@ -436,7 +444,14 @@ declare const isNilEmptyOrZeroLen: (value: unknown) => boolean;
436
444
  * @param {unknown} value - Value to check
437
445
  * History:
438
446
  * 21-08-2025: Created
447
+ * 08-11-2025: Fixed type-safety and logic - added proper 'length' property check using 'in' operator,
448
+ * changed catch block to return false (don't assume error means empty), added explicit
449
+ * false return for values without length property
439
450
  ****************************************************/
451
+ declare const isNilOrZeroLength: (value: unknown) => boolean;
452
+ /**
453
+ * @deprecated Use `isNilOrZeroLength` instead.
454
+ */
440
455
  declare const isNilOrZeroLen: (value: unknown) => boolean;
441
456
  /******************************************************
442
457
  * ##: Nil or NaN Check
@@ -694,4 +709,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
694
709
  declare const isBrowser: boolean;
695
710
  declare const isNode: boolean;
696
711
 
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 };
712
+ 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, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, 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, safeParseFloat, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
package/dist/index.d.ts CHANGED
@@ -306,39 +306,39 @@ declare function round(n: number, decimals?: number): number;
306
306
  * Safely converts a value to an integer. Returns defaultValue if parsing fails or results in NaN.
307
307
  *
308
308
  * Notes:
309
- * Examples: toInteger("42") -> 42, toInteger("abc", 10) -> 10, toInteger(undefined) -> 0, toInteger(3.9) -> 3
309
+ * Examples: safeParseInt("42") -> 42, safeParseInt("abc", 10) -> 10, safeParseInt(undefined) -> 0, safeParseInt(3.9) -> 3
310
310
  * @param {unknown} value - Value to convert
311
311
  * @param {Number} defaultValue - Default value if parsing fails
312
312
  * History:
313
313
  * 21-08-2025: Created
314
+ * 29-10-2025: Renamed from toInteger to safeParseInt
314
315
  ****************************************************/
315
- declare function toInteger(value: unknown, defaultValue?: number): number;
316
- /******************************************************
317
- * ##: Safe Parse Int (Alias)
318
- * Alias for safe integer conversion (for discoverability/backward naming)
319
- * @param {unknown} value - Value to convert
320
- * @param {Number} defaultValue - Default value if parsing fails
321
- * History:
322
- * 21-08-2025: Created
323
- ****************************************************/
324
- declare const safeParseInt: typeof toInteger;
316
+ declare function safeParseInt(value: unknown, defaultValue?: number): number;
317
+ /**
318
+ * @deprecated Use `safeParseFloat` instead.
319
+ */
320
+ declare const toInteger: typeof safeParseInt;
325
321
  /******************************************************
326
322
  * ##: Safe Number Conversion
327
323
  * Safely parses a value into a number with optional decimal precision
328
324
  *
329
325
  * Notes:
330
326
  * Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
331
- * Examples: toNumber("123.45") -> 123.45, toNumber("123,45") -> 123.45, toNumber("1,234.56") -> 1234.56, toNumber("abc", 2) -> 0, toNumber(42) -> 42
332
- * @param {unknown} value - Value to convert
327
+ * Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42 * @param {unknown} value - Value to convert
333
328
  * @param {Number} decimals - Number of decimal places
334
329
  * History:
335
330
  * 21-08-2025: Created
331
+ * * 29-10-2025: Renamed from toNumber to safeParseFloat
336
332
  ****************************************************/
337
- declare function toNumber(value: unknown, decimals?: number): number;
333
+ declare function safeParseFloat(value: unknown, decimals?: number): number;
334
+ /**
335
+ * @deprecated Use `safeParseFloat` instead.
336
+ */
337
+ declare const toNumber: typeof safeParseFloat;
338
338
  /**
339
- * @deprecated Use `toNumber` instead.
339
+ * @deprecated Use `safeParseFloat` instead.
340
340
  */
341
- declare const parseToNumber: typeof toNumber;
341
+ declare const parseToNumber: typeof safeParseFloat;
342
342
  /******************************************************
343
343
  * ##: Random Digits Generator
344
344
  * Generates a random string of digits with secure randomness when available
@@ -412,6 +412,7 @@ declare const isNilText: (value: unknown) => boolean;
412
412
  * @param {unknown} value - Value to check
413
413
  * History:
414
414
  * 21-08-2025: Created
415
+ * 18-10-2025: Trim before checking empty
415
416
  ****************************************************/
416
417
  declare const isNilOrEmpty: (value: unknown) => boolean;
417
418
  /******************************************************
@@ -428,7 +429,14 @@ declare const hasNilOrEmpty: (array: unknown) => boolean;
428
429
  * @param {unknown} value - Value to check
429
430
  * History:
430
431
  * 21-08-2025: Created
432
+ * 08-11-2025: Fixed type-safety and logic - added proper 'length' property check using 'in' operator,
433
+ * changed catch block to return false (don't assume error means empty), added explicit
434
+ * false return for values without length property
431
435
  ****************************************************/
436
+ declare const isNilEmptyOrZeroLength: (value: unknown) => boolean;
437
+ /**
438
+ * @deprecated Use `isNilEmptyOrZeroLength` instead.
439
+ */
432
440
  declare const isNilEmptyOrZeroLen: (value: unknown) => boolean;
433
441
  /******************************************************
434
442
  * ##: Nil or Zero Length Check
@@ -436,7 +444,14 @@ declare const isNilEmptyOrZeroLen: (value: unknown) => boolean;
436
444
  * @param {unknown} value - Value to check
437
445
  * History:
438
446
  * 21-08-2025: Created
447
+ * 08-11-2025: Fixed type-safety and logic - added proper 'length' property check using 'in' operator,
448
+ * changed catch block to return false (don't assume error means empty), added explicit
449
+ * false return for values without length property
439
450
  ****************************************************/
451
+ declare const isNilOrZeroLength: (value: unknown) => boolean;
452
+ /**
453
+ * @deprecated Use `isNilOrZeroLength` instead.
454
+ */
440
455
  declare const isNilOrZeroLen: (value: unknown) => boolean;
441
456
  /******************************************************
442
457
  * ##: Nil or NaN Check
@@ -694,4 +709,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
694
709
  declare const isBrowser: boolean;
695
710
  declare const isNode: boolean;
696
711
 
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 };
712
+ 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, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, 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, safeParseFloat, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
package/dist/index.js CHANGED
@@ -251,7 +251,7 @@ function round(n, decimals = 0) {
251
251
  const f = Math.pow(10, decimals);
252
252
  return Math.round((n + Number.EPSILON) * f) / f;
253
253
  }
254
- function toInteger(value, defaultValue = 0) {
254
+ function safeParseInt(value, defaultValue = 0) {
255
255
  try {
256
256
  const safeValue = parseInt(String(value), 10);
257
257
  return isNaN(safeValue) ? defaultValue : safeValue;
@@ -259,8 +259,8 @@ function toInteger(value, defaultValue = 0) {
259
259
  return defaultValue;
260
260
  }
261
261
  }
262
- var safeParseInt = toInteger;
263
- function toNumber(value, decimals = 6) {
262
+ var toInteger = safeParseInt;
263
+ function safeParseFloat(value, decimals = 6) {
264
264
  try {
265
265
  if (value === void 0 || value === null || value === "") return 0;
266
266
  let str = String(value);
@@ -276,7 +276,8 @@ function toNumber(value, decimals = 6) {
276
276
  return 0;
277
277
  }
278
278
  }
279
- var parseToNumber = toNumber;
279
+ var toNumber = safeParseFloat;
280
+ var parseToNumber = safeParseFloat;
280
281
  function secureRandomIndex(max) {
281
282
  if (max <= 0) return 0;
282
283
  const g = globalThis;
@@ -370,7 +371,7 @@ var isNilText = (value) => {
370
371
  };
371
372
  var isNilOrEmpty = (value) => {
372
373
  try {
373
- return isNil(value) || value === "";
374
+ return isNil(value) || typeof value === "string" && value?.trim() === "";
374
375
  } catch {
375
376
  return true;
376
377
  }
@@ -386,24 +387,32 @@ var hasNilOrEmpty = (array) => {
386
387
  return true;
387
388
  }
388
389
  };
389
- var isNilEmptyOrZeroLen = (value) => {
390
+ var isNilEmptyOrZeroLength = (value) => {
390
391
  try {
391
392
  if (isNil(value) || value === "") return true;
392
- const maybeLen = value?.length;
393
- return typeof maybeLen === "number" && maybeLen === 0;
393
+ if (typeof value === "object" && value !== null && "length" in value) {
394
+ const length = value.length;
395
+ return typeof length === "number" && length === 0;
396
+ }
397
+ return false;
394
398
  } catch {
395
399
  return true;
396
400
  }
397
401
  };
398
- var isNilOrZeroLen = (value) => {
402
+ var isNilEmptyOrZeroLen = isNilEmptyOrZeroLength;
403
+ var isNilOrZeroLength = (value) => {
399
404
  try {
400
405
  if (isNil(value)) return true;
401
- const maybeLen = value?.length;
402
- return typeof maybeLen === "number" && maybeLen === 0;
406
+ if (typeof value === "object" && value !== null && "length" in value) {
407
+ const length = value.length;
408
+ return typeof length === "number" && length === 0;
409
+ }
410
+ return false;
403
411
  } catch {
404
412
  return true;
405
413
  }
406
414
  };
415
+ var isNilOrZeroLen = isNilOrZeroLength;
407
416
  var isNilOrNaN = (value) => {
408
417
  try {
409
418
  return isNil(value) || isNaN(value);
@@ -1614,6 +1623,6 @@ var assessSecurityRisks = (risks) => {
1614
1623
  var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
1615
1624
  var isNode = typeof process !== "undefined" && !!process.versions?.node;
1616
1625
 
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 };
1626
+ 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, isNilEmptyOrZeroLength, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilOrZeroLength, 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, safeParseFloat, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
1618
1627
  //# sourceMappingURL=index.js.map
1619
1628
  //# sourceMappingURL=index.js.map