UNPKG

mendix

Version:

Mendix pluggable widgets API

116 lines (105 loc) 6.4 kB
import { default as Big_2 } from 'big.js'; /** * Represents the type of attribute. */ declare type AttributeType_2 = "AutoNumber" | "Binary" | "Boolean" | "DateTime" | "Decimal" | "Enum" | "EnumSet" | "HashString" | "Integer" | "Long" | "ObjectReference" | "ObjectReferenceSet" | "String"; /** * Represents the value of an attribute. */ declare type AttributeValue_2 = undefined | string | boolean | Date | BigJS_2 | GUID_2 | GUID_2[]; declare type BigJS_2 = Big_2; /** * Type for describing a date format. The following tokens can be used: * * | Letter | Date or Time Component | Examples | * |:------ |:------------------------------------------------ |:------------------------- | * | M | Month in year, digit | 1 | * | MM | Month in year, digit with leading zero | 01 | * | MMM | Month in year, abbreviated (context sensitive) | Nov | * | MMMM | Month in year (context sensitive) | November | * | L | Month in year, digit (standalone), digit | 1 | * | LL | Month in year, digit with leading zero | 01 | * | LLL | Month in year, abbreviated (standalone) | Nov | * | LLLL | Month in year (standalone) | November | * | yy | Year, two digits | 01 | * | yyyy | Year, four digits | 2001 | * | G | Era designator | AD | * | E | Day name in week, abbreviated | Tue | * | EEEE | Day name in week | Tuesday | * | u | Day of week (1 = Monday, ..., 7 = Sunday) | 5 | * | w | Week in year | 11 | * | W | Week in month | 2 | * | D | Day in year | 133 | * | d | Day in month | 7 | * | F | Day of week in month | 1 | * | a | Am/pm marker | PM | * | H | Hour in day (0-23) | 0 | * | k | Hour in day (1-24) | 24 | * | K | Hour in am/pm (0-11) | 0 | * | h | Hour in am/pm (1-12) | 12 | * | m | Minute in hour | 24 | * | s | Second in minute | 50 | * | S | Millisecond | 201 | */ declare type DateFormattingPattern = string; /** * Converts a value to a string in the requested format. * * @param {any} value value to convert * @param {AttributeType} type the data type to use when interpreting the value.. * @param {Object} [config] configuration options for formatting. * @param {"date" | "time" | "datetime"} [config.selector] for date conversions: only format the date, time or both. * @param {DateFormattingPattern} [config.datePattern] for date conversions: custom pattern to use for formatting. * @param {number} [config.places] for numeric conversions: number of decimal digits to display (-1 to keep original precision). * @param {boolean} [config.groups] for numeric conversions: flag indicating whether group separators should be added. * * @returns {string} formatted value * * @example * formatValue(Big(3000), "Decimal", { places: 2 }); // "3000.00" * * @example * formatValue(+new Date(1980, 7, 23), "DateTime", { datePattern: "dd-MM-yyyy" }); // "23-08-1980" */ export declare function formatValue(value: unknown, type: AttributeType_2, config?: FormatValueConfig): string; declare interface FormatValueConfig { selector?: "date" | "time" | "datetime"; datePattern?: DateFormattingPattern; places?: number; groups?: boolean; } declare type GUID_2 = string & { __guidTag: any; }; declare type Option_2<T> = T | undefined; /** * Converts a string in the given format to a value. * @param {string} value string to convert. * @param {AttributeType} type the data type to use when interpreting the value. * @param {Object} [config] configuration options for formatting. * @param {"date" | "time" | "datetime"} [config.selector] for date conversions: only format the date, time or both. * @param {string} [config.datePattern] for date conversions: custom pattern to use for formatting. * @param {number} [config.places] for numeric conversions: number of decimal digits to display (-1 to keep original precision). * @param {boolean} [config.groups] for numeric conversions: flag indicating whether group separators should be added. * * * @returns {AttributeValue} 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 | {@link external:Big} | * | Autonumber | `string` | * | DateTime | `Date` | * | Enum | `string` | * | String | `string` | * | Boolean | `boolean` | * * @example * parseValue("3,000.00", "Decimal"); // Big(3000) * * @example * parseValue("23-8-1980", "DateTime", * { datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23) */ export declare function parseValue(value: string, type: AttributeType_2, config?: FormatValueConfig): Option_2<AttributeValue_2>; export { }