@salespark/toolkit 2.1.5 → 2.1.7
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 +43 -4
- package/dist/index.cjs +86 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -13
- package/dist/index.d.ts +85 -13
- package/dist/index.js +82 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -285,9 +285,9 @@ declare const basicSanitize: typeof sanitize;
|
|
|
285
285
|
/******************************************************
|
|
286
286
|
* ##: Clamp Number
|
|
287
287
|
* Restricts a number to be within the min and max bounds
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {
|
|
290
|
-
* @param {
|
|
288
|
+
* @param {number} n - Number to clamp
|
|
289
|
+
* @param {number} min - Minimum value
|
|
290
|
+
* @param {number} max - Maximum value
|
|
291
291
|
* History:
|
|
292
292
|
* 21-08-2025: Created
|
|
293
293
|
****************************************************/
|
|
@@ -295,8 +295,8 @@ declare const clamp: (n: number, min: number, max: number) => number;
|
|
|
295
295
|
/******************************************************
|
|
296
296
|
* ##: Fixed Decimal Rounding
|
|
297
297
|
* Rounds a number to a fixed number of decimals without floating point surprises
|
|
298
|
-
* @param {
|
|
299
|
-
* @param {
|
|
298
|
+
* @param {number} n - Number to round
|
|
299
|
+
* @param {number} decimals - Number of decimal places
|
|
300
300
|
* History:
|
|
301
301
|
* 21-08-2025: Created
|
|
302
302
|
****************************************************/
|
|
@@ -308,12 +308,82 @@ declare function round(n: number, decimals?: number): number;
|
|
|
308
308
|
* Notes:
|
|
309
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
|
-
* @param {
|
|
311
|
+
* @param {number} defaultValue - Default value if parsing fails
|
|
312
312
|
* History:
|
|
313
313
|
* 21-08-2025: Created
|
|
314
314
|
* 29-10-2025: Renamed from toInteger to safeParseInt
|
|
315
315
|
****************************************************/
|
|
316
316
|
declare function safeParseInt(value: unknown, defaultValue?: number): number;
|
|
317
|
+
/******************************************************
|
|
318
|
+
* ##: Safe Addition
|
|
319
|
+
* Adds two numbers with precision normalization and operand validation.
|
|
320
|
+
*
|
|
321
|
+
* Notes:
|
|
322
|
+
* Returns 0 when operands are invalid or if toFixed throws.
|
|
323
|
+
* Examples: safeAdd(0.1, 0.2, 2) -> 0.3, safeAdd(NaN, 5) -> 0
|
|
324
|
+
* @param {number} a - Augend
|
|
325
|
+
* @param {number} b - Addend
|
|
326
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
327
|
+
* History:
|
|
328
|
+
* 01-12-2025: Created
|
|
329
|
+
****************************************************/
|
|
330
|
+
declare function safeAdd(a: number, b: number, decimals?: number): number;
|
|
331
|
+
/******************************************************
|
|
332
|
+
* ##: Safe Multiplication
|
|
333
|
+
* Multiplies two numbers with precision normalization and operand validation.
|
|
334
|
+
*
|
|
335
|
+
* Notes:
|
|
336
|
+
* Returns 0 when operands are invalid or on computation errors.
|
|
337
|
+
* Examples: safeMultiply(0.1, 0.2, 4) -> 0.02, safeMultiply(Infinity, 2) -> 0
|
|
338
|
+
* @param {number} a - First factor
|
|
339
|
+
* @param {number} b - Second factor
|
|
340
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
341
|
+
* History:
|
|
342
|
+
* 01-12-2025: Created
|
|
343
|
+
****************************************************/
|
|
344
|
+
declare function safeMultiply(a: number, b: number, decimals?: number): number;
|
|
345
|
+
/******************************************************
|
|
346
|
+
* ##: Safe Subtraction
|
|
347
|
+
* Subtracts two numbers with precision normalization and operand validation.
|
|
348
|
+
*
|
|
349
|
+
* Notes:
|
|
350
|
+
* Returns 0 when operands are invalid or on computation errors.
|
|
351
|
+
* Examples: safeSubtract(10, 3.3333, 2) -> 6.67, safeSubtract(5, NaN) -> 0
|
|
352
|
+
* @param {number} a - Minuend
|
|
353
|
+
* @param {number} b - Subtrahend
|
|
354
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
355
|
+
* History:
|
|
356
|
+
* 01-12-2025: Created
|
|
357
|
+
****************************************************/
|
|
358
|
+
declare function safeSubtract(a: number, b: number, decimals?: number): number;
|
|
359
|
+
/******************************************************
|
|
360
|
+
* ##: Safe Division
|
|
361
|
+
* Divides two numbers with precision normalization, operand validation, and zero checks.
|
|
362
|
+
*
|
|
363
|
+
* Notes:
|
|
364
|
+
* Returns 0 when operands are invalid or divisor is zero.
|
|
365
|
+
* Examples: safeDivide(1, 3, 3) -> 0.333, safeDivide(10, 0) -> 0
|
|
366
|
+
* @param {number} a - Dividend
|
|
367
|
+
* @param {number} b - Divisor
|
|
368
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
369
|
+
* History:
|
|
370
|
+
* 01-12-2025: Created
|
|
371
|
+
****************************************************/
|
|
372
|
+
declare function safeDivide(a: number, b: number, decimals?: number): number;
|
|
373
|
+
/******************************************************
|
|
374
|
+
* ##: Safe Number Comparison
|
|
375
|
+
* Compares two numbers using fixed decimal precision with operand validation.
|
|
376
|
+
*
|
|
377
|
+
* Notes:
|
|
378
|
+
* Returns false when operands are invalid.
|
|
379
|
+
* Examples: numbersEqual(0.1 + 0.2, 0.3) -> true, numbersEqual(NaN, 1) -> false
|
|
380
|
+
* @param {number} a - First number
|
|
381
|
+
* @param {number} b - Second number
|
|
382
|
+
* @param {number} decimals - Decimal places for comparison (default 2)
|
|
383
|
+
* History:
|
|
384
|
+
* 01-12-2025: Created
|
|
385
|
+
****************************************************/
|
|
386
|
+
declare function numbersEqual(a: number, b: number, decimals?: number): boolean;
|
|
317
387
|
/**
|
|
318
388
|
* @deprecated Use `safeParseFloat` instead.
|
|
319
389
|
*/
|
|
@@ -324,11 +394,13 @@ declare const toInteger: typeof safeParseInt;
|
|
|
324
394
|
*
|
|
325
395
|
* Notes:
|
|
326
396
|
* Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
|
|
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
|
|
328
|
-
* @param {
|
|
397
|
+
* Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42
|
|
398
|
+
* @param {unknown} value - Value to convert
|
|
399
|
+
* @param {number} decimals - Number of decimal places
|
|
329
400
|
* History:
|
|
330
401
|
* 21-08-2025: Created
|
|
331
|
-
*
|
|
402
|
+
* 29-10-2025: Renamed from toNumber to safeParseFloat
|
|
403
|
+
* 01-12-2025: Fixed space-separated thousands handling and improved number parsing logic
|
|
332
404
|
****************************************************/
|
|
333
405
|
declare function safeParseFloat(value: unknown, decimals?: number): number;
|
|
334
406
|
/**
|
|
@@ -345,8 +417,8 @@ declare const parseToNumber: typeof safeParseFloat;
|
|
|
345
417
|
*
|
|
346
418
|
* Notes:
|
|
347
419
|
* Options: length (default 6), charset (default "0123456789"), noLeadingZero (if true, first char not "0"). Returns a string to preserve leading zeros. Uses Web Crypto when possible; otherwise falls back to Math.random().
|
|
348
|
-
* @param {
|
|
349
|
-
* @param {
|
|
420
|
+
* @param {number} length - Number of digits
|
|
421
|
+
* @param {object} options - Options: charset, noLeadingZero
|
|
350
422
|
* History:
|
|
351
423
|
* 21-08-2025: Created
|
|
352
424
|
****************************************************/
|
|
@@ -365,7 +437,7 @@ declare const otp: typeof randomDigits;
|
|
|
365
437
|
* Intelligently handles European number formats (1.234,56) and US formats (1,234.56).
|
|
366
438
|
* Converts strings to numbers and applies decimal formatting.
|
|
367
439
|
* @param {number|string|null|undefined} value Number value to format
|
|
368
|
-
* @param {number} decimals Number of decimal places (default: 2)
|
|
440
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
369
441
|
* @returns {string} Formatted number string with specified decimals
|
|
370
442
|
* History:
|
|
371
443
|
* 16-10-2025: Created
|
|
@@ -709,4 +781,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
709
781
|
declare const isBrowser: boolean;
|
|
710
782
|
declare const isNode: boolean;
|
|
711
783
|
|
|
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 };
|
|
784
|
+
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, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.d.ts
CHANGED
|
@@ -285,9 +285,9 @@ declare const basicSanitize: typeof sanitize;
|
|
|
285
285
|
/******************************************************
|
|
286
286
|
* ##: Clamp Number
|
|
287
287
|
* Restricts a number to be within the min and max bounds
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {
|
|
290
|
-
* @param {
|
|
288
|
+
* @param {number} n - Number to clamp
|
|
289
|
+
* @param {number} min - Minimum value
|
|
290
|
+
* @param {number} max - Maximum value
|
|
291
291
|
* History:
|
|
292
292
|
* 21-08-2025: Created
|
|
293
293
|
****************************************************/
|
|
@@ -295,8 +295,8 @@ declare const clamp: (n: number, min: number, max: number) => number;
|
|
|
295
295
|
/******************************************************
|
|
296
296
|
* ##: Fixed Decimal Rounding
|
|
297
297
|
* Rounds a number to a fixed number of decimals without floating point surprises
|
|
298
|
-
* @param {
|
|
299
|
-
* @param {
|
|
298
|
+
* @param {number} n - Number to round
|
|
299
|
+
* @param {number} decimals - Number of decimal places
|
|
300
300
|
* History:
|
|
301
301
|
* 21-08-2025: Created
|
|
302
302
|
****************************************************/
|
|
@@ -308,12 +308,82 @@ declare function round(n: number, decimals?: number): number;
|
|
|
308
308
|
* Notes:
|
|
309
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
|
-
* @param {
|
|
311
|
+
* @param {number} defaultValue - Default value if parsing fails
|
|
312
312
|
* History:
|
|
313
313
|
* 21-08-2025: Created
|
|
314
314
|
* 29-10-2025: Renamed from toInteger to safeParseInt
|
|
315
315
|
****************************************************/
|
|
316
316
|
declare function safeParseInt(value: unknown, defaultValue?: number): number;
|
|
317
|
+
/******************************************************
|
|
318
|
+
* ##: Safe Addition
|
|
319
|
+
* Adds two numbers with precision normalization and operand validation.
|
|
320
|
+
*
|
|
321
|
+
* Notes:
|
|
322
|
+
* Returns 0 when operands are invalid or if toFixed throws.
|
|
323
|
+
* Examples: safeAdd(0.1, 0.2, 2) -> 0.3, safeAdd(NaN, 5) -> 0
|
|
324
|
+
* @param {number} a - Augend
|
|
325
|
+
* @param {number} b - Addend
|
|
326
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
327
|
+
* History:
|
|
328
|
+
* 01-12-2025: Created
|
|
329
|
+
****************************************************/
|
|
330
|
+
declare function safeAdd(a: number, b: number, decimals?: number): number;
|
|
331
|
+
/******************************************************
|
|
332
|
+
* ##: Safe Multiplication
|
|
333
|
+
* Multiplies two numbers with precision normalization and operand validation.
|
|
334
|
+
*
|
|
335
|
+
* Notes:
|
|
336
|
+
* Returns 0 when operands are invalid or on computation errors.
|
|
337
|
+
* Examples: safeMultiply(0.1, 0.2, 4) -> 0.02, safeMultiply(Infinity, 2) -> 0
|
|
338
|
+
* @param {number} a - First factor
|
|
339
|
+
* @param {number} b - Second factor
|
|
340
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
341
|
+
* History:
|
|
342
|
+
* 01-12-2025: Created
|
|
343
|
+
****************************************************/
|
|
344
|
+
declare function safeMultiply(a: number, b: number, decimals?: number): number;
|
|
345
|
+
/******************************************************
|
|
346
|
+
* ##: Safe Subtraction
|
|
347
|
+
* Subtracts two numbers with precision normalization and operand validation.
|
|
348
|
+
*
|
|
349
|
+
* Notes:
|
|
350
|
+
* Returns 0 when operands are invalid or on computation errors.
|
|
351
|
+
* Examples: safeSubtract(10, 3.3333, 2) -> 6.67, safeSubtract(5, NaN) -> 0
|
|
352
|
+
* @param {number} a - Minuend
|
|
353
|
+
* @param {number} b - Subtrahend
|
|
354
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
355
|
+
* History:
|
|
356
|
+
* 01-12-2025: Created
|
|
357
|
+
****************************************************/
|
|
358
|
+
declare function safeSubtract(a: number, b: number, decimals?: number): number;
|
|
359
|
+
/******************************************************
|
|
360
|
+
* ##: Safe Division
|
|
361
|
+
* Divides two numbers with precision normalization, operand validation, and zero checks.
|
|
362
|
+
*
|
|
363
|
+
* Notes:
|
|
364
|
+
* Returns 0 when operands are invalid or divisor is zero.
|
|
365
|
+
* Examples: safeDivide(1, 3, 3) -> 0.333, safeDivide(10, 0) -> 0
|
|
366
|
+
* @param {number} a - Dividend
|
|
367
|
+
* @param {number} b - Divisor
|
|
368
|
+
* @param {number} decimals - Decimal places for rounding (default 2)
|
|
369
|
+
* History:
|
|
370
|
+
* 01-12-2025: Created
|
|
371
|
+
****************************************************/
|
|
372
|
+
declare function safeDivide(a: number, b: number, decimals?: number): number;
|
|
373
|
+
/******************************************************
|
|
374
|
+
* ##: Safe Number Comparison
|
|
375
|
+
* Compares two numbers using fixed decimal precision with operand validation.
|
|
376
|
+
*
|
|
377
|
+
* Notes:
|
|
378
|
+
* Returns false when operands are invalid.
|
|
379
|
+
* Examples: numbersEqual(0.1 + 0.2, 0.3) -> true, numbersEqual(NaN, 1) -> false
|
|
380
|
+
* @param {number} a - First number
|
|
381
|
+
* @param {number} b - Second number
|
|
382
|
+
* @param {number} decimals - Decimal places for comparison (default 2)
|
|
383
|
+
* History:
|
|
384
|
+
* 01-12-2025: Created
|
|
385
|
+
****************************************************/
|
|
386
|
+
declare function numbersEqual(a: number, b: number, decimals?: number): boolean;
|
|
317
387
|
/**
|
|
318
388
|
* @deprecated Use `safeParseFloat` instead.
|
|
319
389
|
*/
|
|
@@ -324,11 +394,13 @@ declare const toInteger: typeof safeParseInt;
|
|
|
324
394
|
*
|
|
325
395
|
* Notes:
|
|
326
396
|
* Handles commas as decimal/thousands separators. Returns 0 for null/undefined/empty string or invalid parsing.
|
|
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
|
|
328
|
-
* @param {
|
|
397
|
+
* Examples: safeParseFloat("123.45") -> 123.45, safeParseFloat("123,45") -> 123.45, safeParseFloat("1,234.56") -> 1234.56, safeParseFloat("abc", 2) -> 0, safeParseFloat(42) -> 42
|
|
398
|
+
* @param {unknown} value - Value to convert
|
|
399
|
+
* @param {number} decimals - Number of decimal places
|
|
329
400
|
* History:
|
|
330
401
|
* 21-08-2025: Created
|
|
331
|
-
*
|
|
402
|
+
* 29-10-2025: Renamed from toNumber to safeParseFloat
|
|
403
|
+
* 01-12-2025: Fixed space-separated thousands handling and improved number parsing logic
|
|
332
404
|
****************************************************/
|
|
333
405
|
declare function safeParseFloat(value: unknown, decimals?: number): number;
|
|
334
406
|
/**
|
|
@@ -345,8 +417,8 @@ declare const parseToNumber: typeof safeParseFloat;
|
|
|
345
417
|
*
|
|
346
418
|
* Notes:
|
|
347
419
|
* Options: length (default 6), charset (default "0123456789"), noLeadingZero (if true, first char not "0"). Returns a string to preserve leading zeros. Uses Web Crypto when possible; otherwise falls back to Math.random().
|
|
348
|
-
* @param {
|
|
349
|
-
* @param {
|
|
420
|
+
* @param {number} length - Number of digits
|
|
421
|
+
* @param {object} options - Options: charset, noLeadingZero
|
|
350
422
|
* History:
|
|
351
423
|
* 21-08-2025: Created
|
|
352
424
|
****************************************************/
|
|
@@ -365,7 +437,7 @@ declare const otp: typeof randomDigits;
|
|
|
365
437
|
* Intelligently handles European number formats (1.234,56) and US formats (1,234.56).
|
|
366
438
|
* Converts strings to numbers and applies decimal formatting.
|
|
367
439
|
* @param {number|string|null|undefined} value Number value to format
|
|
368
|
-
* @param {number} decimals Number of decimal places (default: 2)
|
|
440
|
+
* @param {number} decimals - Number of decimal places (default: 2)
|
|
369
441
|
* @returns {string} Formatted number string with specified decimals
|
|
370
442
|
* History:
|
|
371
443
|
* 16-10-2025: Created
|
|
@@ -709,4 +781,4 @@ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
|
|
|
709
781
|
declare const isBrowser: boolean;
|
|
710
782
|
declare const isNode: boolean;
|
|
711
783
|
|
|
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 };
|
|
784
|
+
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, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
package/dist/index.js
CHANGED
|
@@ -259,19 +259,94 @@ function safeParseInt(value, defaultValue = 0) {
|
|
|
259
259
|
return defaultValue;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
+
function normalizeDecimals(decimals) {
|
|
263
|
+
if (!Number.isFinite(decimals)) return 0;
|
|
264
|
+
const int = Math.floor(decimals);
|
|
265
|
+
if (int < 0) return 0;
|
|
266
|
+
if (int > 100) return 100;
|
|
267
|
+
return int;
|
|
268
|
+
}
|
|
269
|
+
function sanitizeOperands(...values) {
|
|
270
|
+
return values.every((value) => Number.isFinite(value));
|
|
271
|
+
}
|
|
272
|
+
function safeAdd(a, b, decimals = 2) {
|
|
273
|
+
try {
|
|
274
|
+
if (!sanitizeOperands(a, b)) return 0;
|
|
275
|
+
const precision = normalizeDecimals(decimals);
|
|
276
|
+
return Number((a + b).toFixed(precision));
|
|
277
|
+
} catch {
|
|
278
|
+
return 0;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function safeMultiply(a, b, decimals = 2) {
|
|
282
|
+
try {
|
|
283
|
+
if (!sanitizeOperands(a, b)) return 0;
|
|
284
|
+
const precision = normalizeDecimals(decimals);
|
|
285
|
+
return Number((a * b).toFixed(precision));
|
|
286
|
+
} catch {
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function safeSubtract(a, b, decimals = 2) {
|
|
291
|
+
try {
|
|
292
|
+
if (!sanitizeOperands(a, b)) return 0;
|
|
293
|
+
const precision = normalizeDecimals(decimals);
|
|
294
|
+
return Number((a - b).toFixed(precision));
|
|
295
|
+
} catch {
|
|
296
|
+
return 0;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function safeDivide(a, b, decimals = 2) {
|
|
300
|
+
try {
|
|
301
|
+
if (!sanitizeOperands(a, b) || b === 0) return 0;
|
|
302
|
+
const precision = normalizeDecimals(decimals);
|
|
303
|
+
return Number((a / b).toFixed(precision));
|
|
304
|
+
} catch {
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function numbersEqual(a, b, decimals = 2) {
|
|
309
|
+
try {
|
|
310
|
+
if (!sanitizeOperands(a, b)) return false;
|
|
311
|
+
const precision = normalizeDecimals(decimals);
|
|
312
|
+
return a.toFixed(precision) === b.toFixed(precision);
|
|
313
|
+
} catch {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
262
317
|
var toInteger = safeParseInt;
|
|
263
318
|
function safeParseFloat(value, decimals = 6) {
|
|
264
319
|
try {
|
|
320
|
+
if (typeof value === "number") {
|
|
321
|
+
return isNaN(value) ? 0 : Number(value.toFixed(decimals));
|
|
322
|
+
}
|
|
265
323
|
if (value === void 0 || value === null || value === "") return 0;
|
|
266
|
-
let str = String(value);
|
|
324
|
+
let str = String(value).trim();
|
|
325
|
+
if (!str) return 0;
|
|
326
|
+
str = str.replace(/\s+/g, "");
|
|
327
|
+
let normalized;
|
|
267
328
|
if (str.includes(",") && str.includes(".")) {
|
|
268
|
-
|
|
329
|
+
const lastComma = str.lastIndexOf(",");
|
|
330
|
+
const lastDot = str.lastIndexOf(".");
|
|
331
|
+
if (lastDot > lastComma) {
|
|
332
|
+
normalized = str.replace(/,/g, "");
|
|
333
|
+
} else {
|
|
334
|
+
normalized = str.replace(/\./g, "").replace(",", ".");
|
|
335
|
+
}
|
|
269
336
|
} else if (str.includes(",")) {
|
|
270
|
-
|
|
337
|
+
const parts = str.split(",");
|
|
338
|
+
if (parts.length === 2 && parts[1].length <= 2) {
|
|
339
|
+
normalized = str.replace(",", ".");
|
|
340
|
+
} else {
|
|
341
|
+
normalized = str.replace(/,/g, "");
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
normalized = str;
|
|
271
345
|
}
|
|
272
|
-
const num = parseFloat(
|
|
273
|
-
if (
|
|
274
|
-
|
|
346
|
+
const num = parseFloat(normalized);
|
|
347
|
+
if (!isFinite(num)) return 0;
|
|
348
|
+
const precision = normalizeDecimals(decimals);
|
|
349
|
+
return Number(num.toFixed(precision));
|
|
275
350
|
} catch {
|
|
276
351
|
return 0;
|
|
277
352
|
}
|
|
@@ -1619,6 +1694,6 @@ var assessSecurityRisks = (risks) => {
|
|
|
1619
1694
|
var isBrowser = typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
1620
1695
|
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
1621
1696
|
|
|
1622
|
-
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 };
|
|
1697
|
+
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, numbersEqual, objectToString, omit, otp, parseName, parseToBool, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeAdd, safeDivide, safeMultiply, safeParseFloat, safeParseInt, safeSubtract, sanitize, sanitizeMarkdown, shuffle, slugify, sortBy, stringSimilarity, symbolToCurrency, throttle, toBool, toInteger, toNumber, uniq, uniqBy };
|
|
1623
1698
|
//# sourceMappingURL=index.js.map
|
|
1624
1699
|
//# sourceMappingURL=index.js.map
|