Formatters
Below is a list of importable functions that are found in the applications/global/front-end/js directory.
They can be imported individually like so:
js
{ enPascalToKebab } from '@global/js/customFilterFunctions'They are also globally installed as mixins in Vue so there is no need to import them within Vue apps and they can be used directly in the template tags.
enFormatDateToLocal -
functionTakes a datetime UTC string and will convert it to a formatted local date and time
| Name | Type | Description |
|---|---|---|
value | string | — |
mm/dd/yyyy hh:mm:ss
enFormatDate -
functionFormats a datetime string, format can be customized by passing in DateTimeFormat options. Removes UTC information so that the date displayed is always the same despite timezone.
| Name | Type | Description |
|---|---|---|
date | string | date string |
options | object |
mm/dd/yyyy
enFormatJsonDate -
functionFormats a datetime string, defaults to 2 digit year format
| Name | Type | Description |
|---|---|---|
value | string | date string |
displayFullYear | boolean | changes to 4 digit year format |
mm/dd/yy
enFormatJsonDatetime -
functionFormats a datetime string to a date and time, defaults to 2 digit year format, removes any UTC information
| Name | Type | Description |
|---|---|---|
value | string | date string |
displayFullYear | boolean | changes to 4 digit year format |
mm/dd/yy hh:mm:ss
enFormatMoney -
functionFormats number value to a currency, adding dollar symbol and comma separators
| Name | Type | Description |
|---|---|---|
value | numberstring | if a string is passed, function will try to convert it to a number |
decimalPlaces | number | number of decimal places to show |
$###,### or ""
enFormatWholeMoney -
functionSimilar to enFormatMoney, but trims trailing .00 and will also return $0 instead of an empty string
| Name | Type | Description |
|---|---|---|
value | * | if a string is passed, function will try to convert it to a number |
decimalPlaces | * | number of decimal places to show |
$###,### or $0
enFormatPercent -
functionAdds a percent symbol to the end of the value
| Name | Type | Description |
|---|---|---|
value | stringnumber | — |
##%
enBoolToYesNo -
functionConverts a boolean value to "Yes" or "No"
| Name | Type | Description |
|---|---|---|
value | boolean | — |
Yes or No
enFormatPhone -
functionConverts a string to a formatted phone number
| Name | Type | Description |
|---|---|---|
value | string | — |
(###) ###-####
enFormatTaxId -
functionConverts a string of numbers to a formatted Tax ID
| Name | Type | Description |
|---|---|---|
value | string | — |
##-#######
enTruncate -
functionShortens the length of a string if the length is greater than the maxLength value and appends an ellipsis to the end
| Name | Type | Description |
|---|---|---|
string | string | — |
maxLength | number | — |
truncated string if longer than max length
dateDelta -
functionDisplays the time elapsed between 2 dates
| Name | Type | Description |
|---|---|---|
fromDate | Date | — |
toDate | Date | (default now) |
roundToDigit | number | (default 0) Will round the least significant date unit disccovered to this many digits |
preciseTo | number | (default '') Will resolve down to provided value, '' will yield only the most significant date unit discovered |
string display of the time elapsed
enCalcAge -
functionFunction that will return an age from a date
| Name | Type | Description |
|---|---|---|
date | string | date string that can be parsed by Date() |
defaultVal | numberstring | return value for if the date passed in is null, empty, or cannot be parsed |
age as a number
enPascalToKebab -
functionFunction that will convert PascalCase to kebab-case.
| Name | Type | Description |
|---|---|---|
string | string | string to convert |
sortByKey -
functionFunction used by .sort on an array of objects to sort by a specific key
| Name | Type | Description |
|---|---|---|
key | string | — |
filterObjectsByString -
functionFunction used to filter a list of objects using a string match on all the keys in the object.
| Name | Type | Description |
|---|---|---|
list | array.<object> | — |
searchString | string | — |
filtered list