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:
- currency: Formats a number as currency
(e.g., $10.00)
- uppercase: Converts a string to
uppercase
- lowercase: Converts a string to
lowercase
- titlecase: Converts a string to
title case
- capitalize: Capitalizes the
first letter
of a string - date: Formats a date
(default format: YYYY-MM-DD)
- number: Formats a number using
locale-specific formatting
- percent: Formats a number as a
percentage
- json: Converts a value to a
JSON string
- truncate: Truncates a string to a specified
length
- pluralize:
Pluralizes
a word based on a count - stripHtml:
Removes HTML
tags from a string - escapeHtml:
Escapes HTML
specialcharacters
- rgbToHex: Converts an
RGB color to hexadecimal
- phone: Formats a
phone number
- creditCard: Formats a
credit card number
- bytes: Formats a
number of bytes
into ahuman-readable format
- timeAgo: Converts a
date
to a"time ago"
format - relativeDate: Formats a
date relativ
e to thecurrent date
To use these filters, you would combine the $text and $format
directives on an
element.