@qrvey/utils 1.2.9-14 → 1.2.9-18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +755 -652
- package/dist/cjs/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -0
- package/dist/cjs/filters/helpers/ui/index.d.ts +1 -0
- package/dist/cjs/filters/helpers/ui/index.js +1 -0
- package/dist/cjs/filters/helpers/ui/transformFilterValues.d.ts +4 -0
- package/dist/cjs/filters/helpers/ui/transformFilterValues.js +22 -0
- package/dist/cjs/filters/interfaces/builder/IFilterBuilderGeneralConfig.d.ts +1 -0
- package/dist/cjs/filters/interfaces/panel/IFilterPanelConfig.d.ts +1 -0
- package/dist/cjs/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
- package/dist/cjs/filters/interfaces/ui/IFUTransformFilterValuesSettings.js +2 -0
- package/dist/cjs/filters/interfaces/ui/index.d.ts +3 -2
- package/dist/cjs/filters/interfaces/ui/index.js +3 -2
- package/dist/cjs/format/definition.d.ts +17 -0
- package/dist/cjs/format/definition.js +31 -1
- package/dist/cjs/format/format.d.ts +2 -1
- package/dist/cjs/format/format.js +8 -5
- package/dist/cjs/format/index.d.ts +1 -0
- package/dist/cjs/format/index.js +1 -0
- package/dist/cjs/format/localization.d.ts +3 -0
- package/dist/cjs/format/localization.js +56 -0
- package/dist/cjs/globalization/helpers/getI18nCalendar.d.ts +4 -0
- package/dist/cjs/globalization/helpers/getI18nCalendar.js +69 -0
- package/dist/cjs/globalization/helpers/index.d.ts +1 -0
- package/dist/cjs/globalization/helpers/index.js +1 -0
- package/dist/cjs/globalization/interfaces/calendar/II18nCalendar.d.ts +7 -0
- package/dist/cjs/globalization/interfaces/calendar/II18nCalendar.js +2 -0
- package/dist/cjs/globalization/interfaces/calendar/II18nCalendarProperties.d.ts +9 -0
- package/dist/cjs/globalization/interfaces/calendar/II18nCalendarProperties.js +2 -0
- package/dist/cjs/globalization/interfaces/calendar/index.d.ts +2 -0
- package/dist/cjs/globalization/interfaces/calendar/index.js +14 -0
- package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderFontOptions.d.ts +5 -3
- package/dist/cjs/globalization/interfaces/common/II18nCommon.d.ts +2 -0
- package/dist/cjs/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
- package/dist/cjs/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
- package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
- package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.js +2 -0
- package/dist/cjs/globalization/interfaces/index.d.ts +1 -0
- package/dist/cjs/globalization/interfaces/index.js +1 -0
- package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
- package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.js +10 -0
- package/dist/cjs/globalization/labels/calendar/index.d.ts +1 -0
- package/dist/cjs/globalization/labels/calendar/index.js +13 -0
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.js +1 -1
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +7 -5
- package/dist/cjs/globalization/labels/common/I18N_COMMON.js +2 -0
- package/dist/cjs/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
- package/dist/cjs/globalization/labels/filters/I18N_FILTER.js +6 -0
- package/dist/cjs/globalization/labels/index.d.ts +1 -0
- package/dist/cjs/globalization/labels/index.js +1 -0
- package/dist/cjs/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
- package/dist/cjs/interfaces/format/IFormatConfig.Interface.js +2 -0
- package/dist/cjs/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
- package/dist/cjs/interfaces/format/IFormatCurrency.Interface.js +2 -0
- package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
- package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.js +2 -0
- package/dist/cjs/interfaces/format/index.d.ts +3 -0
- package/dist/cjs/interfaces/format/index.js +15 -0
- package/dist/cjs/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
- package/dist/cjs/interfaces/index.d.ts +1 -0
- package/dist/cjs/interfaces/index.js +1 -0
- package/dist/cjs/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
- package/dist/cjs/qrvey/helpers/getValueWithSuffixes.js +23 -0
- package/dist/cjs/qrvey/helpers/index.d.ts +2 -0
- package/dist/cjs/qrvey/helpers/index.js +2 -0
- package/dist/cjs/qrvey/helpers/transformValue.d.ts +8 -0
- package/dist/cjs/qrvey/helpers/transformValue.js +46 -0
- package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
- package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.js +2 -0
- package/dist/cjs/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
- package/dist/cjs/qrvey/interfaces/ITransformValueSettings.js +2 -0
- package/dist/cjs/qrvey/interfaces/index.d.ts +2 -0
- package/dist/cjs/qrvey/interfaces/index.js +2 -0
- package/dist/cjs/services/api/getDatasetColumns.api.js +5 -1
- package/dist/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -0
- package/dist/filters/helpers/ui/index.d.ts +1 -0
- package/dist/filters/helpers/ui/index.js +1 -0
- package/dist/filters/helpers/ui/transformFilterValues.d.ts +4 -0
- package/dist/filters/helpers/ui/transformFilterValues.js +18 -0
- package/dist/filters/interfaces/builder/IFilterBuilderGeneralConfig.d.ts +1 -0
- package/dist/filters/interfaces/panel/IFilterPanelConfig.d.ts +1 -0
- package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
- package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.js +1 -0
- package/dist/filters/interfaces/ui/index.d.ts +3 -2
- package/dist/filters/interfaces/ui/index.js +3 -2
- package/dist/format/definition.d.ts +17 -0
- package/dist/format/definition.js +30 -0
- package/dist/format/format.d.ts +2 -1
- package/dist/format/format.js +6 -3
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.js +1 -0
- package/dist/format/localization.d.ts +3 -0
- package/dist/format/localization.js +51 -0
- package/dist/globalization/helpers/getI18nCalendar.d.ts +4 -0
- package/dist/globalization/helpers/getI18nCalendar.js +65 -0
- package/dist/globalization/helpers/index.d.ts +1 -0
- package/dist/globalization/helpers/index.js +1 -0
- package/dist/globalization/interfaces/calendar/II18nCalendar.d.ts +7 -0
- package/dist/globalization/interfaces/calendar/II18nCalendar.js +1 -0
- package/dist/globalization/interfaces/calendar/II18nCalendarProperties.d.ts +9 -0
- package/dist/globalization/interfaces/calendar/II18nCalendarProperties.js +1 -0
- package/dist/globalization/interfaces/calendar/index.d.ts +2 -0
- package/dist/globalization/interfaces/calendar/index.js +2 -0
- package/dist/globalization/interfaces/chart_builder/II18nChartBuilderFontOptions.d.ts +5 -3
- package/dist/globalization/interfaces/common/II18nCommon.d.ts +2 -0
- package/dist/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
- package/dist/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
- package/dist/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
- package/dist/globalization/interfaces/filters/II18nTokenBox.js +1 -0
- package/dist/globalization/interfaces/index.d.ts +1 -0
- package/dist/globalization/interfaces/index.js +1 -0
- package/dist/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
- package/dist/globalization/labels/calendar/I18N_CALENDAR.js +7 -0
- package/dist/globalization/labels/calendar/index.d.ts +1 -0
- package/dist/globalization/labels/calendar/index.js +1 -0
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.js +1 -1
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +7 -5
- package/dist/globalization/labels/common/I18N_COMMON.js +2 -0
- package/dist/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
- package/dist/globalization/labels/filters/I18N_FILTER.js +6 -0
- package/dist/globalization/labels/index.d.ts +1 -0
- package/dist/globalization/labels/index.js +1 -0
- package/dist/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
- package/dist/interfaces/format/IFormatConfig.Interface.js +1 -0
- package/dist/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
- package/dist/interfaces/format/IFormatCurrency.Interface.js +1 -0
- package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
- package/dist/interfaces/format/IFormatOutputFormat.Interface.js +1 -0
- package/dist/interfaces/format/index.d.ts +3 -0
- package/dist/interfaces/format/index.js +3 -0
- package/dist/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
- package/dist/qrvey/helpers/getValueWithSuffixes.js +19 -0
- package/dist/qrvey/helpers/index.d.ts +2 -0
- package/dist/qrvey/helpers/index.js +2 -0
- package/dist/qrvey/helpers/transformValue.d.ts +8 -0
- package/dist/qrvey/helpers/transformValue.js +42 -0
- package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
- package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.js +1 -0
- package/dist/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
- package/dist/qrvey/interfaces/ITransformValueSettings.js +1 -0
- package/dist/qrvey/interfaces/index.d.ts +2 -0
- package/dist/qrvey/interfaces/index.js +2 -0
- package/dist/services/api/getDatasetColumns.api.js +5 -1
- package/package.json +1 -1
- package/src/filters/helpers/builder/getFilterBuilderGeneralConfig.ts +1 -0
- package/src/filters/helpers/ui/index.ts +1 -0
- package/src/filters/helpers/ui/transformFilterValues.ts +29 -0
- package/src/filters/interfaces/builder/IFilterBuilderGeneralConfig.ts +2 -1
- package/src/filters/interfaces/panel/IFilterPanelConfig.ts +1 -0
- package/src/filters/interfaces/ui/IFUTransformFilterValuesSettings.ts +7 -0
- package/src/filters/interfaces/ui/index.ts +3 -2
- package/src/format/definition.ts +45 -0
- package/src/format/format.ts +19 -15
- package/src/format/index.ts +1 -0
- package/src/format/localization.ts +52 -0
- package/src/globalization/helpers/getI18nCalendar.ts +68 -0
- package/src/globalization/helpers/index.ts +1 -0
- package/src/globalization/interfaces/calendar/II18nCalendar.ts +7 -0
- package/src/globalization/interfaces/calendar/II18nCalendarProperties.ts +9 -0
- package/src/globalization/interfaces/calendar/index.ts +2 -0
- package/src/globalization/interfaces/chart_builder/II18nChartBuilderFontOptions.ts +5 -3
- package/src/globalization/interfaces/common/II18nCommon.ts +2 -0
- package/src/globalization/interfaces/common/II18nDayNames.ts +8 -0
- package/src/globalization/interfaces/filters/II18nFilter.ts +2 -0
- package/src/globalization/interfaces/filters/II18nTokenBox.ts +6 -0
- package/src/globalization/interfaces/index.ts +1 -0
- package/src/globalization/labels/calendar/I18N_CALENDAR.ts +9 -0
- package/src/globalization/labels/calendar/index.ts +1 -0
- package/src/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.ts +1 -1
- package/src/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.ts +8 -6
- package/src/globalization/labels/common/I18N_COMMON.ts +2 -0
- package/src/globalization/labels/common/I18N_DAY_NAMES.ts +8 -0
- package/src/globalization/labels/filters/I18N_FILTER.ts +6 -0
- package/src/globalization/labels/index.ts +1 -0
- package/src/interfaces/format/IFormatConfig.Interface.ts +5 -0
- package/src/interfaces/format/IFormatCurrency.Interface.ts +4 -0
- package/src/interfaces/format/IFormatOutputFormat.Interface.ts +9 -0
- package/src/interfaces/format/index.ts +3 -0
- package/src/interfaces/general/IGeneralWidgetConfig.ts +2 -0
- package/src/interfaces/index.ts +1 -0
- package/src/qrvey/helpers/getValueWithSuffixes.ts +19 -0
- package/src/qrvey/helpers/index.ts +2 -0
- package/src/qrvey/helpers/transformValue.ts +47 -0
- package/src/qrvey/interfaces/IGetValueWithSuffixesSettings.ts +12 -0
- package/src/qrvey/interfaces/ITransformValueSettings.ts +12 -0
- package/src/qrvey/interfaces/index.ts +2 -0
- package/src/services/api/getDatasetColumns.api.ts +4 -1
- package/test/columns/isNumericalColumn.test.js +154 -0
- package/test/format.test.js +11 -11
|
@@ -19,7 +19,8 @@ export * from './IFUDataset';
|
|
|
19
19
|
export * from './IFUFilter';
|
|
20
20
|
export * from './IFUFilterExtras';
|
|
21
21
|
export * from './IFUFlattenedFilter';
|
|
22
|
-
export * from './IFUScope';
|
|
23
22
|
export * from './IFUParamsToGetFilter';
|
|
24
|
-
export * from './
|
|
23
|
+
export * from './IFUScope';
|
|
24
|
+
export * from './IFUTransformFilterValuesSettings';
|
|
25
25
|
export * from './IFUUIValueSettings';
|
|
26
|
+
export * from './IFUValue';
|
package/src/format/definition.ts
CHANGED
|
@@ -55,3 +55,48 @@ export function supportNumericFormatting(chartType: ChartType): boolean {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export const isTextColumn = (column: any): boolean => textFields.includes(column.type) || column.formulaType === 'string' || column.formulaType === 'boolean';
|
|
58
|
+
|
|
59
|
+
export const currencyISO = [
|
|
60
|
+
{ text: 'Default', label: 'USD' },
|
|
61
|
+
{ text: '$ (USD)', label: 'USD' },
|
|
62
|
+
{ text: '€ (EUR)', label: 'EUR' },
|
|
63
|
+
{ text: '¥ (JPY)', label: 'JPY' },
|
|
64
|
+
{ text: '£ (GBP)', label: 'GBP' },
|
|
65
|
+
{ text: '₩ (WON)', label: 'WON' },
|
|
66
|
+
{ text: '$ (AUD)', label: 'AUD' },
|
|
67
|
+
{ text: '$ (CAD)', label: 'CAD' },
|
|
68
|
+
{ text: 'CHF (CHF)', label: 'CHF' },
|
|
69
|
+
{ text: '¥ (CNY)', label: 'CNY' },
|
|
70
|
+
{ text: 'kr (SEK)', label: 'SEK' },
|
|
71
|
+
{ text: '$ (MXN)', label: 'MXN' },
|
|
72
|
+
{ text: '$ (NZD)', label: 'NZD' },
|
|
73
|
+
{ text: '$ (SGD)', label: 'SGD' },
|
|
74
|
+
{ text: '$ (HKD)', label: 'HKD' },
|
|
75
|
+
{ text: 'kr (NOK)', label: 'NOK' },
|
|
76
|
+
{ text: '₩ (KRW)', label: 'KRW' },
|
|
77
|
+
{ text: '₺ (TRY)', label: 'TRY' },
|
|
78
|
+
{ text: '₹ (INR)', label: 'INR' },
|
|
79
|
+
{ text: '₽ (RUB)', label: 'RUB' },
|
|
80
|
+
{ text: 'R$ (BRL)', label: 'BRL' },
|
|
81
|
+
{ text: 'R (ZAR)', label: 'ZAR' },
|
|
82
|
+
{ text: 'kr (DKK)', label: 'DKK' },
|
|
83
|
+
{ text: 'zł (PLN)', label: 'PLN' },
|
|
84
|
+
{ text: 'NT$ (TWD)', label: 'TWD' },
|
|
85
|
+
{ text: '฿ (THB)', label: 'THB' },
|
|
86
|
+
{ text: 'RM (MYR)', label: 'MYR' }
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
export const enum LOCALE_FORMATS {
|
|
90
|
+
DECIMAL = 'Decimal',
|
|
91
|
+
CURRENCY = 'Currency',
|
|
92
|
+
PERCENTAGE = 'Percentage',
|
|
93
|
+
SCIENTIFIC = 'Scientific',
|
|
94
|
+
}
|
|
95
|
+
export const enum LOCALE_STYLES {
|
|
96
|
+
DECIMAL = 'decimal',
|
|
97
|
+
PERCENT = 'percent',
|
|
98
|
+
CURRENCY = 'currency',
|
|
99
|
+
SCIENTIFIC = 'scientific',
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const LANG_DEFAULT = 'en-US';
|
package/src/format/format.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { isEmpty } from '../general/mix/isEmpty';
|
|
|
6
6
|
import { _get } from '../general/object/get';
|
|
7
7
|
import { COLUMN } from '../columns/constants/COLUMN';
|
|
8
8
|
import { FORMULA } from '../formulas/constants/FORMULA';
|
|
9
|
+
import { IFormatConfig } from '..';
|
|
10
|
+
import { formatWithLocale } from './localization';
|
|
9
11
|
|
|
10
12
|
dayjs.extend(advancedFormat); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
|
|
11
13
|
|
|
@@ -82,22 +84,24 @@ export function formatFileSize(bytes: number): string {
|
|
|
82
84
|
return megaBytes < 10 ? `${fixDecimals(megaBytes)} MB` : `${Math.round(megaBytes)} MB`;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
export const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case 'FILEUPLOAD':
|
|
97
|
-
return formatFileSize(parseFloat(value));
|
|
98
|
-
default:
|
|
99
|
-
return typeof value === 'number' ? value.toFixed(0) : value;
|
|
87
|
+
export const addFormat = (value: any, outputFormat: any = 'None', config?: IFormatConfig): any => {
|
|
88
|
+
if (isEmpty(value) || typeof value === 'object' && isEmpty(value[0])) return value;
|
|
89
|
+
switch (outputFormat.type) {
|
|
90
|
+
case 'DATE':
|
|
91
|
+
case 'DATETIME':
|
|
92
|
+
return config?.lang && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, outputFormat.format);
|
|
93
|
+
case 'NUMERIC': {
|
|
94
|
+
const parse = parseFloat(value);
|
|
95
|
+
const withLocale = outputFormat.format !== 'Abbreviated' && outputFormat !== 'None' && config?.lang;
|
|
96
|
+
return isNaN(parse) ? value : withLocale ? formatWithLocale(value, outputFormat, config)
|
|
97
|
+
: formatNumber(parse, outputFormat, config);
|
|
100
98
|
}
|
|
99
|
+
case 'IMAGEUPLOAD':
|
|
100
|
+
case 'FILEUPLOAD':
|
|
101
|
+
return formatFileSize(parseFloat(value));
|
|
102
|
+
default:
|
|
103
|
+
return typeof value === 'number' ? value.toFixed(0) : value;
|
|
104
|
+
}
|
|
101
105
|
};
|
|
102
106
|
|
|
103
107
|
export const parseFormulaType = (type: string) => {
|
package/src/format/index.ts
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IFormatConfig, IFormatOutputFormat } from '../interfaces';
|
|
2
|
+
import { currencyISO, LOCALE_FORMATS, LOCALE_STYLES, LANG_DEFAULT } from './definition';
|
|
3
|
+
|
|
4
|
+
export const getLang = (locale: string | Record<string, any>) => {
|
|
5
|
+
if (!locale) return;
|
|
6
|
+
else if(typeof locale === 'object') return locale;
|
|
7
|
+
else return { lang: locale === "browser" ? window.navigator.language : locale };
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig = {}): any => {
|
|
11
|
+
switch (outputFormat.type) {
|
|
12
|
+
case 'DATE':
|
|
13
|
+
case 'DATETIME':
|
|
14
|
+
return formatLocaleDate(value, config);
|
|
15
|
+
case 'NUMERIC':
|
|
16
|
+
return formatLocaleNumber(value, outputFormat, config);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function formatLocaleDate(value: any, config: IFormatConfig) {
|
|
21
|
+
const { lang = LANG_DEFAULT, options } = config;
|
|
22
|
+
const dateParam = new Date(value);
|
|
23
|
+
try {
|
|
24
|
+
return new Intl.DateTimeFormat([lang, LANG_DEFAULT], options).format(dateParam);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return new Intl.DateTimeFormat(LANG_DEFAULT, options).format(dateParam);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
|
|
31
|
+
const { lang = LANG_DEFAULT, options } = config;
|
|
32
|
+
const langOpts = options || getLocaleOptions(outputFormat);
|
|
33
|
+
try {
|
|
34
|
+
return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(value);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getLocaleOptions(outputFormat: IFormatOutputFormat) {
|
|
41
|
+
const { format, decimals, currency, backup_currency } = outputFormat;
|
|
42
|
+
switch(format) {
|
|
43
|
+
case LOCALE_FORMATS.CURRENCY: {
|
|
44
|
+
const iso = currencyISO.find(item => item.text === (currency.text || backup_currency.text));
|
|
45
|
+
return { style: LOCALE_STYLES.CURRENCY, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: 0 };
|
|
46
|
+
}
|
|
47
|
+
case LOCALE_FORMATS.SCIENTIFIC: return { style: LOCALE_STYLES.DECIMAL,
|
|
48
|
+
notation: LOCALE_STYLES.SCIENTIFIC, maximumFractionDigits: decimals };
|
|
49
|
+
case LOCALE_FORMATS.PERCENTAGE: return { style: LOCALE_STYLES.PERCENT, maximumFractionDigits: decimals };
|
|
50
|
+
default: return { style: LOCALE_STYLES.DECIMAL, maximumFractionDigits: decimals };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { II18nCalendarProperties } from "../interfaces/calendar/II18nCalendarProperties";
|
|
2
|
+
import { II18nServiceTranslate } from "../interfaces/II18nServiceTranslate";
|
|
3
|
+
import { I18nService } from "../service/i18nextBuilder";
|
|
4
|
+
|
|
5
|
+
export function getI18nCalendar(locale: I18nService | II18nServiceTranslate): II18nCalendarProperties {
|
|
6
|
+
const localeOverride = locale instanceof I18nService ? locale : typeof locale === 'function' ? { translate: locale } : undefined;
|
|
7
|
+
if (!localeOverride) return undefined;
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
clear: localeOverride.translate('common.calendar.clear'),
|
|
11
|
+
days: [
|
|
12
|
+
localeOverride.translate('common.day_names.sunday_dddd'),
|
|
13
|
+
localeOverride.translate('common.day_names.monday_dddd'),
|
|
14
|
+
localeOverride.translate('common.day_names.tuesday_dddd'),
|
|
15
|
+
localeOverride.translate('common.day_names.wednesday_dddd'),
|
|
16
|
+
localeOverride.translate('common.day_names.thursday_dddd'),
|
|
17
|
+
localeOverride.translate('common.day_names.friday_dddd'),
|
|
18
|
+
localeOverride.translate('common.day_names.saturday_dddd')
|
|
19
|
+
],
|
|
20
|
+
daysMin: [
|
|
21
|
+
localeOverride.translate('common.day_names.sunday_dd'),
|
|
22
|
+
localeOverride.translate('common.day_names.monday_dd'),
|
|
23
|
+
localeOverride.translate('common.day_names.tuesday_dd'),
|
|
24
|
+
localeOverride.translate('common.day_names.wednesday_dd'),
|
|
25
|
+
localeOverride.translate('common.day_names.thursday_dd'),
|
|
26
|
+
localeOverride.translate('common.day_names.friday_dd'),
|
|
27
|
+
localeOverride.translate('common.day_names.saturday_dd')
|
|
28
|
+
],
|
|
29
|
+
daysShort: [
|
|
30
|
+
localeOverride.translate('common.day_names.sunday_ddd'),
|
|
31
|
+
localeOverride.translate('common.day_names.monday_ddd'),
|
|
32
|
+
localeOverride.translate('common.day_names.tuesday_ddd'),
|
|
33
|
+
localeOverride.translate('common.day_names.wednesday_ddd'),
|
|
34
|
+
localeOverride.translate('common.day_names.thursday_ddd'),
|
|
35
|
+
localeOverride.translate('common.day_names.friday_ddd'),
|
|
36
|
+
localeOverride.translate('common.day_names.saturday_ddd')
|
|
37
|
+
],
|
|
38
|
+
months: [
|
|
39
|
+
localeOverride.translate('common.date_grouping.january_mmmm'),
|
|
40
|
+
localeOverride.translate('common.date_grouping.february_mmmm'),
|
|
41
|
+
localeOverride.translate('common.date_grouping.march_mmmm'),
|
|
42
|
+
localeOverride.translate('common.date_grouping.april_mmmm'),
|
|
43
|
+
localeOverride.translate('common.date_grouping.may_mmmm'),
|
|
44
|
+
localeOverride.translate('common.date_grouping.june_mmmm'),
|
|
45
|
+
localeOverride.translate('common.date_grouping.july_mmmm'),
|
|
46
|
+
localeOverride.translate('common.date_grouping.august_mmmm'),
|
|
47
|
+
localeOverride.translate('common.date_grouping.september_mmmm'),
|
|
48
|
+
localeOverride.translate('common.date_grouping.october_mmmm'),
|
|
49
|
+
localeOverride.translate('common.date_grouping.november_mmmm'),
|
|
50
|
+
localeOverride.translate('common.date_grouping.december_mmmm')
|
|
51
|
+
],
|
|
52
|
+
monthsShort: [
|
|
53
|
+
localeOverride.translate('common.date_grouping.january_mmm'),
|
|
54
|
+
localeOverride.translate('common.date_grouping.february_mmm'),
|
|
55
|
+
localeOverride.translate('common.date_grouping.march_mmm'),
|
|
56
|
+
localeOverride.translate('common.date_grouping.april_mmm'),
|
|
57
|
+
localeOverride.translate('common.date_grouping.may_mmm'),
|
|
58
|
+
localeOverride.translate('common.date_grouping.june_mmm'),
|
|
59
|
+
localeOverride.translate('common.date_grouping.july_mmm'),
|
|
60
|
+
localeOverride.translate('common.date_grouping.august_mmm'),
|
|
61
|
+
localeOverride.translate('common.date_grouping.september_mmm'),
|
|
62
|
+
localeOverride.translate('common.date_grouping.october_mmm'),
|
|
63
|
+
localeOverride.translate('common.date_grouping.november_mmm'),
|
|
64
|
+
localeOverride.translate('common.date_grouping.december_mmm')
|
|
65
|
+
],
|
|
66
|
+
today: localeOverride.translate('common.calendar.today')
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export interface II18nChartBuilderFontOptions {
|
|
2
|
+
automatic_resize: string;
|
|
2
3
|
color: string;
|
|
4
|
+
disabled: string;
|
|
5
|
+
select_option_placeholder: string;
|
|
6
|
+
size: string;
|
|
3
7
|
style: string;
|
|
4
|
-
style_regular: string;
|
|
5
8
|
style_bold: string;
|
|
6
9
|
style_italic: string;
|
|
7
|
-
|
|
8
|
-
size: string;
|
|
10
|
+
style_regular: string;
|
|
9
11
|
}
|
|
@@ -5,9 +5,11 @@ import { II18nColumnTypesSuffixes } from "./II18nColumnTypesSuffixes";
|
|
|
5
5
|
import { II18nDateGrouping } from "./II18nDateGrouping";
|
|
6
6
|
import { II18nDayNames } from "./II18nDayNames";
|
|
7
7
|
import { II18nUnits } from "./II18nUnits";
|
|
8
|
+
import { II18nCalendar } from "../calendar/II18nCalendar";
|
|
8
9
|
|
|
9
10
|
export interface II18nCommon {
|
|
10
11
|
aggregate_labels: II18nAgreggateLabels;
|
|
12
|
+
calendar: II18nCalendar;
|
|
11
13
|
column_types: II18nColumnTypes;
|
|
12
14
|
column_types_suffixes: II18nColumnTypesSuffixes;
|
|
13
15
|
date_grouping: II18nDateGrouping;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export interface II18nDayNames {
|
|
2
|
+
sunday_dd: string;
|
|
3
|
+
monday_dd: string;
|
|
4
|
+
tuesday_dd: string;
|
|
5
|
+
wednesday_dd: string;
|
|
6
|
+
thursday_dd: string;
|
|
7
|
+
friday_dd: string;
|
|
8
|
+
saturday_dd: string;
|
|
9
|
+
|
|
2
10
|
sunday_ddd: string;
|
|
3
11
|
monday_ddd: string;
|
|
4
12
|
tuesday_ddd: string;
|
|
@@ -7,6 +7,7 @@ import { II18nFilterOperator } from "./II18nFilterOperator";
|
|
|
7
7
|
import { II18nFilterScopes } from "./II18nFilterScopes";
|
|
8
8
|
import { II18nFilterPanelScopeTitle } from "./II18nFilterPanelScopeTitle";
|
|
9
9
|
import { II18nFilterDateSections } from "./II18nFilterDateSections";
|
|
10
|
+
import { II18nTokenBox } from './II18nTokenBox';
|
|
10
11
|
|
|
11
12
|
export interface II18nFilter {
|
|
12
13
|
date_sections: II18nFilterDateSections;
|
|
@@ -16,6 +17,7 @@ export interface II18nFilter {
|
|
|
16
17
|
scope_title: II18nFilterPanelScopeTitle;
|
|
17
18
|
scopes: II18nFilterScopes;
|
|
18
19
|
slidebar: II18nSlidebar;
|
|
20
|
+
token_box?: II18nTokenBox;
|
|
19
21
|
validators: II18nFilterValidator;
|
|
20
22
|
value_container: II18nValueContainer;
|
|
21
23
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './I18N_CALENDAR';
|
|
@@ -3,7 +3,7 @@ import { II18nChartBuilder } from "../..";
|
|
|
3
3
|
type LayerOptions = 'trends_line' | 'references_line';
|
|
4
4
|
export const I18N_CHART_BUILDER_LAYER_OPTIONS: Pick<II18nChartBuilder, LayerOptions> = {
|
|
5
5
|
trends_line: {
|
|
6
|
-
title: '
|
|
6
|
+
title: 'Trend Line',
|
|
7
7
|
type: 'Type',
|
|
8
8
|
type_none: 'None',
|
|
9
9
|
type_standard_linear_regression: 'Standard Linear Regression',
|
|
@@ -19,9 +19,9 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
|
|
|
19
19
|
comparision_color: 'Comparision Color',
|
|
20
20
|
data_labels_check: 'Data Labels',
|
|
21
21
|
default_format_title: 'Format',
|
|
22
|
-
display_outliers_check: 'Display
|
|
22
|
+
display_outliers_check: 'Display Outliers',
|
|
23
23
|
line_opacity: 'Line Opacity',
|
|
24
|
-
map_borders: 'Map
|
|
24
|
+
map_borders: 'Map Borders',
|
|
25
25
|
needle_color: 'Needle Color',
|
|
26
26
|
opacity: 'Opacity',
|
|
27
27
|
percentage_check: 'Percentage',
|
|
@@ -156,13 +156,15 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
|
|
|
156
156
|
names_rotation: 'Names Rotation',
|
|
157
157
|
},
|
|
158
158
|
font_options: {
|
|
159
|
+
automatic_resize: 'Automatic Resize',
|
|
159
160
|
color: 'Font Color',
|
|
161
|
+
disabled: '<i>Automatic Resize</i> is active, disable it to set the size manually.',
|
|
162
|
+
select_option_placeholder: 'Select Option',
|
|
163
|
+
size: 'Font Size',
|
|
160
164
|
style: 'Font Style',
|
|
161
|
-
style_regular: 'Regular',
|
|
162
165
|
style_bold: 'Bold',
|
|
163
166
|
style_italic: 'Italic',
|
|
164
|
-
|
|
165
|
-
size: 'Font Size',
|
|
167
|
+
style_regular: 'Regular',
|
|
166
168
|
},
|
|
167
169
|
circle_size: {
|
|
168
170
|
title: 'Circle Size',
|
|
@@ -186,7 +188,7 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
|
|
|
186
188
|
target_value: 'Target Value'
|
|
187
189
|
},
|
|
188
190
|
table_style_options: {
|
|
189
|
-
typeface: 'Typeface',
|
|
191
|
+
typeface: 'Typeface',
|
|
190
192
|
weight: 'Weight',
|
|
191
193
|
weight_bold: 'Bold',
|
|
192
194
|
weight_normal: 'normal',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RELATIVE_UNIT_INFO } from "../../../dates/relative/constants/RELATIVE_UNIT_INFO";
|
|
2
2
|
import { II18nCommon } from "../../interfaces/common/II18nCommon";
|
|
3
|
+
import { I18N_CALENDAR } from "../calendar";
|
|
3
4
|
import { I18N_AGGREGATE_LABEL } from "./I18N_AGGREGATE_LABEL";
|
|
4
5
|
import { I18N_COLUMN_LABEL } from "./I18N_COLUMN_LABEL";
|
|
5
6
|
import { I18N_COLUMN_PROPERTY_LABEL } from "./I18N_COLUMN_PROPERTY_LABEL";
|
|
@@ -8,6 +9,7 @@ import { I18N_DAY_NAMES } from "./I18N_DAY_NAMES";
|
|
|
8
9
|
|
|
9
10
|
export const I18N_COMMON: II18nCommon = {
|
|
10
11
|
aggregate_labels: I18N_AGGREGATE_LABEL,
|
|
12
|
+
calendar: I18N_CALENDAR,
|
|
11
13
|
column_types: I18N_COLUMN_LABEL,
|
|
12
14
|
column_types_suffixes: {
|
|
13
15
|
slidebar_one: 'Step',
|
|
@@ -4,6 +4,14 @@ import { capitalize } from "../../../general/string/capitalize";
|
|
|
4
4
|
import { II18nDayNames } from "../../interfaces/common/II18nDayNames";
|
|
5
5
|
|
|
6
6
|
export const I18N_DAY_NAMES: II18nDayNames = {
|
|
7
|
+
sunday_dd: capitalize(DATE_WEEK_DAYS[0].substring(0, 2)),
|
|
8
|
+
monday_dd: capitalize(DATE_WEEK_DAYS[1].substring(0, 2)),
|
|
9
|
+
tuesday_dd: capitalize(DATE_WEEK_DAYS[2].substring(0, 2)),
|
|
10
|
+
wednesday_dd: capitalize(DATE_WEEK_DAYS[3].substring(0, 2)),
|
|
11
|
+
thursday_dd: capitalize(DATE_WEEK_DAYS[4].substring(0, 2)),
|
|
12
|
+
friday_dd: capitalize(DATE_WEEK_DAYS[5].substring(0, 2)),
|
|
13
|
+
saturday_dd: capitalize(DATE_WEEK_DAYS[6].substring(0, 2)),
|
|
14
|
+
|
|
7
15
|
sunday_ddd: capitalize(DATE_WEEK_DAYS[0]),
|
|
8
16
|
monday_ddd: capitalize(DATE_WEEK_DAYS[1]),
|
|
9
17
|
tuesday_ddd: capitalize(DATE_WEEK_DAYS[2]),
|
|
@@ -28,6 +28,12 @@ export const I18N_FILTER: II18nFilter = {
|
|
|
28
28
|
},
|
|
29
29
|
scopes: I18N_FILTER_SCOPE,
|
|
30
30
|
slidebar: I18N_SLIDEBAR,
|
|
31
|
+
token_box: {
|
|
32
|
+
data_tokens: 'DataTokens',
|
|
33
|
+
search: 'Search',
|
|
34
|
+
system_tokens: 'SystemTokens',
|
|
35
|
+
user_tokens: 'UserTokens',
|
|
36
|
+
},
|
|
31
37
|
validators: I18N_FILTER_VALIDATOR,
|
|
32
38
|
value_container: I18N_VALUE_CONTAINER,
|
|
33
39
|
};
|
package/src/interfaces/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isNaNV2 } from "../../general/mix/isNaNV2";
|
|
3
|
+
import { IGetValueWithSuffixesSettings } from "../interfaces/IGetValueWithSuffixesSettings";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get a string value with suffixes if available.
|
|
7
|
+
* Add suffix into the value string. Prioritized for numeric values.
|
|
8
|
+
* @param value a number or string
|
|
9
|
+
* @param suffixes An object with singular or plural suffix string.
|
|
10
|
+
* @returns a string value with suffix
|
|
11
|
+
*/
|
|
12
|
+
export function getValueWithSuffixes(value: string | number, settings: IGetValueWithSuffixesSettings): string {
|
|
13
|
+
let suffix = '';
|
|
14
|
+
if (!isNaNV2(value)) {
|
|
15
|
+
if (!isEmpty(settings.suffixTranslateLabel) && !isEmpty(settings.translate)) suffix = settings.translate(settings.suffixTranslateLabel, { count: +value });
|
|
16
|
+
if (!isEmpty(settings.suffixes)) suffix = (+value > 1 || +value === 0) ? settings.suffixes.plural : settings.suffixes.singular;
|
|
17
|
+
}
|
|
18
|
+
return value + (!isEmpty(suffix) ? ' ' + suffix : '');
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isDateColumn } from "../../columns/helpers/isDateColumn";
|
|
2
|
+
import { isNumericalColumn } from "../../columns/helpers/isNumericalColumn";
|
|
3
|
+
import { IDateColumnPropertyType } from "../../columns/interfaces/IDateColumnPropertyType";
|
|
4
|
+
import { DATE_GROUPING_PROPERTY } from "../../dates/constants/DATE_GROUPING_PROPERTY";
|
|
5
|
+
import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
|
|
6
|
+
import { addFormat } from "../../format/format";
|
|
7
|
+
import { getI18nDateGroupLabel } from "../../globalization/helpers/getI18nDateGroupLabel";
|
|
8
|
+
import { ITransformValueSettings } from "../interfaces/ITransformValueSettings";
|
|
9
|
+
import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Transforms a value depending of localization/globalization and extras settings.
|
|
13
|
+
* @param value A value to transform
|
|
14
|
+
* @param settings The settings of the transformValue function
|
|
15
|
+
* @returns A transformed value
|
|
16
|
+
*/
|
|
17
|
+
export function transformValue(value: string, settings: ITransformValueSettings): string {
|
|
18
|
+
const valueWithI18n = getI18nDateGroupLabel(value, settings.property as IDateColumnPropertyType, settings.translate);
|
|
19
|
+
|
|
20
|
+
const valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|
|
21
|
+
return getValueWithSuffixes(valueWithLocalization, { suffixTranslateLabel: settings.suffixTranslateLabel, translate: settings.translate });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gets the outputformat settings
|
|
26
|
+
* @param settings The settings of the transformValue function
|
|
27
|
+
* @returns the outputformat settings
|
|
28
|
+
*/
|
|
29
|
+
function getOutputFormat(settings: ITransformValueSettings) {
|
|
30
|
+
let type, format;
|
|
31
|
+
if (isDateColumn(settings.column) && [DATE_GROUPING_PROPERTY.DAY, DATE_GROUPING_TIME_PROPERTY.HOUR, DATE_GROUPING_TIME_PROPERTY.MINUTE, DATE_GROUPING_TIME_PROPERTY.SECOND].includes(settings.property as any)) {
|
|
32
|
+
type = 'DATE';
|
|
33
|
+
format = 'Default';
|
|
34
|
+
} else if (isNumericalColumn(settings.column)) {
|
|
35
|
+
type = 'NUMERIC';
|
|
36
|
+
}
|
|
37
|
+
return { type, format };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets the format config
|
|
42
|
+
* @param settings The settings of the transformValue function
|
|
43
|
+
* @returns the format config
|
|
44
|
+
*/
|
|
45
|
+
function getFormatConfig(settings: ITransformValueSettings) {
|
|
46
|
+
return { lang: settings.locale };
|
|
47
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { II18nServiceTranslate } from "../../globalization/interfaces/II18nServiceTranslate";
|
|
2
|
+
|
|
3
|
+
export interface IGetValueWithSuffixesSettings {
|
|
4
|
+
translate?: II18nServiceTranslate; // Function for getting translations
|
|
5
|
+
suffixTranslateLabel?: string; // Label of the i18n path for translations
|
|
6
|
+
suffixes?: IGetValueWithSuffixesSettingsSuffixes; // Manual suffixes to add if the translate and the suffixes translate label is not present
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface IGetValueWithSuffixesSettingsSuffixes {
|
|
10
|
+
singular: string;
|
|
11
|
+
plural: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IColumn } from "../../columns/interfaces/IColumn";
|
|
2
|
+
import { IColumnPropertyType } from "../../columns/interfaces/IColumnPropertyType";
|
|
3
|
+
import { II18nServiceTranslate } from "../../globalization/interfaces/II18nServiceTranslate";
|
|
4
|
+
|
|
5
|
+
export interface ITransformValueSettings {
|
|
6
|
+
column: IColumn;
|
|
7
|
+
property: IColumnPropertyType;
|
|
8
|
+
|
|
9
|
+
translate: II18nServiceTranslate; // Function for getting translations
|
|
10
|
+
locale: string; // The locale string
|
|
11
|
+
suffixTranslateLabel?: string // The i18n label for the suffix values.
|
|
12
|
+
}
|
|
@@ -3,6 +3,8 @@ import { IDataset } from "../../qrvey/interfaces/IDataset";
|
|
|
3
3
|
import { CHART_ENDPOINT } from "../constants/CHART_ENDPOINT";
|
|
4
4
|
import Request from "../helpers/Request";
|
|
5
5
|
import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter";
|
|
6
|
+
import { LANG_DEFAULT } from "../../format/definition";
|
|
7
|
+
import { getLang } from "../..";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Get a dataset by Qrvey ID
|
|
@@ -10,10 +12,11 @@ import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter
|
|
|
10
12
|
* @returns a promise
|
|
11
13
|
*/
|
|
12
14
|
export function getDatasetColumns(config: IGeneralWidgetConfig, qrveyid?: string): Promise<IDataset[]> {
|
|
15
|
+
const lang = getLang(config.lang || (<any>config.locale)?.lang || config.locale || LANG_DEFAULT).lang;
|
|
13
16
|
return Request.post({ ...config, qrveyid, endpoint: CHART_ENDPOINT }, '/question/list', {
|
|
14
17
|
'optionsAttributes': ['id', 'text', 'type', 'property', 'linked', 'linkid', 'qrveyid', 'bucketId', 'formulaId', 'formulaType', 'geogroup', 'outputFormat'],
|
|
15
18
|
'extend': true
|
|
16
|
-
})
|
|
19
|
+
}, { lang })
|
|
17
20
|
.then(BDatasetsToUIDatasets)
|
|
18
21
|
.catch(_e => []);
|
|
19
22
|
}
|