Methods
# static formatValue(value, type, configopt) → {string}
Converts a value to a string in the requested format.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
any
|
value to convert |
|
type |
AttributeType
|
the data type to use when interpreting the value.. |
|
config |
Object
|
<optional> |
configuration options for formatting. |
selector |
"date"
|
"time"
|
"datetime"
|
<optional> |
for date conversions: only format the date, time or both. |
datePattern |
DateFormattingPattern
|
<optional> |
for date conversions: custom pattern to use for formatting. |
places |
number
|
<optional> |
for numeric conversions: number of decimal digits to display (-1 to keep original precision). |
groups |
boolean
|
<optional> |
for numeric conversions: flag indicating whether group separators should be added. |
formatted value
string
Examples
formatValue(Big(3000), "Decimal", { places: 2 }); // "3000.00"
formatValue(+new Date(1980, 7, 23), "DateTime", { datePattern: "dd-MM-yyyy" }); // "23-08-1980"
# static parseValue(value, type, configopt) → {AttributeValue}
Converts a string in the given format to a value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
string
|
string to convert. |
|
type |
AttributeType
|
the data type to use when interpreting the value. |
|
config |
Object
|
<optional> |
configuration options for formatting. |
selector |
"date"
|
"time"
|
"datetime"
|
<optional> |
for date conversions: only format the date, time or both. |
datePattern |
string
|
<optional> |
for date conversions: custom pattern to use for formatting. |
places |
number
|
<optional> |
for numeric conversions: number of decimal digits to display (-1 to keep original precision). |
groups |
boolean
|
<optional> |
for numeric conversions: flag indicating whether group separators should be added. * |
the value if the value could be parsed, otherwise null
. The return type depends on the type of
the attribute as follows:
Attribute type | Return type |
---|---|
Integer, Long, Decimal | external:Big |
Autonumber | string |
DateTime | Date |
Enum | string |
String | string |
Boolean | boolean |
Examples
parseValue("3,000.00", "Decimal"); // Big(3000)
parseValue("23-8-1980", "DateTime",
{ datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23)