UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

169 lines (168 loc) 4.2 kB
export const NUMERIC_FORMAT_PRESETS = { Percentage: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: '%', Multiplier: 100, Parentheses: false, }, Thousand: { FractionDigits: undefined, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: 'K', Multiplier: 0.001, Parentheses: false, }, Million: { FractionDigits: undefined, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: 'M', Multiplier: 0.000001, Parentheses: false, }, Billion: { FractionDigits: undefined, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: 'B', Multiplier: 0.000000001, Parentheses: false, }, BasisPoints: { FractionDigits: 0, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: ' bps', Multiplier: 10000, Parentheses: false, }, Dollar: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '$', Suffix: '', Multiplier: 1, Parentheses: false, }, Sterling: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '£', Suffix: '', Multiplier: 1, Parentheses: false, }, Euro: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '€', Suffix: '', Multiplier: 1, Parentheses: false, }, Yen: { FractionDigits: 0, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '¥', Suffix: '', Multiplier: 1, Parentheses: false, }, Bitcoin: { FractionDigits: 8, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '₿', Suffix: '', Multiplier: 1, Parentheses: false, }, Integer: { FractionDigits: 0, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: '', Multiplier: 1, Parentheses: false, }, Decimal: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: '', Multiplier: 1, Parentheses: false, }, Accounting: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: ',', Prefix: '', Suffix: '', Multiplier: 1, Parentheses: true, }, FXRate: { FractionDigits: 4, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: '', Prefix: '', Suffix: '', Multiplier: 1, Parentheses: false, }, Scientific: { FractionDigits: 2, FractionSeparator: '.', IntegerDigits: undefined, IntegerSeparator: undefined, Prefix: '', Suffix: '', Multiplier: 1, Parentheses: false, Notation: 'scientific', }, }; export const isAdaptableNumericFormatPreset = (value) => { return typeof value === 'string' && value in NUMERIC_FORMAT_PRESETS; }; export const resolveDisplayFormat = (displayFormat) => { if (displayFormat == null) { return undefined; } if (isAdaptableNumericFormatPreset(displayFormat)) { return { Formatter: 'NumberFormatter', Options: { ...NUMERIC_FORMAT_PRESETS[displayFormat] }, }; } return displayFormat; };