FormatUtils: {
    formatAddress: ((address) => string);
    formatCreditCard: ((cardNumber) => string);
    formatCurrency: ((amount, currency?, locale?) => string);
    formatFileSize: ((bytes, decimals?) => string);
    formatNumber: ((num) => string);
    formatPercent: ((value, decimals?) => string);
    formatPhoneNumber: ((phone, format?) => string);
    formatDuration: ((ms, format?) => string);
    formatSSN: ((ssn) => string);
} = ...

Type declaration

  • formatAddress: ((address) => string)

    Formats an address into a comma-separated string.

    Returns

    The formatted address string

    Example

    const address = {
    street: "123 Main St",
    city: "Springfield",
    state: "IL",
    zip: "62701"
    };
    const formatted = FormatUtils.formatAddress(address);
    // "123 Main St, Springfield, IL, 62701"
      • (address): string
      • Parameters

        • address: {
              street?: string;
              city?: string;
              state?: string;
              zip?: string;
              country?: string;
          }

          The address object to format

          • Optional street?: string

            Street address

          • Optional city?: string

            City name

          • Optional state?: string

            State or province

          • Optional zip?: string

            ZIP or postal code

          • Optional country?: string

            Country name

        Returns string

  • formatCreditCard: ((cardNumber) => string)

    Formats a credit card number by adding spaces every 4 digits.

    Returns

    The formatted card number with spaces

    Example

    const card = FormatUtils.formatCreditCard("4111111111111111");
    // "4111 1111 1111 1111"
      • (cardNumber): string
      • Parameters

        • cardNumber: string

          The card number to format

        Returns string

  • formatCurrency: ((amount, currency?, locale?) => string)

    Formats a number as currency using the Intl.NumberFormat API.

    Returns

    The formatted currency string

    Example

    const price = FormatUtils.formatCurrency(99.99, "USD", "en-US");
    // "$99.99"

    const euros = FormatUtils.formatCurrency(99.99, "EUR", "de-DE");
    // "99,99 €"
      • (amount, currency?, locale?): string
      • Parameters

        • amount: number

          The amount to format

        • currency: string = "USD"

          The currency code (e.g., 'USD', 'EUR', 'GBP')

        • locale: string = "en-US"

          The locale to use for formatting

        Returns string

  • formatFileSize: ((bytes, decimals?) => string)

    Formats a file size in bytes to a human-readable string.

    Returns

    The formatted file size with appropriate unit

    Example

    const size = FormatUtils.formatFileSize(1024); // "1 KB"
    const size2 = FormatUtils.formatFileSize(1024 * 1024, 1); // "1.0 MB"
      • (bytes, decimals?): string
      • Parameters

        • bytes: number

          The size in bytes

        • decimals: number = 2

          Number of decimal places to show

        Returns string

  • formatNumber: ((num) => string)

    Formats a number with commas as thousands separators.

    Returns

    Formatted number string with commas

    Example

    const num = FormatUtils.formatNumber(1000000); // "1,000,000"
    
      • (num): string
      • Parameters

        • num: number

          Number to format

        Returns string

  • formatPercent: ((value, decimals?) => string)

    Formats a number as a percentage.

    Returns

    The formatted percentage string

    Example

    const percent = FormatUtils.formatPercent(75.5); // "75.5%"
    
      • (value, decimals?): string
      • Parameters

        • value: number

          The value to format

        • decimals: number = 1

          Number of decimal places to show

        Returns string

  • formatPhoneNumber: ((phone, format?) => string)

    Formats a phone number according to the specified format.

    Returns

    The formatted phone number

    Example

    const usPhone = FormatUtils.formatPhoneNumber("1234567890", "US");
    // "(123) 456-7890"

    const euPhone = FormatUtils.formatPhoneNumber("1234567890", "EU");
    // "12 34 56 78 90"
      • (phone, format?): string
      • Parameters

        • phone: string

          The phone number to format

        • format: "US" | "EU" = "US"

          The format to use ('US' or 'EU')

        Returns string

  • formatDuration: ((ms, format?) => string)

    Formats a duration in milliseconds to a human-readable string.

    Returns

    The formatted duration string

    Example

    const short = FormatUtils.formatDuration(3661000, "short"); // "1h"
    const long = FormatUtils.formatDuration(3661000, "long");
    // "1 hour, 1 minute, 1 second"
      • (ms, format?): string
      • Parameters

        • ms: number

          The duration in milliseconds

        • format: "short" | "long" = "short"

          The format to use ('short' or 'long')

        Returns string

  • formatSSN: ((ssn) => string)

    Formats a social security number with hyphens.

    Returns

    The formatted SSN

    Example

    const ssn = FormatUtils.formatSSN("123456789"); // "123-45-6789"
    
      • (ssn): string
      • Parameters

        • ssn: string

          The SSN to format

        Returns string