@qrvey/utils 1.2.9-21 → 1.2.9-24

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 (53) hide show
  1. package/README.md +295 -295
  2. package/dist/cjs/columns/interfaces/IColumn.d.ts +0 -2
  3. package/dist/cjs/dates/constants/DATETIME_COLUMN_FORMAT.d.ts +1 -0
  4. package/dist/cjs/dates/constants/DATETIME_COLUMN_FORMAT.js +11 -0
  5. package/dist/cjs/dates/constants/index.d.ts +1 -0
  6. package/dist/cjs/dates/constants/index.js +1 -0
  7. package/dist/cjs/filters/adapters/FDToFlatUI.js +1 -1
  8. package/dist/cjs/filters/adapters/FDToUI.js +1 -2
  9. package/dist/cjs/filters/adapters/logicToFlatUI.js +3 -3
  10. package/dist/cjs/filters/helpers/ui/getUpdatedUIFilters.js +1 -1
  11. package/dist/cjs/filters/interfaces/OLD_IFilterDetail.d.ts +4 -1
  12. package/dist/cjs/format/definition.d.ts +16 -2
  13. package/dist/cjs/format/definition.js +3 -1
  14. package/dist/cjs/format/format.js +1 -1
  15. package/dist/cjs/format/localization.js +24 -9
  16. package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderDimensions.d.ts +1 -0
  17. package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_GENERAL.js +1 -0
  18. package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
  19. package/dist/cjs/qrvey/helpers/transformValue.js +1 -1
  20. package/dist/columns/interfaces/IColumn.d.ts +0 -2
  21. package/dist/dates/constants/DATETIME_COLUMN_FORMAT.d.ts +1 -0
  22. package/dist/dates/constants/DATETIME_COLUMN_FORMAT.js +8 -0
  23. package/dist/dates/constants/index.d.ts +1 -0
  24. package/dist/dates/constants/index.js +1 -0
  25. package/dist/filters/adapters/FDToFlatUI.js +1 -1
  26. package/dist/filters/adapters/FDToUI.js +1 -2
  27. package/dist/filters/adapters/logicToFlatUI.js +3 -3
  28. package/dist/filters/helpers/ui/getUpdatedUIFilters.js +1 -1
  29. package/dist/filters/interfaces/OLD_IFilterDetail.d.ts +4 -1
  30. package/dist/format/definition.d.ts +16 -2
  31. package/dist/format/definition.js +2 -0
  32. package/dist/format/format.js +1 -1
  33. package/dist/format/localization.js +25 -10
  34. package/dist/globalization/interfaces/chart_builder/II18nChartBuilderDimensions.d.ts +1 -0
  35. package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_GENERAL.js +1 -0
  36. package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
  37. package/dist/qrvey/helpers/transformValue.js +1 -1
  38. package/package.json +1 -1
  39. package/src/columns/interfaces/IColumn.ts +0 -2
  40. package/src/dates/constants/DATETIME_COLUMN_FORMAT.ts +8 -0
  41. package/src/dates/constants/index.ts +1 -0
  42. package/src/filters/adapters/FDToFlatUI.ts +1 -1
  43. package/src/filters/adapters/FDToUI.ts +1 -1
  44. package/src/filters/adapters/logicToFlatUI.ts +1 -1
  45. package/src/filters/helpers/ui/getUpdatedUIFilters.ts +1 -1
  46. package/src/filters/interfaces/OLD_IFilterDetail.ts +2 -1
  47. package/src/format/definition.ts +6 -1
  48. package/src/format/format.ts +1 -1
  49. package/src/format/localization.ts +24 -10
  50. package/src/globalization/interfaces/chart_builder/II18nChartBuilderDimensions.ts +1 -0
  51. package/src/globalization/labels/chart_builder/I18N_CHART_BUILDER_GENERAL.ts +1 -0
  52. package/src/interfaces/format/IFormatOutputFormat.Interface.ts +2 -1
  53. package/src/qrvey/helpers/transformValue.ts +1 -1
@@ -18,7 +18,7 @@ export function getUpdatedUIFilters(data: IFUData, datasets: IDataset[] = []): I
18
18
  if (!isEmpty(datasetInfo)) dataset.label = datasetInfo.label;
19
19
  dataset.filters = dataset.filters.map(filter => {
20
20
  let columnInfo: IColumn;
21
- if (!isEmpty(datasetInfo)) columnInfo = datasetInfo.options.find(cInfo => cInfo.id === filter.column.id && cInfo.dataset?.qrveyid === filter.column.qrveyid && cInfo.dataset?.linkid === filter.column.linkid);
21
+ if (!isEmpty(datasetInfo)) columnInfo = datasetInfo.options.find(cInfo => cInfo.id === filter.column.id && cInfo.qrveyid === filter.column.qrveyid && cInfo.linkid === filter.column.linkid);
22
22
  if (!isEmpty(columnInfo)) {
23
23
  filter.column.formulaType = columnInfo.formulaType;
24
24
  filter.column.label = columnInfo.label;
@@ -1,4 +1,5 @@
1
1
  import { IColumn } from "../../columns/interfaces/IColumn";
2
+ import { IDataset } from "../../qrvey/interfaces/IDataset";
2
3
  import { IFSFilterExtrasInfo } from "./common/IFSFilterExtrasInfo";
3
4
  import { IFDateSection } from "./IFDateSection";
4
5
  import { IFOperator } from "./IFOperator";
@@ -11,7 +12,7 @@ import { IFUChartSettings } from "./ui/IFUChartSettings";
11
12
  import { IFUValue } from "./ui/IFUValue";
12
13
 
13
14
  export interface OLD_IFilterDetail {
14
- column?: IColumn;
15
+ column?: IColumn & { dataset: IDataset };
15
16
  dateSection?: IFDateSection;
16
17
  enabled?: boolean;
17
18
  lookupDisplayIndex?: number;
@@ -91,12 +91,17 @@ export const enum LOCALE_FORMATS {
91
91
  CURRENCY = 'Currency',
92
92
  PERCENTAGE = 'Percentage',
93
93
  SCIENTIFIC = 'Scientific',
94
+ ABBREVIATED = 'Abbreviated'
94
95
  }
95
96
  export const enum LOCALE_STYLES {
96
97
  DECIMAL = 'decimal',
97
98
  PERCENT = 'percent',
98
99
  CURRENCY = 'currency',
99
100
  SCIENTIFIC = 'scientific',
101
+ COMPACT = 'compact'
100
102
  }
101
103
 
102
- export const LANG_DEFAULT = 'en-US';
104
+ export const LANG_DEFAULT = 'en-US';
105
+ export const CURRENCY_DEFAULT = { text: '$ (USD)', label: 'USD' };
106
+ export const DATETIME_OPTIONS = { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' };
107
+
@@ -92,7 +92,7 @@ export const addFormat = (value: any, outputFormat: any = 'None', config?: IForm
92
92
  return config?.lang && outputFormat.format === 'Default' ? formatWithLocale(value, outputFormat, config) : formatDate(value, outputFormat.format);
93
93
  case 'NUMERIC': {
94
94
  const parse = parseFloat(value);
95
- const withLocale = outputFormat.format !== 'Abbreviated' && outputFormat !== 'None' && config?.lang;
95
+ const withLocale = outputFormat !== 'None' && config?.lang;
96
96
  return isNaN(parse) ? value : withLocale ? formatWithLocale(value, outputFormat, config)
97
97
  : formatNumber(parse, outputFormat, config);
98
98
  }
@@ -1,5 +1,7 @@
1
+ import { DATETIME_COLUMN_FORMAT } from '..';
2
+ import { isEmpty } from '../general/mix/isEmpty';
1
3
  import { IFormatConfig, IFormatOutputFormat } from '../interfaces';
2
- import { currencyISO, LOCALE_FORMATS, LOCALE_STYLES, LANG_DEFAULT } from './definition';
4
+ import { currencyISO, LOCALE_FORMATS, LOCALE_STYLES, LANG_DEFAULT, CURRENCY_DEFAULT, DATETIME_OPTIONS } from './definition';
3
5
 
4
6
  export const getLang = (locale: string | Record<string, any>) => {
5
7
  if (!locale) return;
@@ -19,19 +21,24 @@ export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat,
19
21
  switch (outputFormat.type) {
20
22
  case 'DATE':
21
23
  case 'DATETIME':
22
- return formatLocaleDate(value, config);
24
+ return formatLocaleDate(value, outputFormat, config);
23
25
  case 'NUMERIC':
24
26
  return formatLocaleNumber(value, outputFormat, config);
25
27
  }
26
28
  };
27
29
 
28
- function formatLocaleDate(value: any, config: IFormatConfig) {
30
+ function formatLocaleDate(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig) {
29
31
  const { lang = LANG_DEFAULT, options } = config;
30
32
  const dateParam = new Date(value);
33
+ let langOpts = options;
34
+ if (outputFormat?.originalFormat) {
35
+ const { format } = outputFormat.originalFormat;
36
+ if (DATETIME_COLUMN_FORMAT.includes(format)) langOpts = DATETIME_OPTIONS;
37
+ }
31
38
  try {
32
- return new Intl.DateTimeFormat([lang, LANG_DEFAULT], options).format(dateParam);
39
+ return new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts).format(dateParam);
33
40
  } catch (error) {
34
- return new Intl.DateTimeFormat(LANG_DEFAULT, options).format(dateParam);
41
+ return new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
35
42
  }
36
43
  }
37
44
 
@@ -49,12 +56,19 @@ function getLocaleOptions(outputFormat: IFormatOutputFormat) {
49
56
  const { format, decimals, currency } = outputFormat;
50
57
  switch(format) {
51
58
  case LOCALE_FORMATS.CURRENCY: {
52
- const iso = currencyISO.find(item => (item.text === currency.text) || (item.text.includes(currency.label)));
53
- return { style: LOCALE_STYLES.CURRENCY, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: 0 };
59
+ let iso = isEmpty(currency) ? CURRENCY_DEFAULT : currencyISO.find(item => item.text === currency.text);
60
+ if(isEmpty(iso)) {
61
+ iso = currencyISO.find(item => {
62
+ const symbol = item.text.split(' ')[0];
63
+ return symbol === currency.label;
64
+ });
65
+ }
66
+ return { style: LOCALE_STYLES.CURRENCY, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: decimals, currencyDisplay: 'narrowSymbol' };
54
67
  }
55
68
  case LOCALE_FORMATS.SCIENTIFIC: return { style: LOCALE_STYLES.DECIMAL,
56
- notation: LOCALE_STYLES.SCIENTIFIC, maximumFractionDigits: decimals };
57
- case LOCALE_FORMATS.PERCENTAGE: return { style: LOCALE_STYLES.PERCENT, maximumFractionDigits: decimals };
58
- default: return { style: LOCALE_STYLES.DECIMAL, maximumFractionDigits: decimals };
69
+ notation: LOCALE_STYLES.SCIENTIFIC, maximumFractionDigits: decimals, minimumFractionDigits: decimals };
70
+ case LOCALE_FORMATS.PERCENTAGE: return { style: LOCALE_STYLES.PERCENT, maximumFractionDigits: decimals, minimumFractionDigits: decimals };
71
+ case LOCALE_FORMATS.ABBREVIATED: return { notation: LOCALE_STYLES.COMPACT, maximumFractionDigits: decimals, minimumFractionDigits: decimals };
72
+ default: return { style: LOCALE_STYLES.DECIMAL, maximumFractionDigits: decimals, minimumFractionDigits: decimals };
59
73
  }
60
74
  }
@@ -8,6 +8,7 @@ export interface II18nChartBuilderDimensions {
8
8
  geolocation: string;
9
9
  group: string;
10
10
  groups: string;
11
+ other_value: string;
11
12
  other_values: string;
12
13
  pivot: string;
13
14
  row: string;
@@ -85,6 +85,7 @@ export const I18N_CHART_BUILDER_GENERAL: Pick<II18nChartBuilder, General> = {
85
85
  geolocation: 'Geolocation',
86
86
  group: 'Group',
87
87
  groups: 'Groups',
88
+ other_value: 'Other Value',
88
89
  other_values: 'Other Values',
89
90
  pivot: 'Pivot',
90
91
  row: 'Row',
@@ -6,4 +6,5 @@ export interface IFormatOutputFormat {
6
6
  decimals?: number;
7
7
  currency?: IFormatCurrency;
8
8
  backup_currency?: IFormatCurrency;
9
- }
9
+ originalFormat?: any;
10
+ }
@@ -43,5 +43,5 @@ function getOutputFormat(settings: ITransformValueSettings) {
43
43
  * @returns the format config
44
44
  */
45
45
  function getFormatConfig(settings: ITransformValueSettings) {
46
- return { lang: settings.i18n?.lang };
46
+ return { lang: settings.i18n?.locale };
47
47
  }