@salespark/toolkit 2.0.1 → 2.1.0

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
@@ -488,13 +488,179 @@ declare const getStringSimilarity: (s1: string, s2: string) => number;
488
488
  * 21-08-2025: Created
489
489
  ****************************************************/
490
490
  declare const addThousandsSpace: (value: number | string) => string;
491
+ /******************************************************
492
+ * ##: Delay Function
493
+ * Creates a promise that resolves after the specified number of milliseconds
494
+ * @param {Number} ms - Delay in milliseconds (negative values are treated as 0)
495
+ * @returns {Promise<void>} Promise that resolves after the delay
496
+ * History:
497
+ * 25-09-2025: Created
498
+ ****************************************************/
499
+ declare const delay: (ms: number) => Promise<void>;
500
+ /******************************************************
501
+ * ##: Enforced Nil/Empty/Textual Null Check
502
+ * Checks if value is null/undefined/empty string or the text values "null" / "undefined" (case-insensitive)
503
+ * @param {unknown} value - Value to check
504
+ * @returns {Boolean} true if value is considered empty-like
505
+ * History:
506
+ * 25-09-2025: Created
507
+ ****************************************************/
508
+ declare const isNilTextOrEmpty: (value: unknown) => boolean;
509
+ /******************************************************
510
+ * ##: Modern Currency Formatter (Intl.NumberFormat)
511
+ * Formats currency values using modern Intl.NumberFormat API with configurable locale and currency.
512
+ *
513
+ * Provides flexible currency formatting with optional symbol display,
514
+ * proper decimal handling, and graceful fallback for errors.
515
+ * @param {number|string|null|undefined} value Currency value to format
516
+ * @param {boolean} withoutCurrencySymbol Hide currency symbol (show as decimal)
517
+ * @param {string} currency Currency code (ISO 4217, e.g., "EUR", "USD")
518
+ * @param {string} locale Locale string (e.g., "pt-PT", "en-US")
519
+ * @returns {string} Formatted currency string (e.g., "1.234,56 €" or "1.234,56")
520
+ * History:
521
+ * 25-09-2025: Created
522
+ ****************************************************/
523
+ declare const formatCurrency: (value: number | string | null | undefined, withoutCurrencySymbol?: boolean, currency?: string, locale?: string) => string;
524
+ /******************************************************
525
+ * ##: Parse Name into First and Last Components
526
+ * Extracts first and last name from a full name string.
527
+ *
528
+ * Handles edge cases like single names, empty inputs, and multi-word names.
529
+ * Returns first word as firstName and last word as lastName.
530
+ * @param {string|null|undefined} name Full name string to parse
531
+ * @returns {{firstName: string, lastName: string}} Object with firstName and lastName properties
532
+ * History:
533
+ * 25-09-2025: Created
534
+ ****************************************************/
535
+ declare const parseName: (name: string | null | undefined) => {
536
+ firstName: string;
537
+ lastName: string;
538
+ };
539
+ /******************************************************
540
+ * ##: Currency Symbol to ISO Code Converter
541
+ * Converts currency symbols (€, £, $) to ISO 4217 currency codes.
542
+ *
543
+ * Maps common currency symbols to their corresponding three-letter codes.
544
+ * Returns "EUR" as fallback for unknown symbols.
545
+ * @param {string|null|undefined} symbol Currency symbol to convert (e.g., "€", "£", "$")
546
+ * @returns {string} ISO 4217 currency code (e.g., "EUR", "GBP", "USD")
547
+ * History:
548
+ * 25-09-2025: Created
549
+ ****************************************************/
550
+ declare const symbolToCurrency: (symbol: string | null | undefined) => string;
551
+ /******************************************************
552
+ * ##: ISO Currency Code to Symbol Converter
553
+ * Converts ISO 4217 currency codes to their corresponding symbols.
554
+ *
555
+ * Maps three-letter currency codes to common currency symbols.
556
+ * Returns "€" as fallback for unknown currencies.
557
+ * @param {string|null|undefined} currency ISO 4217 currency code (e.g., "EUR", "GBP", "USD")
558
+ * @returns {string} Currency symbol (e.g., "€", "£", "$")
559
+ * History:
560
+ * 25-09-2025: Created
561
+ ****************************************************/
562
+ declare const currencyToSymbol: (currency: string | null | undefined) => string;
563
+ /**
564
+ * @deprecated Use `isNilTextOrEmpty` instead.
565
+ */
566
+ declare const isNullUndefinedOrEmptyEnforced: (value: unknown) => boolean;
491
567
  /**
492
568
  * @deprecated Use `addThousandsSpace` instead.
493
569
  */
494
570
  declare const addSpaceBetweenNumbers: (value: number | string) => string;
495
571
 
572
+ /******************************************************
573
+ * ##: Portuguese Tax ID (NIF) Validator
574
+ * Validates a Portuguese tax identification number ("NIF").
575
+ *
576
+ * Rules / Notes:
577
+ * - Exactly 9 digits.
578
+ * - Check digit (last digit) via Mod11 weights 9..2 over first 8 digits.
579
+ * sum = Σ(d[i]*w[i]); mod = sum % 11; check = (mod < 2 ? 0 : 11 - mod).
580
+ * - Allowed leading digits: 1,2,3,5,6,8,9.
581
+ * - Strips non-digit characters.
582
+ * - Rejects repeated digit sequences (e.g., 000000000).
583
+ * @param value Raw input to validate (string or number)
584
+ * @returns true if valid, otherwise false.
585
+ * History:
586
+ * 25-09-2025: Created as isValidPTTaxId
587
+ ****************************************************/
588
+ declare function isPTTaxId(value: string | number): boolean;
589
+ /**
590
+ * @deprecated Use isPTTaxId instead.
591
+ */
592
+ declare const isValidPTTaxId: typeof isPTTaxId;
593
+
594
+ /******************************************************
595
+ * ##: IBAN (International Bank Account Number) Validator
596
+ * Validates International Bank Account Numbers according to ISO 13616.
597
+ *
598
+ * Rules / Notes:
599
+ * - Country-specific format and length validation
600
+ * - MOD-97 checksum validation
601
+ * - BBAN (Basic Bank Account Number) format validation
602
+ * - Supports all IBAN registry countries
603
+ * - Strips spaces and formatting automatically
604
+ * @param value Raw IBAN input to validate (string)
605
+ * @returns true if valid IBAN, otherwise false.
606
+ * History:
607
+ * 25-09-2025: Adapted from ibantools library for SalesPark toolkit
608
+ ****************************************************/
609
+ declare function isValidIBAN(value: string): boolean;
610
+
611
+ /******************************************************
612
+ * ##: Markdown Security Checker
613
+ * Analyzes markdown text for potential security risks and XSS vulnerabilities.
614
+ *
615
+ * Detects dangerous HTML tags, JavaScript injection attempts, suspicious protocols,
616
+ * and other security threats. Provides sanitized output with detailed risk assessment.
617
+ * @param {string|null|undefined} markdownText Markdown content to analyze
618
+ * @returns {{isValid: boolean, text: string, risks: Array}} Security analysis result
619
+ * History:
620
+ * 25-09-2025: Created
621
+ ****************************************************/
622
+ interface SecurityRisk {
623
+ type: string;
624
+ description: string;
625
+ severity?: 'low' | 'medium' | 'high' | 'critical';
626
+ }
627
+ interface SecurityCheckResult {
628
+ isValid: boolean;
629
+ text: string;
630
+ risks: SecurityRisk[];
631
+ sanitized: boolean;
632
+ }
633
+ declare const checkMarkdownSecurity: (markdownText: string | null | undefined) => SecurityCheckResult;
634
+ /******************************************************
635
+ * ##: HTML/Markdown Sanitizer
636
+ * Removes potentially dangerous HTML elements and attributes from text.
637
+ *
638
+ * More aggressive sanitization for when security is paramount.
639
+ * Strips all HTML tags and suspicious content.
640
+ * @param {string|null|undefined} text Text to sanitize
641
+ * @returns {string} Sanitized text with dangerous content removed
642
+ * History:
643
+ * 25-09-2025: Created
644
+ ****************************************************/
645
+ declare const sanitizeMarkdown: (text: string | null | undefined) => string;
646
+ /******************************************************
647
+ * ##: Security Risk Assessment
648
+ * Provides a security risk score and recommendations based on detected risks.
649
+ *
650
+ * Calculates risk score and provides actionable security recommendations.
651
+ * @param {SecurityRisk[]} risks Array of detected security risks
652
+ * @returns {{score: number, level: string, recommendations: string[]}} Risk assessment
653
+ * History:
654
+ * 25-09-2025: Created
655
+ ****************************************************/
656
+ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
657
+ score: number;
658
+ level: "safe" | "low" | "medium" | "high" | "critical";
659
+ recommendations: string[];
660
+ };
661
+
496
662
  /** Environment helpers (runtime-agnostic checks) */
497
663
  declare const isBrowser: boolean;
498
664
  declare const isNode: boolean;
499
665
 
500
- export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, basicSanitize, chunk, clamp, cleanObject, compact, debounce, deburr, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrZero, objectToString, omit, otp, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, shuffle, slugify, sortBy, stringSimilarity, throttle, toInteger, toNumber, uniq, uniqBy };
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 };
package/dist/index.d.ts CHANGED
@@ -488,13 +488,179 @@ declare const getStringSimilarity: (s1: string, s2: string) => number;
488
488
  * 21-08-2025: Created
489
489
  ****************************************************/
490
490
  declare const addThousandsSpace: (value: number | string) => string;
491
+ /******************************************************
492
+ * ##: Delay Function
493
+ * Creates a promise that resolves after the specified number of milliseconds
494
+ * @param {Number} ms - Delay in milliseconds (negative values are treated as 0)
495
+ * @returns {Promise<void>} Promise that resolves after the delay
496
+ * History:
497
+ * 25-09-2025: Created
498
+ ****************************************************/
499
+ declare const delay: (ms: number) => Promise<void>;
500
+ /******************************************************
501
+ * ##: Enforced Nil/Empty/Textual Null Check
502
+ * Checks if value is null/undefined/empty string or the text values "null" / "undefined" (case-insensitive)
503
+ * @param {unknown} value - Value to check
504
+ * @returns {Boolean} true if value is considered empty-like
505
+ * History:
506
+ * 25-09-2025: Created
507
+ ****************************************************/
508
+ declare const isNilTextOrEmpty: (value: unknown) => boolean;
509
+ /******************************************************
510
+ * ##: Modern Currency Formatter (Intl.NumberFormat)
511
+ * Formats currency values using modern Intl.NumberFormat API with configurable locale and currency.
512
+ *
513
+ * Provides flexible currency formatting with optional symbol display,
514
+ * proper decimal handling, and graceful fallback for errors.
515
+ * @param {number|string|null|undefined} value Currency value to format
516
+ * @param {boolean} withoutCurrencySymbol Hide currency symbol (show as decimal)
517
+ * @param {string} currency Currency code (ISO 4217, e.g., "EUR", "USD")
518
+ * @param {string} locale Locale string (e.g., "pt-PT", "en-US")
519
+ * @returns {string} Formatted currency string (e.g., "1.234,56 €" or "1.234,56")
520
+ * History:
521
+ * 25-09-2025: Created
522
+ ****************************************************/
523
+ declare const formatCurrency: (value: number | string | null | undefined, withoutCurrencySymbol?: boolean, currency?: string, locale?: string) => string;
524
+ /******************************************************
525
+ * ##: Parse Name into First and Last Components
526
+ * Extracts first and last name from a full name string.
527
+ *
528
+ * Handles edge cases like single names, empty inputs, and multi-word names.
529
+ * Returns first word as firstName and last word as lastName.
530
+ * @param {string|null|undefined} name Full name string to parse
531
+ * @returns {{firstName: string, lastName: string}} Object with firstName and lastName properties
532
+ * History:
533
+ * 25-09-2025: Created
534
+ ****************************************************/
535
+ declare const parseName: (name: string | null | undefined) => {
536
+ firstName: string;
537
+ lastName: string;
538
+ };
539
+ /******************************************************
540
+ * ##: Currency Symbol to ISO Code Converter
541
+ * Converts currency symbols (€, £, $) to ISO 4217 currency codes.
542
+ *
543
+ * Maps common currency symbols to their corresponding three-letter codes.
544
+ * Returns "EUR" as fallback for unknown symbols.
545
+ * @param {string|null|undefined} symbol Currency symbol to convert (e.g., "€", "£", "$")
546
+ * @returns {string} ISO 4217 currency code (e.g., "EUR", "GBP", "USD")
547
+ * History:
548
+ * 25-09-2025: Created
549
+ ****************************************************/
550
+ declare const symbolToCurrency: (symbol: string | null | undefined) => string;
551
+ /******************************************************
552
+ * ##: ISO Currency Code to Symbol Converter
553
+ * Converts ISO 4217 currency codes to their corresponding symbols.
554
+ *
555
+ * Maps three-letter currency codes to common currency symbols.
556
+ * Returns "€" as fallback for unknown currencies.
557
+ * @param {string|null|undefined} currency ISO 4217 currency code (e.g., "EUR", "GBP", "USD")
558
+ * @returns {string} Currency symbol (e.g., "€", "£", "$")
559
+ * History:
560
+ * 25-09-2025: Created
561
+ ****************************************************/
562
+ declare const currencyToSymbol: (currency: string | null | undefined) => string;
563
+ /**
564
+ * @deprecated Use `isNilTextOrEmpty` instead.
565
+ */
566
+ declare const isNullUndefinedOrEmptyEnforced: (value: unknown) => boolean;
491
567
  /**
492
568
  * @deprecated Use `addThousandsSpace` instead.
493
569
  */
494
570
  declare const addSpaceBetweenNumbers: (value: number | string) => string;
495
571
 
572
+ /******************************************************
573
+ * ##: Portuguese Tax ID (NIF) Validator
574
+ * Validates a Portuguese tax identification number ("NIF").
575
+ *
576
+ * Rules / Notes:
577
+ * - Exactly 9 digits.
578
+ * - Check digit (last digit) via Mod11 weights 9..2 over first 8 digits.
579
+ * sum = Σ(d[i]*w[i]); mod = sum % 11; check = (mod < 2 ? 0 : 11 - mod).
580
+ * - Allowed leading digits: 1,2,3,5,6,8,9.
581
+ * - Strips non-digit characters.
582
+ * - Rejects repeated digit sequences (e.g., 000000000).
583
+ * @param value Raw input to validate (string or number)
584
+ * @returns true if valid, otherwise false.
585
+ * History:
586
+ * 25-09-2025: Created as isValidPTTaxId
587
+ ****************************************************/
588
+ declare function isPTTaxId(value: string | number): boolean;
589
+ /**
590
+ * @deprecated Use isPTTaxId instead.
591
+ */
592
+ declare const isValidPTTaxId: typeof isPTTaxId;
593
+
594
+ /******************************************************
595
+ * ##: IBAN (International Bank Account Number) Validator
596
+ * Validates International Bank Account Numbers according to ISO 13616.
597
+ *
598
+ * Rules / Notes:
599
+ * - Country-specific format and length validation
600
+ * - MOD-97 checksum validation
601
+ * - BBAN (Basic Bank Account Number) format validation
602
+ * - Supports all IBAN registry countries
603
+ * - Strips spaces and formatting automatically
604
+ * @param value Raw IBAN input to validate (string)
605
+ * @returns true if valid IBAN, otherwise false.
606
+ * History:
607
+ * 25-09-2025: Adapted from ibantools library for SalesPark toolkit
608
+ ****************************************************/
609
+ declare function isValidIBAN(value: string): boolean;
610
+
611
+ /******************************************************
612
+ * ##: Markdown Security Checker
613
+ * Analyzes markdown text for potential security risks and XSS vulnerabilities.
614
+ *
615
+ * Detects dangerous HTML tags, JavaScript injection attempts, suspicious protocols,
616
+ * and other security threats. Provides sanitized output with detailed risk assessment.
617
+ * @param {string|null|undefined} markdownText Markdown content to analyze
618
+ * @returns {{isValid: boolean, text: string, risks: Array}} Security analysis result
619
+ * History:
620
+ * 25-09-2025: Created
621
+ ****************************************************/
622
+ interface SecurityRisk {
623
+ type: string;
624
+ description: string;
625
+ severity?: 'low' | 'medium' | 'high' | 'critical';
626
+ }
627
+ interface SecurityCheckResult {
628
+ isValid: boolean;
629
+ text: string;
630
+ risks: SecurityRisk[];
631
+ sanitized: boolean;
632
+ }
633
+ declare const checkMarkdownSecurity: (markdownText: string | null | undefined) => SecurityCheckResult;
634
+ /******************************************************
635
+ * ##: HTML/Markdown Sanitizer
636
+ * Removes potentially dangerous HTML elements and attributes from text.
637
+ *
638
+ * More aggressive sanitization for when security is paramount.
639
+ * Strips all HTML tags and suspicious content.
640
+ * @param {string|null|undefined} text Text to sanitize
641
+ * @returns {string} Sanitized text with dangerous content removed
642
+ * History:
643
+ * 25-09-2025: Created
644
+ ****************************************************/
645
+ declare const sanitizeMarkdown: (text: string | null | undefined) => string;
646
+ /******************************************************
647
+ * ##: Security Risk Assessment
648
+ * Provides a security risk score and recommendations based on detected risks.
649
+ *
650
+ * Calculates risk score and provides actionable security recommendations.
651
+ * @param {SecurityRisk[]} risks Array of detected security risks
652
+ * @returns {{score: number, level: string, recommendations: string[]}} Risk assessment
653
+ * History:
654
+ * 25-09-2025: Created
655
+ ****************************************************/
656
+ declare const assessSecurityRisks: (risks: SecurityRisk[]) => {
657
+ score: number;
658
+ level: "safe" | "low" | "medium" | "high" | "critical";
659
+ recommendations: string[];
660
+ };
661
+
496
662
  /** Environment helpers (runtime-agnostic checks) */
497
663
  declare const isBrowser: boolean;
498
664
  declare const isNode: boolean;
499
665
 
500
- export { addSpaceBetweenNumbers, addThousandsSpace, areArraysDeepEqualUnordered, areArraysEqual, basicSanitize, chunk, clamp, cleanObject, compact, debounce, deburr, difference, fill, flatten, flattenDepth, flattenDepthBase, flattenOnce, formatBytes, getStringSimilarity, groupBy, hasNilOrEmpty, humanFileSize, intersection, isBrowser, isFlattenable, isNil, isNilEmptyOrZeroLen, isNilOrEmpty, isNilOrNaN, isNilOrZeroLen, isNilText, isNode, isNullOrUndefined, isNullOrUndefinedEmptyOrZero, isNullOrUndefinedInArray, isNullOrUndefinedOrNaN, isNullOrUndefinedTextInc, isNullUndefinedOrEmpty, isNullUndefinedOrZero, objectToString, omit, otp, parseToNumber, pick, pluck, pushAll, randomDigits, removeDiacritics, round, safeParseInt, sanitize, shuffle, slugify, sortBy, stringSimilarity, throttle, toInteger, toNumber, uniq, uniqBy };
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 };