@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.
Files changed (182) hide show
  1. package/README.md +214 -111
  2. package/dist/cjs/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -0
  3. package/dist/cjs/filters/helpers/ui/index.d.ts +1 -0
  4. package/dist/cjs/filters/helpers/ui/index.js +1 -0
  5. package/dist/cjs/filters/helpers/ui/transformFilterValues.d.ts +4 -0
  6. package/dist/cjs/filters/helpers/ui/transformFilterValues.js +22 -0
  7. package/dist/cjs/filters/interfaces/builder/IFilterBuilderGeneralConfig.d.ts +1 -0
  8. package/dist/cjs/filters/interfaces/panel/IFilterPanelConfig.d.ts +1 -0
  9. package/dist/cjs/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
  10. package/dist/cjs/filters/interfaces/ui/IFUTransformFilterValuesSettings.js +2 -0
  11. package/dist/cjs/filters/interfaces/ui/index.d.ts +3 -2
  12. package/dist/cjs/filters/interfaces/ui/index.js +3 -2
  13. package/dist/cjs/format/definition.d.ts +17 -0
  14. package/dist/cjs/format/definition.js +31 -1
  15. package/dist/cjs/format/format.d.ts +2 -1
  16. package/dist/cjs/format/format.js +8 -5
  17. package/dist/cjs/format/index.d.ts +1 -0
  18. package/dist/cjs/format/index.js +1 -0
  19. package/dist/cjs/format/localization.d.ts +4 -0
  20. package/dist/cjs/format/localization.js +65 -0
  21. package/dist/cjs/globalization/helpers/getI18nCalendar.d.ts +4 -0
  22. package/dist/cjs/globalization/helpers/getI18nCalendar.js +69 -0
  23. package/dist/cjs/globalization/helpers/index.d.ts +1 -0
  24. package/dist/cjs/globalization/helpers/index.js +1 -0
  25. package/dist/cjs/globalization/interfaces/calendar/II18nCalendar.d.ts +7 -0
  26. package/dist/cjs/globalization/interfaces/calendar/II18nCalendar.js +2 -0
  27. package/dist/cjs/globalization/interfaces/calendar/II18nCalendarProperties.d.ts +9 -0
  28. package/dist/cjs/globalization/interfaces/calendar/II18nCalendarProperties.js +2 -0
  29. package/dist/cjs/globalization/interfaces/calendar/index.d.ts +2 -0
  30. package/dist/cjs/globalization/interfaces/calendar/index.js +14 -0
  31. package/dist/cjs/globalization/interfaces/common/II18nCommon.d.ts +2 -0
  32. package/dist/cjs/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
  33. package/dist/cjs/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
  34. package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
  35. package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.js +2 -0
  36. package/dist/cjs/globalization/interfaces/index.d.ts +1 -0
  37. package/dist/cjs/globalization/interfaces/index.js +1 -0
  38. package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
  39. package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.js +10 -0
  40. package/dist/cjs/globalization/labels/calendar/index.d.ts +1 -0
  41. package/dist/cjs/globalization/labels/calendar/index.js +13 -0
  42. package/dist/cjs/globalization/labels/common/I18N_COMMON.js +2 -0
  43. package/dist/cjs/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
  44. package/dist/cjs/globalization/labels/filters/I18N_FILTER.js +6 -0
  45. package/dist/cjs/globalization/labels/index.d.ts +1 -0
  46. package/dist/cjs/globalization/labels/index.js +1 -0
  47. package/dist/cjs/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
  48. package/dist/cjs/interfaces/format/IFormatConfig.Interface.js +2 -0
  49. package/dist/cjs/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
  50. package/dist/cjs/interfaces/format/IFormatCurrency.Interface.js +2 -0
  51. package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
  52. package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.js +2 -0
  53. package/dist/cjs/interfaces/format/index.d.ts +3 -0
  54. package/dist/cjs/interfaces/format/index.js +15 -0
  55. package/dist/cjs/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
  56. package/dist/cjs/interfaces/index.d.ts +1 -0
  57. package/dist/cjs/interfaces/index.js +1 -0
  58. package/dist/cjs/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
  59. package/dist/cjs/qrvey/helpers/getValueWithSuffixes.js +23 -0
  60. package/dist/cjs/qrvey/helpers/index.d.ts +2 -0
  61. package/dist/cjs/qrvey/helpers/index.js +2 -0
  62. package/dist/cjs/qrvey/helpers/transformValue.d.ts +8 -0
  63. package/dist/cjs/qrvey/helpers/transformValue.js +46 -0
  64. package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
  65. package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.js +2 -0
  66. package/dist/cjs/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
  67. package/dist/cjs/qrvey/interfaces/ITransformValueSettings.js +2 -0
  68. package/dist/cjs/qrvey/interfaces/index.d.ts +2 -0
  69. package/dist/cjs/qrvey/interfaces/index.js +2 -0
  70. package/dist/cjs/services/api/getDatasetColumns.api.js +3 -1
  71. package/dist/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -0
  72. package/dist/filters/helpers/ui/index.d.ts +1 -0
  73. package/dist/filters/helpers/ui/index.js +1 -0
  74. package/dist/filters/helpers/ui/transformFilterValues.d.ts +4 -0
  75. package/dist/filters/helpers/ui/transformFilterValues.js +18 -0
  76. package/dist/filters/interfaces/builder/IFilterBuilderGeneralConfig.d.ts +1 -0
  77. package/dist/filters/interfaces/panel/IFilterPanelConfig.d.ts +1 -0
  78. package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
  79. package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.js +1 -0
  80. package/dist/filters/interfaces/ui/index.d.ts +3 -2
  81. package/dist/filters/interfaces/ui/index.js +3 -2
  82. package/dist/format/definition.d.ts +17 -0
  83. package/dist/format/definition.js +30 -0
  84. package/dist/format/format.d.ts +2 -1
  85. package/dist/format/format.js +6 -3
  86. package/dist/format/index.d.ts +1 -0
  87. package/dist/format/index.js +1 -0
  88. package/dist/format/localization.d.ts +4 -0
  89. package/dist/format/localization.js +59 -0
  90. package/dist/globalization/helpers/getI18nCalendar.d.ts +4 -0
  91. package/dist/globalization/helpers/getI18nCalendar.js +65 -0
  92. package/dist/globalization/helpers/index.d.ts +1 -0
  93. package/dist/globalization/helpers/index.js +1 -0
  94. package/dist/globalization/interfaces/calendar/II18nCalendar.d.ts +7 -0
  95. package/dist/globalization/interfaces/calendar/II18nCalendar.js +1 -0
  96. package/dist/globalization/interfaces/calendar/II18nCalendarProperties.d.ts +9 -0
  97. package/dist/globalization/interfaces/calendar/II18nCalendarProperties.js +1 -0
  98. package/dist/globalization/interfaces/calendar/index.d.ts +2 -0
  99. package/dist/globalization/interfaces/calendar/index.js +2 -0
  100. package/dist/globalization/interfaces/common/II18nCommon.d.ts +2 -0
  101. package/dist/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
  102. package/dist/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
  103. package/dist/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
  104. package/dist/globalization/interfaces/filters/II18nTokenBox.js +1 -0
  105. package/dist/globalization/interfaces/index.d.ts +1 -0
  106. package/dist/globalization/interfaces/index.js +1 -0
  107. package/dist/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
  108. package/dist/globalization/labels/calendar/I18N_CALENDAR.js +7 -0
  109. package/dist/globalization/labels/calendar/index.d.ts +1 -0
  110. package/dist/globalization/labels/calendar/index.js +1 -0
  111. package/dist/globalization/labels/common/I18N_COMMON.js +2 -0
  112. package/dist/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
  113. package/dist/globalization/labels/filters/I18N_FILTER.js +6 -0
  114. package/dist/globalization/labels/index.d.ts +1 -0
  115. package/dist/globalization/labels/index.js +1 -0
  116. package/dist/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
  117. package/dist/interfaces/format/IFormatConfig.Interface.js +1 -0
  118. package/dist/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
  119. package/dist/interfaces/format/IFormatCurrency.Interface.js +1 -0
  120. package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
  121. package/dist/interfaces/format/IFormatOutputFormat.Interface.js +1 -0
  122. package/dist/interfaces/format/index.d.ts +3 -0
  123. package/dist/interfaces/format/index.js +3 -0
  124. package/dist/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
  125. package/dist/interfaces/index.d.ts +1 -0
  126. package/dist/interfaces/index.js +1 -0
  127. package/dist/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
  128. package/dist/qrvey/helpers/getValueWithSuffixes.js +19 -0
  129. package/dist/qrvey/helpers/index.d.ts +2 -0
  130. package/dist/qrvey/helpers/index.js +2 -0
  131. package/dist/qrvey/helpers/transformValue.d.ts +8 -0
  132. package/dist/qrvey/helpers/transformValue.js +42 -0
  133. package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
  134. package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.js +1 -0
  135. package/dist/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
  136. package/dist/qrvey/interfaces/ITransformValueSettings.js +1 -0
  137. package/dist/qrvey/interfaces/index.d.ts +2 -0
  138. package/dist/qrvey/interfaces/index.js +2 -0
  139. package/dist/services/api/getDatasetColumns.api.js +3 -1
  140. package/package.json +1 -1
  141. package/src/filters/helpers/builder/getFilterBuilderGeneralConfig.ts +1 -0
  142. package/src/filters/helpers/ui/index.ts +1 -0
  143. package/src/filters/helpers/ui/transformFilterValues.ts +29 -0
  144. package/src/filters/interfaces/builder/IFilterBuilderGeneralConfig.ts +2 -1
  145. package/src/filters/interfaces/panel/IFilterPanelConfig.ts +1 -0
  146. package/src/filters/interfaces/ui/IFUTransformFilterValuesSettings.ts +7 -0
  147. package/src/filters/interfaces/ui/index.ts +3 -2
  148. package/src/format/definition.ts +45 -0
  149. package/src/format/format.ts +19 -15
  150. package/src/format/index.ts +1 -0
  151. package/src/format/localization.ts +62 -0
  152. package/src/globalization/helpers/getI18nCalendar.ts +68 -0
  153. package/src/globalization/helpers/index.ts +1 -0
  154. package/src/globalization/interfaces/calendar/II18nCalendar.ts +7 -0
  155. package/src/globalization/interfaces/calendar/II18nCalendarProperties.ts +9 -0
  156. package/src/globalization/interfaces/calendar/index.ts +2 -0
  157. package/src/globalization/interfaces/common/II18nCommon.ts +2 -0
  158. package/src/globalization/interfaces/common/II18nDayNames.ts +8 -0
  159. package/src/globalization/interfaces/filters/II18nFilter.ts +2 -0
  160. package/src/globalization/interfaces/filters/II18nTokenBox.ts +6 -0
  161. package/src/globalization/interfaces/index.ts +1 -0
  162. package/src/globalization/labels/calendar/I18N_CALENDAR.ts +9 -0
  163. package/src/globalization/labels/calendar/index.ts +1 -0
  164. package/src/globalization/labels/common/I18N_COMMON.ts +2 -0
  165. package/src/globalization/labels/common/I18N_DAY_NAMES.ts +8 -0
  166. package/src/globalization/labels/filters/I18N_FILTER.ts +6 -0
  167. package/src/globalization/labels/index.ts +1 -0
  168. package/src/interfaces/format/IFormatConfig.Interface.ts +5 -0
  169. package/src/interfaces/format/IFormatCurrency.Interface.ts +4 -0
  170. package/src/interfaces/format/IFormatOutputFormat.Interface.ts +9 -0
  171. package/src/interfaces/format/index.ts +3 -0
  172. package/src/interfaces/general/IGeneralWidgetConfig.ts +2 -0
  173. package/src/interfaces/index.ts +1 -0
  174. package/src/qrvey/helpers/getValueWithSuffixes.ts +19 -0
  175. package/src/qrvey/helpers/index.ts +2 -0
  176. package/src/qrvey/helpers/transformValue.ts +47 -0
  177. package/src/qrvey/interfaces/IGetValueWithSuffixesSettings.ts +12 -0
  178. package/src/qrvey/interfaces/ITransformValueSettings.ts +12 -0
  179. package/src/qrvey/interfaces/index.ts +2 -0
  180. package/src/services/api/getDatasetColumns.api.ts +3 -1
  181. package/test/columns/isNumericalColumn.test.js +154 -0
  182. package/test/format.test.js +11 -11
@@ -1,4 +1,5 @@
1
1
  export * from './bucket_builder/index';
2
+ export * from './calendar/index';
2
3
  export * from './chart_builder/index';
3
4
  export * from './columns/index';
4
5
  export * from './common/index';
@@ -0,0 +1,2 @@
1
+ import { II18nCalendar } from "../../interfaces/calendar/II18nCalendar";
2
+ export declare const I18N_CALENDAR: II18nCalendar;
@@ -0,0 +1,7 @@
1
+ export const I18N_CALENDAR = {
2
+ clear: "Clear",
3
+ hours: 'Hours',
4
+ minutes: 'Minutes',
5
+ seconds: 'Seconds',
6
+ today: "Today"
7
+ };
@@ -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
  };
@@ -1,4 +1,5 @@
1
1
  export * from './bucket_builder';
2
+ export * from './calendar';
2
3
  export * from './chart_builder';
3
4
  export * from './columns';
4
5
  export * from './common';
@@ -1,4 +1,5 @@
1
1
  export * from './bucket_builder';
2
+ export * from './calendar';
2
3
  export * from './chart_builder';
3
4
  export * from './columns';
4
5
  export * from './common';
@@ -0,0 +1,5 @@
1
+ export interface IFormatConfig {
2
+ lang?: string;
3
+ options?: object;
4
+ isMultiplied?: boolean;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface IFormatCurrency {
2
+ text: string;
3
+ label: string;
4
+ }
@@ -0,0 +1,8 @@
1
+ import { IFormatCurrency } from "./IFormatCurrency.Interface";
2
+ export interface IFormatOutputFormat {
3
+ format: string;
4
+ type: string;
5
+ decimals?: number;
6
+ currency?: IFormatCurrency;
7
+ backup_currency?: IFormatCurrency;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from './IFormatConfig.Interface';
2
+ export * from './IFormatOutputFormat.Interface';
3
+ export * from './IFormatCurrency.Interface';
@@ -0,0 +1,3 @@
1
+ export * from './IFormatConfig.Interface';
2
+ export * from './IFormatOutputFormat.Interface';
3
+ export * from './IFormatCurrency.Interface';
@@ -3,8 +3,10 @@ export interface IGeneralWidgetConfig {
3
3
  apiKey?: string;
4
4
  qrveyid?: string;
5
5
  qv_token?: string;
6
+ locale?: string;
6
7
  timezoneControl?: string;
7
8
  isFromAN?: boolean;
8
9
  appid: string;
9
10
  userid: string;
11
+ lang?: string;
10
12
  }
@@ -2,3 +2,4 @@ export * from './Chart.Interface';
2
2
  export * from './IChartBuilder.Interface';
3
3
  export * from './general';
4
4
  export * from './Qrvey.Interface';
5
+ export * from './format';
@@ -2,3 +2,4 @@ export * from './Chart.Interface';
2
2
  export * from './IChartBuilder.Interface';
3
3
  export * from './general';
4
4
  export * from './Qrvey.Interface';
5
+ export * from './format';
@@ -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
+ }
@@ -1,2 +1,4 @@
1
1
  export * from './getColumnsLabel';
2
2
  export * from './getPropertyLabel';
3
+ export * from './getValueWithSuffixes';
4
+ export * from './transformValue';
@@ -1,2 +1,4 @@
1
1
  export * from './getColumnsLabel';
2
2
  export * from './getPropertyLabel';
3
+ export * from './getValueWithSuffixes';
4
+ export * from './transformValue';
@@ -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,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 {};
@@ -3,3 +3,5 @@ export * from './ICalculation';
3
3
  export * from './ICalculationInfo';
4
4
  export * from './ICalculationType';
5
5
  export * from './IDataset';
6
+ export * from './IGetValueWithSuffixesSettings';
7
+ export * from './ITransformValueSettings';
@@ -3,3 +3,5 @@ export * from './ICalculation';
3
3
  export * from './ICalculationInfo';
4
4
  export * from './ICalculationType';
5
5
  export * from './IDataset';
6
+ export * from './IGetValueWithSuffixesSettings';
7
+ export * from './ITransformValueSettings';
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.2.9-15",
3
+ "version": "1.2.9-19",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",
@@ -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,
@@ -8,3 +8,4 @@ export * from './getUIFlatFiltersByParams';
8
8
  export * from './getUIFlatFiltersByScopes';
9
9
  export * from './getUIValues';
10
10
  export * from './getUpdatedUIFilters';
11
+ export * from './transformFilterValues';
@@ -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
  }
@@ -8,4 +8,5 @@ import { IFUDataStore } from "../ui/IFUDataStore";
8
8
  export interface IFilterPanelConfig extends IFUDataStore {
9
9
  filterBuilderConfig?: IFilterBuilderConfig; // Filter Builder config object
10
10
  i18n?: IResourceI18n;
11
+ locale?: string; // Localization setting
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 './IFUValue';
23
+ export * from './IFUScope';
24
+ export * from './IFUTransformFilterValuesSettings';
25
25
  export * from './IFUUIValueSettings';
26
+ export * from './IFUValue';
@@ -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';
@@ -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 formatValue = (value: any, outputFormat: any = 'None', config?): any => {
86
- if (isEmpty(value) || typeof value === 'object' && isEmpty(value[0])) return value;
87
- switch (outputFormat.type) {
88
- case 'DATE':
89
- case 'DATETIME':
90
- return formatDate(value, outputFormat.format);
91
- case 'NUMERIC': {
92
- const parse = parseFloat(value);
93
- return isNaN(parse) ? value : formatNumber(parse, outputFormat, config);
94
- }
95
- case 'IMAGEUPLOAD':
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) => {
@@ -1 +1,2 @@
1
1
  export * from './format';
2
+ export * from './localization';
@@ -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
+ }