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 letterof 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:
Pluralizesa word based on a count - stripHtml:
Removes HTMLtags from a string - escapeHtml:
Escapes HTMLspecialcharacters - rgbToHex: Converts an
RGB color to hexadecimal - phone: Formats a
phone number - creditCard: Formats a
credit card number - bytes: Formats a
number of bytesinto ahuman-readable format - timeAgo: Converts a
dateto a"time ago"format - relativeDate: Formats a
date relative to thecurrent date
To use these filters, you would combine the $text and $format directives on an
element.