Skip to main content

format Attribute

Based on the provided code, the $format directive is not directly implemented. However, we can infer its functionality from the filters object in the deshi class. Here's how you might use the $format directive:

~index.html
<span $text="{price}" $format="currency"></span>

This would display a numeric value stored in the price variable, formatted as currency.

The $format directive allows you to apply predefined formatting filters to your dynamic content. Available filters include:

  1. currency: Formats a number as currency (e.g., $10.00)
  2. uppercase: Converts a string to uppercase
  3. lowercase: Converts a string to lowercase
  4. titlecase: Converts a string to title case
  5. capitalize: Capitalizes the first letter of a string
  6. date: Formats a date (default format: YYYY-MM-DD)
  7. number: Formats a number using locale-specific formatting
  8. percent: Formats a number as a percentage
  9. json: Converts a value to a JSON string
  10. truncate: Truncates a string to a specified length
  11. pluralize: Pluralizes a word based on a count
  12. stripHtml: Removes HTML tags from a string
  13. escapeHtml: Escapes HTML special characters
  14. rgbToHex: Converts an RGB color to hexadecimal
  15. phone: Formats a phone number
  16. creditCard: Formats a credit card number
  17. bytes: Formats a number of bytes into a human-readable format
  18. timeAgo: Converts a date to a "time ago" format
  19. relativeDate: Formats a date relative to the current date

To use these filters, you would combine the $text and $format directives on an element.