@salespark/toolkit 2.1.2 → 2.1.3
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 +36 -24
- package/dist/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -12
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:
|
|
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
|
|
316
|
-
|
|
317
|
-
*
|
|
318
|
-
|
|
319
|
-
|
|
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:
|
|
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
|
|
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 `
|
|
339
|
+
* @deprecated Use `safeParseFloat` instead.
|
|
340
340
|
*/
|
|
341
|
-
declare const parseToNumber: typeof
|
|
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
|
/******************************************************
|
|
@@ -694,4 +695,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
694
695
|
declare const isBrowser: boolean;
|
|
695
696
|
declare const isNode: boolean;
|
|
696
697
|
|
|
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 };
|
|
698
|
+
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, 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:
|
|
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
|
|
316
|
-
|
|
317
|
-
*
|
|
318
|
-
|
|
319
|
-
|
|
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:
|
|
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
|
|
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 `
|
|
339
|
+
* @deprecated Use `safeParseFloat` instead.
|
|
340
340
|
*/
|
|
341
|
-
declare const parseToNumber: typeof
|
|
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
|
/******************************************************
|
|
@@ -694,4 +695,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
694
695
|
declare const isBrowser: boolean;
|
|
695
696
|
declare const isNode: boolean;
|
|
696
697
|
|
|
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 };
|
|
698
|
+
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, 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
|
|
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
|
|
263
|
-
function
|
|
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
|
|
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
|
}
|
|
@@ -1614,6 +1615,6 @@ var assessSecurityRisks = (risks) => {
|
|
|
1614
1615
|
var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
1615
1616
|
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
1616
1617
|
|
|
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 };
|
|
1618
|
+
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, safeParseFloat, safeParseInt, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
1618
1619
|
//# sourceMappingURL=index.js.map
|
|
1619
1620
|
//# sourceMappingURL=index.js.map
|