Date & Time
formatDate
Format a date value using a custom format pattern.
Parameters
Parameter | Type | Required | Description |
|
| Yes | Date object, epoch timestamp (ms), or stringified number |
|
| Yes | Format pattern (date-fns tokens) |
Returns: Formatted date string, empty string if invalid
Examples
// basic formatting
{{ utils.formatDate(new Date(), 'dd-MM-yyyy') }}
// → 26-10-2025
// with time
{{ utils.formatDate(new Date(), 'dd-MM-yyyy HH:mm:ss') }}
// → 26-10-2025 14:30:45
// epoch timestamp
{{ utils.formatDate(1729944645000, 'MMM dd, yyyy') }}
// → Oct 26, 2025
// from data source
{{ utils.formatDate({{ userRecord.createdTime }}, 'dd-MMM-yyyy') }}
// → 26-Oct-2025Common Patterns
Pattern | Output |
| 26-10-2025 |
| 10/26/2025 |
| 2025-10-26 |
| Oct 26, 2025 |
| 26/10/2025 14:30 |
| 2:30 PM |
formatDateByFormatType
Format dates using predefined format types. Includes relative time formatting ("2 hours ago").
Parameters
Parameter | Type | Required | Default | Description |
|
| Yes | - | Date object, epoch timestamp (ms), or stringified number |
|
| No |
| Predefined format type or custom pattern |
|
| No | - | Options for
only |
Format Types
Type | Output Example |
(default) | 10/26/2025 14:30 |
| 26 Oct 2025, 14:30:45 |
| 2025-10-26 |
| 2025-10-26T14:30:45+00:00 |
| 2 hours ago |
Examples
// default format
{{ utils.formatDateByFormatType(new Date()) }}
// → 10/26/2025 14:30
// specific format
{{ utils.formatDateByFormatType(new Date(), 'dmyhms') }}
// → 26 Oct 2025, 14:30:45
// relative time
{{ utils.formatDateByFormatType({{ lastLogin }}, 'relative-time-to-now') }}
// → 2 hours ago
// with options (relative time only)
{{ utils.formatDateByFormatType({{ lastLogin }}, 'relative-time-to-now', { includeSeconds: true }) }}
// → 2 hours 15 minutes 30 seconds agoformatTime
Convert milliseconds into a human-readable duration (e.g., "1h 30m 15s").
Parameters
Parameter | Type | Required | Default | Description |
|
| Yes | - | Duration in milliseconds |
|
| No |
| Lowest time unit to display |
|
| No |
|
: "1h 30m",
: "1 hour 30 minutes" |
|
| No |
| Max number of units to show |
Examples
// basic duration
{{ utils.formatTime(5415000) }}
// → 1h 30m 15s
// limit precision
{{ utils.formatTime(3661005, 'minutes') }}
// → 1h 1m
// comfortable notation
{{ utils.formatTime(5415000, 'seconds', 'comfortable') }}
// → 1 hour 30 minutes 15 seconds
// limit units shown
{{ utils.formatTime(269329401003, 'milliseconds', 'compact', 2) }}
// → 8y 6mo
// uptime display
System uptime:
{{ utils.formatTime({{ uptimeMs }}, 'seconds') }}
// → System uptime: 15d 6h 32m 18sNumbers
formatNumber
Format numbers with locale support, compact notation (1.2K, 3.4M), and units.
Parameters
Single object parameter with these properties:
Property | Type | Required | Description |
|
| Yes | Number to format |
|
| No | Locale (e.g., 'en-US', 'de-DE') |
|
| No | Max decimal places |
|
| No | Format style (default: 'standard') |
|
| No | For compact: 'short' = "1.5K", 'long' = "1.5 thousand" |
|
| No | Unit (e.g., 'percent', 'kilometer', 'byte') |
|
| No | Unit display style |
|
| No | Pad decimals (5.5 → 5.50) |
Examples
// basic formatting
{{ utils.formatNumber({ value: 1234.567, maximumFractionDigits: 2 }) }}
// → 1,234.57
// compact notation
{{ utils.formatNumber({ value: 1500000, notation: 'compact', compactDisplay: 'short' }) }}
// → 1.5M
// with units
{{ utils.formatNumber({ value: 0.856, unit: 'percent' }) }}
// → 85.6%
{{ utils.formatNumber({ value: 42.5, unit: 'kilometer' }) }}
// → 42.5 km
// locale-specific
{{ utils.formatNumber({ value: 1234.56, locale: 'de-DE' }) }}
// → 1.234,56
// dashboard metric
Total Users:
{{ utils.formatNumber({ value: {{ totalUsers }}, notation: 'compact' }) }}
// → Total Users: 1.2MCommon Units
Category | Units |
Length |
|
Mass |
|
Temperature |
|
Digital |
|
Other |
|
JSON
parseJson
Safely parse JSON strings. Never throws errors—returns fallback value on failure.
Parameters
Parameter | Type | Required | Default | Description |
|
| Yes | - | JSON string to parse |
|
| No |
| Value returned if parsing fails |
|
| No | - | Custom reviver function |
Examples
// basic parsing
{{ utils.parseJson('{"name": "John", "age": 30}') }}
// → { name: "John", age: 30 }
// with fallback
{{ utils.parseJson('invalid json', { error: true }) }}
// → { error: true }
// parse API response
{{ utils.parseJson({{ apiResponse }}, { success: false, data: [] }) }}
// parse stored settings
{{ utils.parseJson({{ userSettings }}, { theme: 'light', lang: 'en' }).theme }}
// → 'light'stringifyJson
Safely convert objects to JSON strings. Never throws errors—returns fallback on failure (e.g., circular references).
Parameters
Parameter | Type | Required | Default | Description |
|
| Yes | - | Object to stringify |
|
| No |
| Value returned if stringify fails |
|
| No |
| Spaces for indentation (pretty print) |
|
| No | - | Custom replacer function |
Examples
// basic stringify
{{ utils.stringifyJson({ name: "John", age: 30 }) }}
// → '{"name":"John","age":30}'
// pretty print
{{ utils.stringifyJson({ name: "John", age: 30 }, null, 2) }}
// → '{
// "name": "John",
// "age": 30
// }'
// with fallback
{{ utils.stringifyJson({{ circularObject }}, '{}') }}
// → '{}'
// prepare for API
{{ utils.stringifyJson({ userId: {{ user.id }}, action: "update" }) }}
// filter sensitive data
{{ utils.stringifyJson(
{{ userData }},
null,
0,
(key, value) => key === 'password' ? undefined : value
) }}Reference
Format Type Reference
Complete list of formatDateByFormatTypeformat types:
Type | Pattern | Example |
|
| 10/26/2025 14:30 |
|
| 26 Oct 2025, 14:30:45 |
|
| 26 Oct, 14:30:45 |
|
| 26 Oct 2025, 2:30 PM |
|
| 26 Oct 2025, 14:30 |
|
| Oct 26, 2025 2:30 PM |
|
| Oct 26, 2:30PM |
|
| October 26, 2025 |
|
| 26 Oct 2025 |
|
| 2025-10-26 |
|
| 26-10-2025 |
|
| 26-10-2025 2:30 PM |
|
| 26 Oct |
|
| 2025-10-26T14:30:45+00:00 |
|
| 2:30 PM |
|
| Sunday, 10-26-2025 |
| - | 2 hours ago |