@qrvey/utils 1.2.9-14 → 1.2.9-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +755 -652
  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 +3 -0
  20. package/dist/cjs/format/localization.js +56 -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/chart_builder/II18nChartBuilderFontOptions.d.ts +5 -3
  32. package/dist/cjs/globalization/interfaces/common/II18nCommon.d.ts +2 -0
  33. package/dist/cjs/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
  34. package/dist/cjs/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
  35. package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
  36. package/dist/cjs/globalization/interfaces/filters/II18nTokenBox.js +2 -0
  37. package/dist/cjs/globalization/interfaces/index.d.ts +1 -0
  38. package/dist/cjs/globalization/interfaces/index.js +1 -0
  39. package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
  40. package/dist/cjs/globalization/labels/calendar/I18N_CALENDAR.js +10 -0
  41. package/dist/cjs/globalization/labels/calendar/index.d.ts +1 -0
  42. package/dist/cjs/globalization/labels/calendar/index.js +13 -0
  43. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.js +1 -1
  44. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +7 -5
  45. package/dist/cjs/globalization/labels/common/I18N_COMMON.js +2 -0
  46. package/dist/cjs/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
  47. package/dist/cjs/globalization/labels/filters/I18N_FILTER.js +6 -0
  48. package/dist/cjs/globalization/labels/index.d.ts +1 -0
  49. package/dist/cjs/globalization/labels/index.js +1 -0
  50. package/dist/cjs/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
  51. package/dist/cjs/interfaces/format/IFormatConfig.Interface.js +2 -0
  52. package/dist/cjs/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
  53. package/dist/cjs/interfaces/format/IFormatCurrency.Interface.js +2 -0
  54. package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
  55. package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.js +2 -0
  56. package/dist/cjs/interfaces/format/index.d.ts +3 -0
  57. package/dist/cjs/interfaces/format/index.js +15 -0
  58. package/dist/cjs/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
  59. package/dist/cjs/interfaces/index.d.ts +1 -0
  60. package/dist/cjs/interfaces/index.js +1 -0
  61. package/dist/cjs/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
  62. package/dist/cjs/qrvey/helpers/getValueWithSuffixes.js +23 -0
  63. package/dist/cjs/qrvey/helpers/index.d.ts +2 -0
  64. package/dist/cjs/qrvey/helpers/index.js +2 -0
  65. package/dist/cjs/qrvey/helpers/transformValue.d.ts +8 -0
  66. package/dist/cjs/qrvey/helpers/transformValue.js +46 -0
  67. package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
  68. package/dist/cjs/qrvey/interfaces/IGetValueWithSuffixesSettings.js +2 -0
  69. package/dist/cjs/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
  70. package/dist/cjs/qrvey/interfaces/ITransformValueSettings.js +2 -0
  71. package/dist/cjs/qrvey/interfaces/index.d.ts +2 -0
  72. package/dist/cjs/qrvey/interfaces/index.js +2 -0
  73. package/dist/cjs/services/api/getDatasetColumns.api.js +5 -1
  74. package/dist/filters/helpers/builder/getFilterBuilderGeneralConfig.js +1 -0
  75. package/dist/filters/helpers/ui/index.d.ts +1 -0
  76. package/dist/filters/helpers/ui/index.js +1 -0
  77. package/dist/filters/helpers/ui/transformFilterValues.d.ts +4 -0
  78. package/dist/filters/helpers/ui/transformFilterValues.js +18 -0
  79. package/dist/filters/interfaces/builder/IFilterBuilderGeneralConfig.d.ts +1 -0
  80. package/dist/filters/interfaces/panel/IFilterPanelConfig.d.ts +1 -0
  81. package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.d.ts +6 -0
  82. package/dist/filters/interfaces/ui/IFUTransformFilterValuesSettings.js +1 -0
  83. package/dist/filters/interfaces/ui/index.d.ts +3 -2
  84. package/dist/filters/interfaces/ui/index.js +3 -2
  85. package/dist/format/definition.d.ts +17 -0
  86. package/dist/format/definition.js +30 -0
  87. package/dist/format/format.d.ts +2 -1
  88. package/dist/format/format.js +6 -3
  89. package/dist/format/index.d.ts +1 -0
  90. package/dist/format/index.js +1 -0
  91. package/dist/format/localization.d.ts +3 -0
  92. package/dist/format/localization.js +51 -0
  93. package/dist/globalization/helpers/getI18nCalendar.d.ts +4 -0
  94. package/dist/globalization/helpers/getI18nCalendar.js +65 -0
  95. package/dist/globalization/helpers/index.d.ts +1 -0
  96. package/dist/globalization/helpers/index.js +1 -0
  97. package/dist/globalization/interfaces/calendar/II18nCalendar.d.ts +7 -0
  98. package/dist/globalization/interfaces/calendar/II18nCalendar.js +1 -0
  99. package/dist/globalization/interfaces/calendar/II18nCalendarProperties.d.ts +9 -0
  100. package/dist/globalization/interfaces/calendar/II18nCalendarProperties.js +1 -0
  101. package/dist/globalization/interfaces/calendar/index.d.ts +2 -0
  102. package/dist/globalization/interfaces/calendar/index.js +2 -0
  103. package/dist/globalization/interfaces/chart_builder/II18nChartBuilderFontOptions.d.ts +5 -3
  104. package/dist/globalization/interfaces/common/II18nCommon.d.ts +2 -0
  105. package/dist/globalization/interfaces/common/II18nDayNames.d.ts +7 -0
  106. package/dist/globalization/interfaces/filters/II18nFilter.d.ts +2 -0
  107. package/dist/globalization/interfaces/filters/II18nTokenBox.d.ts +6 -0
  108. package/dist/globalization/interfaces/filters/II18nTokenBox.js +1 -0
  109. package/dist/globalization/interfaces/index.d.ts +1 -0
  110. package/dist/globalization/interfaces/index.js +1 -0
  111. package/dist/globalization/labels/calendar/I18N_CALENDAR.d.ts +2 -0
  112. package/dist/globalization/labels/calendar/I18N_CALENDAR.js +7 -0
  113. package/dist/globalization/labels/calendar/index.d.ts +1 -0
  114. package/dist/globalization/labels/calendar/index.js +1 -0
  115. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.js +1 -1
  116. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +7 -5
  117. package/dist/globalization/labels/common/I18N_COMMON.js +2 -0
  118. package/dist/globalization/labels/common/I18N_DAY_NAMES.js +7 -0
  119. package/dist/globalization/labels/filters/I18N_FILTER.js +6 -0
  120. package/dist/globalization/labels/index.d.ts +1 -0
  121. package/dist/globalization/labels/index.js +1 -0
  122. package/dist/interfaces/format/IFormatConfig.Interface.d.ts +5 -0
  123. package/dist/interfaces/format/IFormatConfig.Interface.js +1 -0
  124. package/dist/interfaces/format/IFormatCurrency.Interface.d.ts +4 -0
  125. package/dist/interfaces/format/IFormatCurrency.Interface.js +1 -0
  126. package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +8 -0
  127. package/dist/interfaces/format/IFormatOutputFormat.Interface.js +1 -0
  128. package/dist/interfaces/format/index.d.ts +3 -0
  129. package/dist/interfaces/format/index.js +3 -0
  130. package/dist/interfaces/general/IGeneralWidgetConfig.d.ts +2 -0
  131. package/dist/interfaces/index.d.ts +1 -0
  132. package/dist/interfaces/index.js +1 -0
  133. package/dist/qrvey/helpers/getValueWithSuffixes.d.ts +9 -0
  134. package/dist/qrvey/helpers/getValueWithSuffixes.js +19 -0
  135. package/dist/qrvey/helpers/index.d.ts +2 -0
  136. package/dist/qrvey/helpers/index.js +2 -0
  137. package/dist/qrvey/helpers/transformValue.d.ts +8 -0
  138. package/dist/qrvey/helpers/transformValue.js +42 -0
  139. package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.d.ts +11 -0
  140. package/dist/qrvey/interfaces/IGetValueWithSuffixesSettings.js +1 -0
  141. package/dist/qrvey/interfaces/ITransformValueSettings.d.ts +10 -0
  142. package/dist/qrvey/interfaces/ITransformValueSettings.js +1 -0
  143. package/dist/qrvey/interfaces/index.d.ts +2 -0
  144. package/dist/qrvey/interfaces/index.js +2 -0
  145. package/dist/services/api/getDatasetColumns.api.js +5 -1
  146. package/package.json +1 -1
  147. package/src/filters/helpers/builder/getFilterBuilderGeneralConfig.ts +1 -0
  148. package/src/filters/helpers/ui/index.ts +1 -0
  149. package/src/filters/helpers/ui/transformFilterValues.ts +29 -0
  150. package/src/filters/interfaces/builder/IFilterBuilderGeneralConfig.ts +2 -1
  151. package/src/filters/interfaces/panel/IFilterPanelConfig.ts +1 -0
  152. package/src/filters/interfaces/ui/IFUTransformFilterValuesSettings.ts +7 -0
  153. package/src/filters/interfaces/ui/index.ts +3 -2
  154. package/src/format/definition.ts +45 -0
  155. package/src/format/format.ts +19 -15
  156. package/src/format/index.ts +1 -0
  157. package/src/format/localization.ts +52 -0
  158. package/src/globalization/helpers/getI18nCalendar.ts +68 -0
  159. package/src/globalization/helpers/index.ts +1 -0
  160. package/src/globalization/interfaces/calendar/II18nCalendar.ts +7 -0
  161. package/src/globalization/interfaces/calendar/II18nCalendarProperties.ts +9 -0
  162. package/src/globalization/interfaces/calendar/index.ts +2 -0
  163. package/src/globalization/interfaces/chart_builder/II18nChartBuilderFontOptions.ts +5 -3
  164. package/src/globalization/interfaces/common/II18nCommon.ts +2 -0
  165. package/src/globalization/interfaces/common/II18nDayNames.ts +8 -0
  166. package/src/globalization/interfaces/filters/II18nFilter.ts +2 -0
  167. package/src/globalization/interfaces/filters/II18nTokenBox.ts +6 -0
  168. package/src/globalization/interfaces/index.ts +1 -0
  169. package/src/globalization/labels/calendar/I18N_CALENDAR.ts +9 -0
  170. package/src/globalization/labels/calendar/index.ts +1 -0
  171. package/src/globalization/labels/chart_builder/I18N_CHART_BUILDER_LAYER_OPTIONS.ts +1 -1
  172. package/src/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.ts +8 -6
  173. package/src/globalization/labels/common/I18N_COMMON.ts +2 -0
  174. package/src/globalization/labels/common/I18N_DAY_NAMES.ts +8 -0
  175. package/src/globalization/labels/filters/I18N_FILTER.ts +6 -0
  176. package/src/globalization/labels/index.ts +1 -0
  177. package/src/interfaces/format/IFormatConfig.Interface.ts +5 -0
  178. package/src/interfaces/format/IFormatCurrency.Interface.ts +4 -0
  179. package/src/interfaces/format/IFormatOutputFormat.Interface.ts +9 -0
  180. package/src/interfaces/format/index.ts +3 -0
  181. package/src/interfaces/general/IGeneralWidgetConfig.ts +2 -0
  182. package/src/interfaces/index.ts +1 -0
  183. package/src/qrvey/helpers/getValueWithSuffixes.ts +19 -0
  184. package/src/qrvey/helpers/index.ts +2 -0
  185. package/src/qrvey/helpers/transformValue.ts +47 -0
  186. package/src/qrvey/interfaces/IGetValueWithSuffixesSettings.ts +12 -0
  187. package/src/qrvey/interfaces/ITransformValueSettings.ts +12 -0
  188. package/src/qrvey/interfaces/index.ts +2 -0
  189. package/src/services/api/getDatasetColumns.api.ts +4 -1
  190. package/test/columns/isNumericalColumn.test.js +154 -0
  191. package/test/format.test.js +11 -11
@@ -19,7 +19,8 @@ export * from './IFUDataset';
19
19
  export * from './IFUFilter';
20
20
  export * from './IFUFilterExtras';
21
21
  export * from './IFUFlattenedFilter';
22
- export * from './IFUScope';
23
22
  export * from './IFUParamsToGetFilter';
24
- export * from './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,52 @@
1
+ import { IFormatConfig, IFormatOutputFormat } from '../interfaces';
2
+ import { currencyISO, LOCALE_FORMATS, LOCALE_STYLES, LANG_DEFAULT } from './definition';
3
+
4
+ export const getLang = (locale: string | Record<string, any>) => {
5
+ if (!locale) return;
6
+ else if(typeof locale === 'object') return locale;
7
+ else return { lang: locale === "browser" ? window.navigator.language : locale };
8
+ };
9
+
10
+ export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig = {}): any => {
11
+ switch (outputFormat.type) {
12
+ case 'DATE':
13
+ case 'DATETIME':
14
+ return formatLocaleDate(value, config);
15
+ case 'NUMERIC':
16
+ return formatLocaleNumber(value, outputFormat, config);
17
+ }
18
+ };
19
+
20
+ function formatLocaleDate(value: any, config: IFormatConfig) {
21
+ const { lang = LANG_DEFAULT, options } = config;
22
+ const dateParam = new Date(value);
23
+ try {
24
+ return new Intl.DateTimeFormat([lang, LANG_DEFAULT], options).format(dateParam);
25
+ } catch (error) {
26
+ return new Intl.DateTimeFormat(LANG_DEFAULT, options).format(dateParam);
27
+ }
28
+ }
29
+
30
+ function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
31
+ const { lang = LANG_DEFAULT, options } = config;
32
+ const langOpts = options || getLocaleOptions(outputFormat);
33
+ try {
34
+ return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(value);
35
+ } catch (e) {
36
+ return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(value);
37
+ }
38
+ }
39
+
40
+ function getLocaleOptions(outputFormat: IFormatOutputFormat) {
41
+ const { format, decimals, currency, backup_currency } = outputFormat;
42
+ switch(format) {
43
+ case LOCALE_FORMATS.CURRENCY: {
44
+ const iso = currencyISO.find(item => item.text === (currency.text || backup_currency.text));
45
+ return { style: LOCALE_STYLES.CURRENCY, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: 0 };
46
+ }
47
+ case LOCALE_FORMATS.SCIENTIFIC: return { style: LOCALE_STYLES.DECIMAL,
48
+ notation: LOCALE_STYLES.SCIENTIFIC, maximumFractionDigits: decimals };
49
+ case LOCALE_FORMATS.PERCENTAGE: return { style: LOCALE_STYLES.PERCENT, maximumFractionDigits: decimals };
50
+ default: return { style: LOCALE_STYLES.DECIMAL, maximumFractionDigits: decimals };
51
+ }
52
+ }
@@ -0,0 +1,68 @@
1
+ import { II18nCalendarProperties } from "../interfaces/calendar/II18nCalendarProperties";
2
+ import { II18nServiceTranslate } from "../interfaces/II18nServiceTranslate";
3
+ import { I18nService } from "../service/i18nextBuilder";
4
+
5
+ export function getI18nCalendar(locale: I18nService | II18nServiceTranslate): II18nCalendarProperties {
6
+ const localeOverride = locale instanceof I18nService ? locale : typeof locale === 'function' ? { translate: locale } : undefined;
7
+ if (!localeOverride) return undefined;
8
+
9
+ return {
10
+ clear: localeOverride.translate('common.calendar.clear'),
11
+ days: [
12
+ localeOverride.translate('common.day_names.sunday_dddd'),
13
+ localeOverride.translate('common.day_names.monday_dddd'),
14
+ localeOverride.translate('common.day_names.tuesday_dddd'),
15
+ localeOverride.translate('common.day_names.wednesday_dddd'),
16
+ localeOverride.translate('common.day_names.thursday_dddd'),
17
+ localeOverride.translate('common.day_names.friday_dddd'),
18
+ localeOverride.translate('common.day_names.saturday_dddd')
19
+ ],
20
+ daysMin: [
21
+ localeOverride.translate('common.day_names.sunday_dd'),
22
+ localeOverride.translate('common.day_names.monday_dd'),
23
+ localeOverride.translate('common.day_names.tuesday_dd'),
24
+ localeOverride.translate('common.day_names.wednesday_dd'),
25
+ localeOverride.translate('common.day_names.thursday_dd'),
26
+ localeOverride.translate('common.day_names.friday_dd'),
27
+ localeOverride.translate('common.day_names.saturday_dd')
28
+ ],
29
+ daysShort: [
30
+ localeOverride.translate('common.day_names.sunday_ddd'),
31
+ localeOverride.translate('common.day_names.monday_ddd'),
32
+ localeOverride.translate('common.day_names.tuesday_ddd'),
33
+ localeOverride.translate('common.day_names.wednesday_ddd'),
34
+ localeOverride.translate('common.day_names.thursday_ddd'),
35
+ localeOverride.translate('common.day_names.friday_ddd'),
36
+ localeOverride.translate('common.day_names.saturday_ddd')
37
+ ],
38
+ months: [
39
+ localeOverride.translate('common.date_grouping.january_mmmm'),
40
+ localeOverride.translate('common.date_grouping.february_mmmm'),
41
+ localeOverride.translate('common.date_grouping.march_mmmm'),
42
+ localeOverride.translate('common.date_grouping.april_mmmm'),
43
+ localeOverride.translate('common.date_grouping.may_mmmm'),
44
+ localeOverride.translate('common.date_grouping.june_mmmm'),
45
+ localeOverride.translate('common.date_grouping.july_mmmm'),
46
+ localeOverride.translate('common.date_grouping.august_mmmm'),
47
+ localeOverride.translate('common.date_grouping.september_mmmm'),
48
+ localeOverride.translate('common.date_grouping.october_mmmm'),
49
+ localeOverride.translate('common.date_grouping.november_mmmm'),
50
+ localeOverride.translate('common.date_grouping.december_mmmm')
51
+ ],
52
+ monthsShort: [
53
+ localeOverride.translate('common.date_grouping.january_mmm'),
54
+ localeOverride.translate('common.date_grouping.february_mmm'),
55
+ localeOverride.translate('common.date_grouping.march_mmm'),
56
+ localeOverride.translate('common.date_grouping.april_mmm'),
57
+ localeOverride.translate('common.date_grouping.may_mmm'),
58
+ localeOverride.translate('common.date_grouping.june_mmm'),
59
+ localeOverride.translate('common.date_grouping.july_mmm'),
60
+ localeOverride.translate('common.date_grouping.august_mmm'),
61
+ localeOverride.translate('common.date_grouping.september_mmm'),
62
+ localeOverride.translate('common.date_grouping.october_mmm'),
63
+ localeOverride.translate('common.date_grouping.november_mmm'),
64
+ localeOverride.translate('common.date_grouping.december_mmm')
65
+ ],
66
+ today: localeOverride.translate('common.calendar.today')
67
+ };
68
+ }
@@ -1,2 +1,3 @@
1
+ export * from './getI18nCalendar';
1
2
  export * from './getI18nDateGroupLabel';
2
3
  export * from './getReverseI18nGroupLabel';
@@ -0,0 +1,7 @@
1
+ export interface II18nCalendar {
2
+ clear: string;
3
+ hours: string;
4
+ minutes: string;
5
+ seconds: string;
6
+ today: string;
7
+ }
@@ -0,0 +1,9 @@
1
+ export interface II18nCalendarProperties {
2
+ clear: string;
3
+ days: string[];
4
+ daysMin: string[];
5
+ daysShort: string[];
6
+ months: string[];
7
+ monthsShort: string[];
8
+ today: string;
9
+ }
@@ -0,0 +1,2 @@
1
+ export * from './II18nCalendar';
2
+ export * from './II18nCalendarProperties';
@@ -1,9 +1,11 @@
1
1
  export interface II18nChartBuilderFontOptions {
2
+ automatic_resize: string;
2
3
  color: string;
4
+ disabled: string;
5
+ select_option_placeholder: string;
6
+ size: string;
3
7
  style: string;
4
- style_regular: string;
5
8
  style_bold: string;
6
9
  style_italic: string;
7
- automatic_resize: string;
8
- size: string;
10
+ style_regular: string;
9
11
  }
@@ -5,9 +5,11 @@ import { II18nColumnTypesSuffixes } from "./II18nColumnTypesSuffixes";
5
5
  import { II18nDateGrouping } from "./II18nDateGrouping";
6
6
  import { II18nDayNames } from "./II18nDayNames";
7
7
  import { II18nUnits } from "./II18nUnits";
8
+ import { II18nCalendar } from "../calendar/II18nCalendar";
8
9
 
9
10
  export interface II18nCommon {
10
11
  aggregate_labels: II18nAgreggateLabels;
12
+ calendar: II18nCalendar;
11
13
  column_types: II18nColumnTypes;
12
14
  column_types_suffixes: II18nColumnTypesSuffixes;
13
15
  date_grouping: II18nDateGrouping;
@@ -1,4 +1,12 @@
1
1
  export interface II18nDayNames {
2
+ sunday_dd: string;
3
+ monday_dd: string;
4
+ tuesday_dd: string;
5
+ wednesday_dd: string;
6
+ thursday_dd: string;
7
+ friday_dd: string;
8
+ saturday_dd: string;
9
+
2
10
  sunday_ddd: string;
3
11
  monday_ddd: string;
4
12
  tuesday_ddd: string;
@@ -7,6 +7,7 @@ import { II18nFilterOperator } from "./II18nFilterOperator";
7
7
  import { II18nFilterScopes } from "./II18nFilterScopes";
8
8
  import { II18nFilterPanelScopeTitle } from "./II18nFilterPanelScopeTitle";
9
9
  import { II18nFilterDateSections } from "./II18nFilterDateSections";
10
+ import { II18nTokenBox } from './II18nTokenBox';
10
11
 
11
12
  export interface II18nFilter {
12
13
  date_sections: II18nFilterDateSections;
@@ -16,6 +17,7 @@ export interface II18nFilter {
16
17
  scope_title: II18nFilterPanelScopeTitle;
17
18
  scopes: II18nFilterScopes;
18
19
  slidebar: II18nSlidebar;
20
+ token_box?: II18nTokenBox;
19
21
  validators: II18nFilterValidator;
20
22
  value_container: II18nValueContainer;
21
23
  }
@@ -0,0 +1,6 @@
1
+ export interface II18nTokenBox {
2
+ data_tokens?: string;
3
+ search?: string;
4
+ system_tokens?: string;
5
+ user_tokens?: string;
6
+ }
@@ -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,9 @@
1
+ import { II18nCalendar } from "../../interfaces/calendar/II18nCalendar";
2
+
3
+ export const I18N_CALENDAR: II18nCalendar = {
4
+ clear: "Clear",
5
+ hours: 'Hours',
6
+ minutes: 'Minutes',
7
+ seconds: 'Seconds',
8
+ today: "Today"
9
+ };
@@ -0,0 +1 @@
1
+ export * from './I18N_CALENDAR';
@@ -3,7 +3,7 @@ import { II18nChartBuilder } from "../..";
3
3
  type LayerOptions = 'trends_line' | 'references_line';
4
4
  export const I18N_CHART_BUILDER_LAYER_OPTIONS: Pick<II18nChartBuilder, LayerOptions> = {
5
5
  trends_line: {
6
- title: 'Trends line',
6
+ title: 'Trend Line',
7
7
  type: 'Type',
8
8
  type_none: 'None',
9
9
  type_standard_linear_regression: 'Standard Linear Regression',
@@ -19,9 +19,9 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
19
19
  comparision_color: 'Comparision Color',
20
20
  data_labels_check: 'Data Labels',
21
21
  default_format_title: 'Format',
22
- display_outliers_check: 'Display outliers',
22
+ display_outliers_check: 'Display Outliers',
23
23
  line_opacity: 'Line Opacity',
24
- map_borders: 'Map borders',
24
+ map_borders: 'Map Borders',
25
25
  needle_color: 'Needle Color',
26
26
  opacity: 'Opacity',
27
27
  percentage_check: 'Percentage',
@@ -156,13 +156,15 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
156
156
  names_rotation: 'Names Rotation',
157
157
  },
158
158
  font_options: {
159
+ automatic_resize: 'Automatic Resize',
159
160
  color: 'Font Color',
161
+ disabled: '<i>Automatic Resize</i> is active, disable it to set the size manually.',
162
+ select_option_placeholder: 'Select Option',
163
+ size: 'Font Size',
160
164
  style: 'Font Style',
161
- style_regular: 'Regular',
162
165
  style_bold: 'Bold',
163
166
  style_italic: 'Italic',
164
- automatic_resize: 'Automatic Resize',
165
- size: 'Font Size',
167
+ style_regular: 'Regular',
166
168
  },
167
169
  circle_size: {
168
170
  title: 'Circle Size',
@@ -186,7 +188,7 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS: Pick<II18nChartBuilder, StyleOpti
186
188
  target_value: 'Target Value'
187
189
  },
188
190
  table_style_options: {
189
- typeface: 'Typeface', // used
191
+ typeface: 'Typeface',
190
192
  weight: 'Weight',
191
193
  weight_bold: 'Bold',
192
194
  weight_normal: 'normal',
@@ -1,5 +1,6 @@
1
1
  import { RELATIVE_UNIT_INFO } from "../../../dates/relative/constants/RELATIVE_UNIT_INFO";
2
2
  import { II18nCommon } from "../../interfaces/common/II18nCommon";
3
+ import { I18N_CALENDAR } from "../calendar";
3
4
  import { I18N_AGGREGATE_LABEL } from "./I18N_AGGREGATE_LABEL";
4
5
  import { I18N_COLUMN_LABEL } from "./I18N_COLUMN_LABEL";
5
6
  import { I18N_COLUMN_PROPERTY_LABEL } from "./I18N_COLUMN_PROPERTY_LABEL";
@@ -8,6 +9,7 @@ import { I18N_DAY_NAMES } from "./I18N_DAY_NAMES";
8
9
 
9
10
  export const I18N_COMMON: II18nCommon = {
10
11
  aggregate_labels: I18N_AGGREGATE_LABEL,
12
+ calendar: I18N_CALENDAR,
11
13
  column_types: I18N_COLUMN_LABEL,
12
14
  column_types_suffixes: {
13
15
  slidebar_one: 'Step',
@@ -4,6 +4,14 @@ import { capitalize } from "../../../general/string/capitalize";
4
4
  import { II18nDayNames } from "../../interfaces/common/II18nDayNames";
5
5
 
6
6
  export const I18N_DAY_NAMES: II18nDayNames = {
7
+ sunday_dd: capitalize(DATE_WEEK_DAYS[0].substring(0, 2)),
8
+ monday_dd: capitalize(DATE_WEEK_DAYS[1].substring(0, 2)),
9
+ tuesday_dd: capitalize(DATE_WEEK_DAYS[2].substring(0, 2)),
10
+ wednesday_dd: capitalize(DATE_WEEK_DAYS[3].substring(0, 2)),
11
+ thursday_dd: capitalize(DATE_WEEK_DAYS[4].substring(0, 2)),
12
+ friday_dd: capitalize(DATE_WEEK_DAYS[5].substring(0, 2)),
13
+ saturday_dd: capitalize(DATE_WEEK_DAYS[6].substring(0, 2)),
14
+
7
15
  sunday_ddd: capitalize(DATE_WEEK_DAYS[0]),
8
16
  monday_ddd: capitalize(DATE_WEEK_DAYS[1]),
9
17
  tuesday_ddd: capitalize(DATE_WEEK_DAYS[2]),
@@ -28,6 +28,12 @@ export const I18N_FILTER: II18nFilter = {
28
28
  },
29
29
  scopes: I18N_FILTER_SCOPE,
30
30
  slidebar: I18N_SLIDEBAR,
31
+ token_box: {
32
+ data_tokens: 'DataTokens',
33
+ search: 'Search',
34
+ system_tokens: 'SystemTokens',
35
+ user_tokens: 'UserTokens',
36
+ },
31
37
  validators: I18N_FILTER_VALIDATOR,
32
38
  value_container: I18N_VALUE_CONTAINER,
33
39
  };
@@ -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,4 @@
1
+ export interface IFormatCurrency {
2
+ text: string;
3
+ label: string;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { IFormatCurrency } from "./IFormatCurrency.Interface";
2
+
3
+ export interface IFormatOutputFormat {
4
+ format: string;
5
+ type: string;
6
+ decimals?: number;
7
+ currency?: IFormatCurrency;
8
+ backup_currency?: IFormatCurrency;
9
+ }
@@ -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';
@@ -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
+ }
@@ -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,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,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,6 +3,8 @@ import { IDataset } from "../../qrvey/interfaces/IDataset";
3
3
  import { CHART_ENDPOINT } from "../constants/CHART_ENDPOINT";
4
4
  import Request from "../helpers/Request";
5
5
  import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter";
6
+ import { LANG_DEFAULT } from "../../format/definition";
7
+ import { getLang } from "../..";
6
8
 
7
9
  /**
8
10
  * Get a dataset by Qrvey ID
@@ -10,10 +12,11 @@ import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter
10
12
  * @returns a promise
11
13
  */
12
14
  export function getDatasetColumns(config: IGeneralWidgetConfig, qrveyid?: string): Promise<IDataset[]> {
15
+ const lang = getLang(config.lang || (<any>config.locale)?.lang || config.locale || LANG_DEFAULT).lang;
13
16
  return Request.post({ ...config, qrveyid, endpoint: CHART_ENDPOINT }, '/question/list', {
14
17
  'optionsAttributes': ['id', 'text', 'type', 'property', 'linked', 'linkid', 'qrveyid', 'bucketId', 'formulaId', 'formulaType', 'geogroup', 'outputFormat'],
15
18
  'extend': true
16
- })
19
+ }, { lang })
17
20
  .then(BDatasetsToUIDatasets)
18
21
  .catch(_e => []);
19
22
  }