@qrvey/utils 1.2.9-15 → 1.2.9-19
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 +214 -111
- 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 +4 -0
- package/dist/cjs/format/localization.js +65 -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/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/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 +3 -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 +4 -0
- package/dist/format/localization.js +59 -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/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/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 +3 -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 +62 -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/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/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 +3 -1
- package/test/columns/isNumericalColumn.test.js +154 -0
- package/test/format.test.js +11 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './I18N_CALENDAR';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './I18N_CALENDAR';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RELATIVE_UNIT_INFO } from "../../../dates/relative/constants/RELATIVE_UNIT_INFO";
|
|
2
|
+
import { I18N_CALENDAR } from "../calendar";
|
|
2
3
|
import { I18N_AGGREGATE_LABEL } from "./I18N_AGGREGATE_LABEL";
|
|
3
4
|
import { I18N_COLUMN_LABEL } from "./I18N_COLUMN_LABEL";
|
|
4
5
|
import { I18N_COLUMN_PROPERTY_LABEL } from "./I18N_COLUMN_PROPERTY_LABEL";
|
|
@@ -6,6 +7,7 @@ import { I18N_DATE_GROUPING } from "./I18N_DATE_GROUPING";
|
|
|
6
7
|
import { I18N_DAY_NAMES } from "./I18N_DAY_NAMES";
|
|
7
8
|
export const I18N_COMMON = {
|
|
8
9
|
aggregate_labels: I18N_AGGREGATE_LABEL,
|
|
10
|
+
calendar: I18N_CALENDAR,
|
|
9
11
|
column_types: I18N_COLUMN_LABEL,
|
|
10
12
|
column_types_suffixes: {
|
|
11
13
|
slidebar_one: 'Step',
|
|
@@ -2,6 +2,13 @@ import { DATE_WEEK_DAYS } from "../../../dates/constants/DATE_WEEK_DAYS";
|
|
|
2
2
|
import { DATE_WEEK_DAYS_DDDD } from "../../../dates/constants/DATE_WEEK_DAYS_DDDD";
|
|
3
3
|
import { capitalize } from "../../../general/string/capitalize";
|
|
4
4
|
export const I18N_DAY_NAMES = {
|
|
5
|
+
sunday_dd: capitalize(DATE_WEEK_DAYS[0].substring(0, 2)),
|
|
6
|
+
monday_dd: capitalize(DATE_WEEK_DAYS[1].substring(0, 2)),
|
|
7
|
+
tuesday_dd: capitalize(DATE_WEEK_DAYS[2].substring(0, 2)),
|
|
8
|
+
wednesday_dd: capitalize(DATE_WEEK_DAYS[3].substring(0, 2)),
|
|
9
|
+
thursday_dd: capitalize(DATE_WEEK_DAYS[4].substring(0, 2)),
|
|
10
|
+
friday_dd: capitalize(DATE_WEEK_DAYS[5].substring(0, 2)),
|
|
11
|
+
saturday_dd: capitalize(DATE_WEEK_DAYS[6].substring(0, 2)),
|
|
5
12
|
sunday_ddd: capitalize(DATE_WEEK_DAYS[0]),
|
|
6
13
|
monday_ddd: capitalize(DATE_WEEK_DAYS[1]),
|
|
7
14
|
tuesday_ddd: capitalize(DATE_WEEK_DAYS[2]),
|
|
@@ -26,6 +26,12 @@ export const I18N_FILTER = {
|
|
|
26
26
|
},
|
|
27
27
|
scopes: I18N_FILTER_SCOPE,
|
|
28
28
|
slidebar: I18N_SLIDEBAR,
|
|
29
|
+
token_box: {
|
|
30
|
+
data_tokens: 'DataTokens',
|
|
31
|
+
search: 'Search',
|
|
32
|
+
system_tokens: 'SystemTokens',
|
|
33
|
+
user_tokens: 'UserTokens',
|
|
34
|
+
},
|
|
29
35
|
validators: I18N_FILTER_VALIDATOR,
|
|
30
36
|
value_container: I18N_VALUE_CONTAINER,
|
|
31
37
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/interfaces/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IGetValueWithSuffixesSettings } from "../interfaces/IGetValueWithSuffixesSettings";
|
|
2
|
+
/**
|
|
3
|
+
* Get a string value with suffixes if available.
|
|
4
|
+
* Add suffix into the value string. Prioritized for numeric values.
|
|
5
|
+
* @param value a number or string
|
|
6
|
+
* @param suffixes An object with singular or plural suffix string.
|
|
7
|
+
* @returns a string value with suffix
|
|
8
|
+
*/
|
|
9
|
+
export declare function getValueWithSuffixes(value: string | number, settings: IGetValueWithSuffixesSettings): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
2
|
+
import { isNaNV2 } from "../../general/mix/isNaNV2";
|
|
3
|
+
/**
|
|
4
|
+
* Get a string value with suffixes if available.
|
|
5
|
+
* Add suffix into the value string. Prioritized for numeric values.
|
|
6
|
+
* @param value a number or string
|
|
7
|
+
* @param suffixes An object with singular or plural suffix string.
|
|
8
|
+
* @returns a string value with suffix
|
|
9
|
+
*/
|
|
10
|
+
export function getValueWithSuffixes(value, settings) {
|
|
11
|
+
let suffix = '';
|
|
12
|
+
if (!isNaNV2(value)) {
|
|
13
|
+
if (!isEmpty(settings.suffixTranslateLabel) && !isEmpty(settings.translate))
|
|
14
|
+
suffix = settings.translate(settings.suffixTranslateLabel, { count: +value });
|
|
15
|
+
if (!isEmpty(settings.suffixes))
|
|
16
|
+
suffix = (+value > 1 || +value === 0) ? settings.suffixes.plural : settings.suffixes.singular;
|
|
17
|
+
}
|
|
18
|
+
return value + (!isEmpty(suffix) ? ' ' + suffix : '');
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ITransformValueSettings } from "../interfaces/ITransformValueSettings";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms a value depending of localization/globalization and extras settings.
|
|
4
|
+
* @param value A value to transform
|
|
5
|
+
* @param settings The settings of the transformValue function
|
|
6
|
+
* @returns A transformed value
|
|
7
|
+
*/
|
|
8
|
+
export declare function transformValue(value: string, settings: ITransformValueSettings): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isDateColumn } from "../../columns/helpers/isDateColumn";
|
|
2
|
+
import { isNumericalColumn } from "../../columns/helpers/isNumericalColumn";
|
|
3
|
+
import { DATE_GROUPING_PROPERTY } from "../../dates/constants/DATE_GROUPING_PROPERTY";
|
|
4
|
+
import { DATE_GROUPING_TIME_PROPERTY } from "../../dates/constants/DATE_GROUPING_TIME_PROPERTY";
|
|
5
|
+
import { addFormat } from "../../format/format";
|
|
6
|
+
import { getI18nDateGroupLabel } from "../../globalization/helpers/getI18nDateGroupLabel";
|
|
7
|
+
import { getValueWithSuffixes } from "./getValueWithSuffixes";
|
|
8
|
+
/**
|
|
9
|
+
* Transforms a value depending of localization/globalization and extras settings.
|
|
10
|
+
* @param value A value to transform
|
|
11
|
+
* @param settings The settings of the transformValue function
|
|
12
|
+
* @returns A transformed value
|
|
13
|
+
*/
|
|
14
|
+
export function transformValue(value, settings) {
|
|
15
|
+
const valueWithI18n = getI18nDateGroupLabel(value, settings.property, settings.translate);
|
|
16
|
+
const valueWithLocalization = addFormat(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|
|
17
|
+
return getValueWithSuffixes(valueWithLocalization, { suffixTranslateLabel: settings.suffixTranslateLabel, translate: settings.translate });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the outputformat settings
|
|
21
|
+
* @param settings The settings of the transformValue function
|
|
22
|
+
* @returns the outputformat settings
|
|
23
|
+
*/
|
|
24
|
+
function getOutputFormat(settings) {
|
|
25
|
+
let type, format;
|
|
26
|
+
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)) {
|
|
27
|
+
type = 'DATE';
|
|
28
|
+
format = 'Default';
|
|
29
|
+
}
|
|
30
|
+
else if (isNumericalColumn(settings.column)) {
|
|
31
|
+
type = 'NUMERIC';
|
|
32
|
+
}
|
|
33
|
+
return { type, format };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the format config
|
|
37
|
+
* @param settings The settings of the transformValue function
|
|
38
|
+
* @returns the format config
|
|
39
|
+
*/
|
|
40
|
+
function getFormatConfig(settings) {
|
|
41
|
+
return { lang: settings.locale };
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { II18nServiceTranslate } from "../../globalization/interfaces/II18nServiceTranslate";
|
|
2
|
+
export interface IGetValueWithSuffixesSettings {
|
|
3
|
+
translate?: II18nServiceTranslate;
|
|
4
|
+
suffixTranslateLabel?: string;
|
|
5
|
+
suffixes?: IGetValueWithSuffixesSettingsSuffixes;
|
|
6
|
+
}
|
|
7
|
+
interface IGetValueWithSuffixesSettingsSuffixes {
|
|
8
|
+
singular: string;
|
|
9
|
+
plural: string;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IColumn } from "../../columns/interfaces/IColumn";
|
|
2
|
+
import { IColumnPropertyType } from "../../columns/interfaces/IColumnPropertyType";
|
|
3
|
+
import { II18nServiceTranslate } from "../../globalization/interfaces/II18nServiceTranslate";
|
|
4
|
+
export interface ITransformValueSettings {
|
|
5
|
+
column: IColumn;
|
|
6
|
+
property: IColumnPropertyType;
|
|
7
|
+
translate: II18nServiceTranslate;
|
|
8
|
+
locale: string;
|
|
9
|
+
suffixTranslateLabel?: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { CHART_ENDPOINT } from "../constants/CHART_ENDPOINT";
|
|
2
2
|
import Request from "../helpers/Request";
|
|
3
3
|
import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter";
|
|
4
|
+
import { chooseLang } from "../..";
|
|
4
5
|
/**
|
|
5
6
|
* Get a dataset by Qrvey ID
|
|
6
7
|
* @param qrveyid The Qrvey ID
|
|
7
8
|
* @returns a promise
|
|
8
9
|
*/
|
|
9
10
|
export function getDatasetColumns(config, qrveyid) {
|
|
11
|
+
const lang = chooseLang(config);
|
|
10
12
|
return Request.post(Object.assign(Object.assign({}, config), { qrveyid, endpoint: CHART_ENDPOINT }), '/question/list', {
|
|
11
13
|
'optionsAttributes': ['id', 'text', 'type', 'property', 'linked', 'linkid', 'qrveyid', 'bucketId', 'formulaId', 'formulaType', 'geogroup', 'outputFormat'],
|
|
12
14
|
'extend': true
|
|
13
|
-
})
|
|
15
|
+
}, { lang })
|
|
14
16
|
.then(BDatasetsToUIDatasets)
|
|
15
17
|
.catch(_e => []);
|
|
16
18
|
}
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ export function getFilterBuilderGeneralConfig(config: any = {}): IFilterBuilderG
|
|
|
11
11
|
apiKey: getAttribute(config, 'api_key') || config.apiKey,
|
|
12
12
|
appid: getAttribute(config, 'app_id') || config.appid,
|
|
13
13
|
domain: config.domain,
|
|
14
|
+
locale: config.locale,
|
|
14
15
|
qv_token: config.qv_token,
|
|
15
16
|
timezoneControl: getAttribute(config, 'timezone_control') || config.timezoneControl,
|
|
16
17
|
userid: getAttribute(config, 'user_id') || config.userid,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
2
|
+
import { transformValue } from "../../../qrvey/helpers/transformValue";
|
|
3
|
+
import { IFSFilter } from "../../interfaces/common/IFSFilter";
|
|
4
|
+
import { IFSValue } from "../../interfaces/common/IFSValue";
|
|
5
|
+
import { IFSValueRange } from "../../interfaces/common/IFSValueRange";
|
|
6
|
+
import { IFValue } from "../../interfaces/IFValue";
|
|
7
|
+
import { IFUTransformFilterValuesSettings } from "../../interfaces/ui/IFUTransformFilterValuesSettings";
|
|
8
|
+
import { isRangeValidator } from "../common/isRangeValidator";
|
|
9
|
+
import { isRegularValidator } from "../common/isRegularValidator";
|
|
10
|
+
|
|
11
|
+
export function transformFilterValues(filter: IFSFilter, settings: IFUTransformFilterValuesSettings): IFValue[] {
|
|
12
|
+
const transformValueSettings = { ...settings, column: filter.column, property: filter.property };
|
|
13
|
+
if (isEmpty(filter)) return [];
|
|
14
|
+
|
|
15
|
+
if (isRegularValidator(filter.validator)) {
|
|
16
|
+
return (filter.values as IFSValue[]).map((value: IFSValue) => ({
|
|
17
|
+
...value,
|
|
18
|
+
value: transformValue(value.value, transformValueSettings),
|
|
19
|
+
}));
|
|
20
|
+
} else if (isRangeValidator(filter.validator)) {
|
|
21
|
+
return (filter.values as IFSValueRange[]).map((value: IFSValueRange) => ({
|
|
22
|
+
...value,
|
|
23
|
+
min: transformValue(value.min, transformValueSettings),
|
|
24
|
+
max: transformValue(value.max, transformValueSettings)
|
|
25
|
+
}));
|
|
26
|
+
} else {
|
|
27
|
+
return filter.values;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -6,6 +6,7 @@ export interface IFilterBuilderGeneralConfig {
|
|
|
6
6
|
appid: string; // App ID
|
|
7
7
|
domain: string; // The domain of the environment
|
|
8
8
|
qv_token?: string; // Qrvey Token for RLS
|
|
9
|
-
timezoneControl?: string;
|
|
9
|
+
timezoneControl?: string; // Offset number for Timezone
|
|
10
|
+
locale?: string; // Localization setting
|
|
10
11
|
userid: string; // User ID
|
|
11
12
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { II18nServiceTranslate } from "../../../globalization/interfaces/II18nServiceTranslate";
|
|
2
|
+
|
|
3
|
+
export interface IFUTransformFilterValuesSettings {
|
|
4
|
+
translate: II18nServiceTranslate; // Function for getting translations
|
|
5
|
+
locale: string; // The locale string
|
|
6
|
+
suffixTranslateLabel?: string // The i18n label for the suffix values.
|
|
7
|
+
}
|
|
@@ -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,62 @@
|
|
|
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 chooseLang = (config: Record<string, any>): string => {
|
|
11
|
+
const lang: string | Record<string, any> = (
|
|
12
|
+
config?.i18n?.lang ||
|
|
13
|
+
config?.i18n?.locale?.lang ||
|
|
14
|
+
config?.locale?.lang ||
|
|
15
|
+
config.lang
|
|
16
|
+
);
|
|
17
|
+
return (<any>lang)?.lang || lang || LANG_DEFAULT;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig = {}): any => {
|
|
21
|
+
switch (outputFormat.type) {
|
|
22
|
+
case 'DATE':
|
|
23
|
+
case 'DATETIME':
|
|
24
|
+
return formatLocaleDate(value, config);
|
|
25
|
+
case 'NUMERIC':
|
|
26
|
+
return formatLocaleNumber(value, outputFormat, config);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function formatLocaleDate(value: any, config: IFormatConfig) {
|
|
31
|
+
const { lang = LANG_DEFAULT, options } = config;
|
|
32
|
+
const dateParam = new Date(value);
|
|
33
|
+
try {
|
|
34
|
+
return new Intl.DateTimeFormat([lang, LANG_DEFAULT], options).format(dateParam);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return new Intl.DateTimeFormat(LANG_DEFAULT, options).format(dateParam);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
|
|
41
|
+
const { lang = LANG_DEFAULT, options } = config;
|
|
42
|
+
const langOpts = options || getLocaleOptions(outputFormat);
|
|
43
|
+
try {
|
|
44
|
+
return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(value);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getLocaleOptions(outputFormat: IFormatOutputFormat) {
|
|
51
|
+
const { format, decimals, currency, backup_currency } = outputFormat;
|
|
52
|
+
switch(format) {
|
|
53
|
+
case LOCALE_FORMATS.CURRENCY: {
|
|
54
|
+
const iso = currencyISO.find(item => item.text === (currency.text || backup_currency.text));
|
|
55
|
+
return { style: LOCALE_STYLES.CURRENCY, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: 0 };
|
|
56
|
+
}
|
|
57
|
+
case LOCALE_FORMATS.SCIENTIFIC: return { style: LOCALE_STYLES.DECIMAL,
|
|
58
|
+
notation: LOCALE_STYLES.SCIENTIFIC, maximumFractionDigits: decimals };
|
|
59
|
+
case LOCALE_FORMATS.PERCENTAGE: return { style: LOCALE_STYLES.PERCENT, maximumFractionDigits: decimals };
|
|
60
|
+
default: return { style: LOCALE_STYLES.DECIMAL, maximumFractionDigits: decimals };
|
|
61
|
+
}
|
|
62
|
+
}
|