@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,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
|
+
}
|
|
@@ -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';
|
|
@@ -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,7 @@ 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 { chooseLang } from "../..";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Get a dataset by Qrvey ID
|
|
@@ -10,10 +11,11 @@ import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter
|
|
|
10
11
|
* @returns a promise
|
|
11
12
|
*/
|
|
12
13
|
export function getDatasetColumns(config: IGeneralWidgetConfig, qrveyid?: string): Promise<IDataset[]> {
|
|
14
|
+
const lang = chooseLang(config);
|
|
13
15
|
return Request.post({ ...config, qrveyid, endpoint: CHART_ENDPOINT }, '/question/list', {
|
|
14
16
|
'optionsAttributes': ['id', 'text', 'type', 'property', 'linked', 'linkid', 'qrveyid', 'bucketId', 'formulaId', 'formulaType', 'geogroup', 'outputFormat'],
|
|
15
17
|
'extend': true
|
|
16
|
-
})
|
|
18
|
+
}, { lang })
|
|
17
19
|
.then(BDatasetsToUIDatasets)
|
|
18
20
|
.catch(_e => []);
|
|
19
21
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const { COLUMN, FORMULA, isNumericalColumn } = require("../../dist/cjs");
|
|
2
|
+
|
|
3
|
+
const column1 = {
|
|
4
|
+
id: '123',
|
|
5
|
+
qrveyid: 'abc',
|
|
6
|
+
type: COLUMN.NUMERIC
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const column2 = {
|
|
10
|
+
id: '222',
|
|
11
|
+
qrveyid: 'abc',
|
|
12
|
+
type: COLUMN.RATING
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const column3 = {
|
|
16
|
+
id: '333',
|
|
17
|
+
qrveyid: 'abc',
|
|
18
|
+
type: COLUMN.SLIDEBAR
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const column4 = {
|
|
22
|
+
formulaid: '456',
|
|
23
|
+
formulaType: FORMULA.NUMBER,
|
|
24
|
+
id: '456',
|
|
25
|
+
qrveyid: 'abc',
|
|
26
|
+
type: COLUMN.FORMULA
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const wrongColumn1 = {
|
|
30
|
+
formulaid: '456',
|
|
31
|
+
formulaType: FORMULA.DATE,
|
|
32
|
+
id: '494',
|
|
33
|
+
qrveyid: 'abc',
|
|
34
|
+
type: COLUMN.FORMULA
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const wrongColumn2 = {
|
|
38
|
+
id: '789',
|
|
39
|
+
qrveyid: 'abc',
|
|
40
|
+
type: COLUMN.TEXTFIELD
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('Testing undefined/empty arguments', function () {
|
|
44
|
+
const empty1 = undefined;
|
|
45
|
+
const empty2 = null;
|
|
46
|
+
const empty3 = '';
|
|
47
|
+
const empty4 = [];
|
|
48
|
+
const empty5 = {};
|
|
49
|
+
|
|
50
|
+
test('no argument passed', function () {
|
|
51
|
+
const validation = isNumericalColumn();
|
|
52
|
+
expect(validation).toBeFalsy();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('Undefined argument', function () {
|
|
56
|
+
const validation = isNumericalColumn(empty1);
|
|
57
|
+
expect(validation).toBeFalsy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('Null argument', function () {
|
|
61
|
+
const validation = isNumericalColumn(empty2);
|
|
62
|
+
expect(validation).toBeFalsy();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('Empty string argument', function () {
|
|
66
|
+
const validation = isNumericalColumn(empty3);
|
|
67
|
+
expect(validation).toBeFalsy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('Empty array argument', function () {
|
|
71
|
+
const validation = isNumericalColumn(empty4);
|
|
72
|
+
expect(validation).toBeFalsy();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('Empty object argument', function () {
|
|
76
|
+
const validation = isNumericalColumn(empty5);
|
|
77
|
+
expect(validation).toBeFalsy();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('Testing no-object arguments', function () {
|
|
82
|
+
const variable1 = 1;
|
|
83
|
+
const variable2 = false;
|
|
84
|
+
const variable3 = new Date();
|
|
85
|
+
const variable4 = ['Hello', 'World'];
|
|
86
|
+
const variable5 = (num1 = 1, num2 = 2) => num1 + num2;
|
|
87
|
+
|
|
88
|
+
test('Numeric variable', function () {
|
|
89
|
+
const validation = isNumericalColumn(variable1);
|
|
90
|
+
expect(validation).toBeFalsy();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('Boolean variable', function () {
|
|
94
|
+
const validation = isNumericalColumn(variable2);
|
|
95
|
+
expect(validation).toBeFalsy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('Date object variable', function () {
|
|
99
|
+
const validation = isNumericalColumn(variable3);
|
|
100
|
+
expect(validation).toBeFalsy();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('Array variable', function () {
|
|
104
|
+
const validation = isNumericalColumn(variable4);
|
|
105
|
+
expect(validation).toBeFalsy();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('Function-like variable', function () {
|
|
109
|
+
const validation = isNumericalColumn(variable5);
|
|
110
|
+
expect(validation).toBeFalsy();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('Testing invalid expected object', function () {
|
|
115
|
+
const variable1 = { tag1: 'value1', tag2: 'value2' };
|
|
116
|
+
|
|
117
|
+
test('Different expected object', function () {
|
|
118
|
+
const validation = isNumericalColumn(variable1);
|
|
119
|
+
expect(validation).toBeFalsy();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('Different column type 2', function () {
|
|
123
|
+
const validation = isNumericalColumn(wrongColumn1);
|
|
124
|
+
expect(validation).toBeFalsy();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('Different column type 1', function () {
|
|
128
|
+
const validation = isNumericalColumn(wrongColumn2);
|
|
129
|
+
expect(validation).toBeFalsy();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('Regular scenarios', function () {
|
|
134
|
+
test('Scenario #1 - Numeric column type', function () {
|
|
135
|
+
const validation = isNumericalColumn(column1);
|
|
136
|
+
expect(validation).toBeTruthy();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('Scenario #2 - Rating column type', function () {
|
|
140
|
+
const validation = isNumericalColumn(column2);
|
|
141
|
+
expect(validation).toBeTruthy();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('Scenario #4 - Slidebar column type', function () {
|
|
145
|
+
const validation = isNumericalColumn(column3);
|
|
146
|
+
expect(validation).toBeTruthy();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('Scenario #4 - Formula column type with a number type', function () {
|
|
150
|
+
const validation = isNumericalColumn(column4);
|
|
151
|
+
expect(validation).toBeTruthy();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
});
|
package/test/format.test.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { addFormat, defineFormat, formatAbbreviated } = require('../dist/cjs');
|
|
2
2
|
|
|
3
3
|
describe('Testing format util', function () {
|
|
4
4
|
test('Number formats', function () {
|
|
5
|
-
const abbreviated =
|
|
5
|
+
const abbreviated = addFormat('1000000', {
|
|
6
6
|
"type": "NUMERIC",
|
|
7
7
|
"format": "Abbreviated",
|
|
8
8
|
"decimals": "3"
|
|
9
9
|
});
|
|
10
10
|
expect(abbreviated).toEqual('1.00M');
|
|
11
11
|
|
|
12
|
-
const numeric =
|
|
12
|
+
const numeric = addFormat('1000000', {
|
|
13
13
|
"type": "NUMERIC",
|
|
14
14
|
"format": "Numeric",
|
|
15
15
|
"decimals": "3"
|
|
16
16
|
});
|
|
17
17
|
expect(numeric).toEqual('1,000,000.000');
|
|
18
18
|
|
|
19
|
-
const currency =
|
|
19
|
+
const currency = addFormat('1000000', {
|
|
20
20
|
"type": "NUMERIC",
|
|
21
21
|
"format": "Currency",
|
|
22
22
|
"decimals": "3"
|
|
23
23
|
});
|
|
24
24
|
expect(currency).toEqual(' $1,000,000.000');
|
|
25
25
|
|
|
26
|
-
const percentage =
|
|
26
|
+
const percentage = addFormat('1000000', {
|
|
27
27
|
"type": "NUMERIC",
|
|
28
28
|
"format": "Percentage",
|
|
29
29
|
"decimals": "3"
|
|
@@ -32,31 +32,31 @@ describe('Testing format util', function () {
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('Date formats', function () {
|
|
35
|
-
const yyyyMMdd =
|
|
35
|
+
const yyyyMMdd = addFormat('2021-08-06', {
|
|
36
36
|
"type": "DATE",
|
|
37
37
|
"format": "MM/DD/YYYY HH24:MM:SS"
|
|
38
38
|
});
|
|
39
39
|
expect(yyyyMMdd).toEqual('08/06/2021 00:00:00');
|
|
40
40
|
|
|
41
|
-
const yyyyMMddHHmmSS =
|
|
41
|
+
const yyyyMMddHHmmSS = addFormat('2021-08-06 05:30:50', {
|
|
42
42
|
"type": "DATE",
|
|
43
43
|
"format": "MM/DD/YYYY HH24:MM:SS"
|
|
44
44
|
});
|
|
45
45
|
expect(yyyyMMddHHmmSS).toEqual('08/06/2021 05:30:50');
|
|
46
46
|
|
|
47
|
-
const ISOFormat =
|
|
47
|
+
const ISOFormat = addFormat('2021-06-09T13:15:46', {
|
|
48
48
|
"type": "DATE",
|
|
49
49
|
"format": "MM/DD/YYYY hh:MM:SS"
|
|
50
50
|
});
|
|
51
51
|
expect(ISOFormat).toEqual('06/09/2021 01:15:46');
|
|
52
52
|
|
|
53
|
-
const ISOFormatRandom =
|
|
53
|
+
const ISOFormatRandom = addFormat('2021-06-09T13:15:46', {
|
|
54
54
|
"type": "DATE",
|
|
55
55
|
"format": "MM YYYY H M s"
|
|
56
56
|
});
|
|
57
57
|
expect(ISOFormatRandom).toEqual('06 2021 13 6 46');
|
|
58
58
|
|
|
59
|
-
const ISOFormatRandom1 =
|
|
59
|
+
const ISOFormatRandom1 = addFormat('2018-01-01T00:00:00', {
|
|
60
60
|
"type": "DATE",
|
|
61
61
|
"format": "Q MMMM Do ddd"
|
|
62
62
|
});
|
|
@@ -336,7 +336,7 @@ describe('Define format tests', function () {
|
|
|
336
336
|
|
|
337
337
|
const format = defineFormat(column, true);
|
|
338
338
|
expect(format).toEqual({ type: 'NUMERIC', format: 'Currency', decimals: '3' });
|
|
339
|
-
const currency =
|
|
339
|
+
const currency = addFormat('1000000', format);
|
|
340
340
|
expect(currency).toEqual(' $1,000,000.000');
|
|
341
341
|
});
|
|
342
342
|
|