@qrvey/utils 1.2.9-15 → 1.2.9-16
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 +251 -148
- 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 +3 -0
- package/dist/cjs/format/localization.js +56 -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 +1 -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 +45 -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 +1 -0
- 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 +3 -0
- package/dist/format/localization.js +51 -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 +1 -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 +41 -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 +1 -0
- 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 +52 -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 +1 -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 +46 -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 +1 -0
- package/test/format.test.js +11 -11
|
@@ -12,6 +12,7 @@ function getFilterBuilderGeneralConfig(config = {}) {
|
|
|
12
12
|
apiKey: (0, getAttribute_1.getAttribute)(config, 'api_key') || config.apiKey,
|
|
13
13
|
appid: (0, getAttribute_1.getAttribute)(config, 'app_id') || config.appid,
|
|
14
14
|
domain: config.domain,
|
|
15
|
+
locale: config.locale,
|
|
15
16
|
qv_token: config.qv_token,
|
|
16
17
|
timezoneControl: (0, getAttribute_1.getAttribute)(config, 'timezone_control') || config.timezoneControl,
|
|
17
18
|
userid: (0, getAttribute_1.getAttribute)(config, 'user_id') || config.userid,
|
|
@@ -20,3 +20,4 @@ __exportStar(require("./getUIFlatFiltersByParams"), exports);
|
|
|
20
20
|
__exportStar(require("./getUIFlatFiltersByScopes"), exports);
|
|
21
21
|
__exportStar(require("./getUIValues"), exports);
|
|
22
22
|
__exportStar(require("./getUpdatedUIFilters"), exports);
|
|
23
|
+
__exportStar(require("./transformFilterValues"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IFSFilter } from "../../interfaces/common/IFSFilter";
|
|
2
|
+
import { IFValue } from "../../interfaces/IFValue";
|
|
3
|
+
import { IFUTransformFilterValuesSettings } from "../../interfaces/ui/IFUTransformFilterValuesSettings";
|
|
4
|
+
export declare function transformFilterValues(filter: IFSFilter, settings: IFUTransformFilterValuesSettings): IFValue[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformFilterValues = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../../general/mix/isEmpty");
|
|
5
|
+
const transformValue_1 = require("../../../qrvey/helpers/transformValue");
|
|
6
|
+
const isRangeValidator_1 = require("../common/isRangeValidator");
|
|
7
|
+
const isRegularValidator_1 = require("../common/isRegularValidator");
|
|
8
|
+
function transformFilterValues(filter, settings) {
|
|
9
|
+
const transformValueSettings = Object.assign(Object.assign({}, settings), { column: filter.column, property: filter.property });
|
|
10
|
+
if ((0, isEmpty_1.isEmpty)(filter))
|
|
11
|
+
return [];
|
|
12
|
+
if ((0, isRegularValidator_1.isRegularValidator)(filter.validator)) {
|
|
13
|
+
return filter.values.map((value) => (Object.assign(Object.assign({}, value), { value: (0, transformValue_1.transformValue)(value.value, transformValueSettings) })));
|
|
14
|
+
}
|
|
15
|
+
else if ((0, isRangeValidator_1.isRangeValidator)(filter.validator)) {
|
|
16
|
+
return filter.values.map((value) => (Object.assign(Object.assign({}, value), { min: (0, transformValue_1.transformValue)(value.min, transformValueSettings), max: (0, transformValue_1.transformValue)(value.max, transformValueSettings) })));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return filter.values;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.transformFilterValues = transformFilterValues;
|
|
@@ -18,7 +18,8 @@ export * from './IFUDataset';
|
|
|
18
18
|
export * from './IFUFilter';
|
|
19
19
|
export * from './IFUFilterExtras';
|
|
20
20
|
export * from './IFUFlattenedFilter';
|
|
21
|
-
export * from './IFUScope';
|
|
22
21
|
export * from './IFUParamsToGetFilter';
|
|
23
|
-
export * from './
|
|
22
|
+
export * from './IFUScope';
|
|
23
|
+
export * from './IFUTransformFilterValuesSettings';
|
|
24
24
|
export * from './IFUUIValueSettings';
|
|
25
|
+
export * from './IFUValue';
|
|
@@ -30,7 +30,8 @@ __exportStar(require("./IFUDataset"), exports);
|
|
|
30
30
|
__exportStar(require("./IFUFilter"), exports);
|
|
31
31
|
__exportStar(require("./IFUFilterExtras"), exports);
|
|
32
32
|
__exportStar(require("./IFUFlattenedFilter"), exports);
|
|
33
|
-
__exportStar(require("./IFUScope"), exports);
|
|
34
33
|
__exportStar(require("./IFUParamsToGetFilter"), exports);
|
|
35
|
-
__exportStar(require("./
|
|
34
|
+
__exportStar(require("./IFUScope"), exports);
|
|
35
|
+
__exportStar(require("./IFUTransformFilterValuesSettings"), exports);
|
|
36
36
|
__exportStar(require("./IFUUIValueSettings"), exports);
|
|
37
|
+
__exportStar(require("./IFUValue"), exports);
|
|
@@ -11,3 +11,20 @@ export declare const isComplexColumn: (column?: any) => boolean;
|
|
|
11
11
|
export declare const isNumericalColumn: (column?: any) => boolean;
|
|
12
12
|
export declare function supportNumericFormatting(chartType: ChartType): boolean;
|
|
13
13
|
export declare const isTextColumn: (column: any) => boolean;
|
|
14
|
+
export declare const currencyISO: {
|
|
15
|
+
text: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
export declare const enum LOCALE_FORMATS {
|
|
19
|
+
DECIMAL = "Decimal",
|
|
20
|
+
CURRENCY = "Currency",
|
|
21
|
+
PERCENTAGE = "Percentage",
|
|
22
|
+
SCIENTIFIC = "Scientific"
|
|
23
|
+
}
|
|
24
|
+
export declare const enum LOCALE_STYLES {
|
|
25
|
+
DECIMAL = "decimal",
|
|
26
|
+
PERCENT = "percent",
|
|
27
|
+
CURRENCY = "currency",
|
|
28
|
+
SCIENTIFIC = "scientific"
|
|
29
|
+
}
|
|
30
|
+
export declare const LANG_DEFAULT = "en-US";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTextColumn = exports.supportNumericFormatting = exports.isNumericalColumn = exports.isComplexColumn = exports.hasfileSizeProperty = exports.appliesFormatting = exports.DATEGROUP_FORMATTING_UNSUPPORT = exports.QUESTION_FORMAT_SUPPORT = exports.numericalFields = exports.complexFields = exports.textFields = void 0;
|
|
3
|
+
exports.LANG_DEFAULT = exports.currencyISO = exports.isTextColumn = exports.supportNumericFormatting = exports.isNumericalColumn = exports.isComplexColumn = exports.hasfileSizeProperty = exports.appliesFormatting = exports.DATEGROUP_FORMATTING_UNSUPPORT = exports.QUESTION_FORMAT_SUPPORT = exports.numericalFields = exports.complexFields = exports.textFields = void 0;
|
|
4
4
|
const COLUMN_1 = require("../columns/constants/COLUMN");
|
|
5
5
|
const Charts_Const_1 = require("../constants/Charts.Const");
|
|
6
6
|
exports.textFields = [COLUMN_1.COLUMN.TEXTFIELD, COLUMN_1.COLUMN.TEXT_CATEGORY, COLUMN_1.COLUMN.TEXT_LABEL, COLUMN_1.COLUMN.TEXT_CATEGORY];
|
|
@@ -52,3 +52,33 @@ function supportNumericFormatting(chartType) {
|
|
|
52
52
|
exports.supportNumericFormatting = supportNumericFormatting;
|
|
53
53
|
const isTextColumn = (column) => exports.textFields.includes(column.type) || column.formulaType === 'string' || column.formulaType === 'boolean';
|
|
54
54
|
exports.isTextColumn = isTextColumn;
|
|
55
|
+
exports.currencyISO = [
|
|
56
|
+
{ text: 'Default', label: 'USD' },
|
|
57
|
+
{ text: '$ (USD)', label: 'USD' },
|
|
58
|
+
{ text: '€ (EUR)', label: 'EUR' },
|
|
59
|
+
{ text: '¥ (JPY)', label: 'JPY' },
|
|
60
|
+
{ text: '£ (GBP)', label: 'GBP' },
|
|
61
|
+
{ text: '₩ (WON)', label: 'WON' },
|
|
62
|
+
{ text: '$ (AUD)', label: 'AUD' },
|
|
63
|
+
{ text: '$ (CAD)', label: 'CAD' },
|
|
64
|
+
{ text: 'CHF (CHF)', label: 'CHF' },
|
|
65
|
+
{ text: '¥ (CNY)', label: 'CNY' },
|
|
66
|
+
{ text: 'kr (SEK)', label: 'SEK' },
|
|
67
|
+
{ text: '$ (MXN)', label: 'MXN' },
|
|
68
|
+
{ text: '$ (NZD)', label: 'NZD' },
|
|
69
|
+
{ text: '$ (SGD)', label: 'SGD' },
|
|
70
|
+
{ text: '$ (HKD)', label: 'HKD' },
|
|
71
|
+
{ text: 'kr (NOK)', label: 'NOK' },
|
|
72
|
+
{ text: '₩ (KRW)', label: 'KRW' },
|
|
73
|
+
{ text: '₺ (TRY)', label: 'TRY' },
|
|
74
|
+
{ text: '₹ (INR)', label: 'INR' },
|
|
75
|
+
{ text: '₽ (RUB)', label: 'RUB' },
|
|
76
|
+
{ text: 'R$ (BRL)', label: 'BRL' },
|
|
77
|
+
{ text: 'R (ZAR)', label: 'ZAR' },
|
|
78
|
+
{ text: 'kr (DKK)', label: 'DKK' },
|
|
79
|
+
{ text: 'zł (PLN)', label: 'PLN' },
|
|
80
|
+
{ text: 'NT$ (TWD)', label: 'TWD' },
|
|
81
|
+
{ text: '฿ (THB)', label: 'THB' },
|
|
82
|
+
{ text: 'RM (MYR)', label: 'MYR' }
|
|
83
|
+
];
|
|
84
|
+
exports.LANG_DEFAULT = 'en-US';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IFormatConfig } from '..';
|
|
1
2
|
export declare function formatDate(dateString: any, format: any): any;
|
|
2
3
|
export declare function formatAbbreviated(num: any, decimals: any): any;
|
|
3
4
|
/**
|
|
@@ -5,7 +6,7 @@ export declare function formatAbbreviated(num: any, decimals: any): any;
|
|
|
5
6
|
* @param bytes type number
|
|
6
7
|
*/
|
|
7
8
|
export declare function formatFileSize(bytes: number): string;
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const addFormat: (value: any, outputFormat?: any, config?: IFormatConfig) => any;
|
|
9
10
|
export declare const parseFormulaType: (type: string) => "DATE" | "NUMERIC" | "TEXT_LABEL";
|
|
10
11
|
export declare const validateColumnType: (column: any) => any;
|
|
11
12
|
export declare const defineFormat: (column?: any, isSimpleTable?: boolean, isCategoryDimension?: boolean) => any;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defineFormat = exports.validateColumnType = exports.parseFormulaType = exports.
|
|
6
|
+
exports.defineFormat = exports.validateColumnType = exports.parseFormulaType = exports.addFormat = exports.formatFileSize = exports.formatAbbreviated = exports.formatDate = void 0;
|
|
7
7
|
const d3_1 = require("d3");
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
9
|
const definition_1 = require("./definition");
|
|
@@ -12,6 +12,7 @@ const isEmpty_1 = require("../general/mix/isEmpty");
|
|
|
12
12
|
const get_1 = require("../general/object/get");
|
|
13
13
|
const COLUMN_1 = require("../columns/constants/COLUMN");
|
|
14
14
|
const FORMULA_1 = require("../formulas/constants/FORMULA");
|
|
15
|
+
const localization_1 = require("./localization");
|
|
15
16
|
dayjs_1.default.extend(advancedFormat_1.default); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
|
|
16
17
|
/**
|
|
17
18
|
* Apply to the given date format to a date value
|
|
@@ -83,16 +84,18 @@ function formatFileSize(bytes) {
|
|
|
83
84
|
return megaBytes < 10 ? `${fixDecimals(megaBytes)} MB` : `${Math.round(megaBytes)} MB`;
|
|
84
85
|
}
|
|
85
86
|
exports.formatFileSize = formatFileSize;
|
|
86
|
-
const
|
|
87
|
+
const addFormat = (value, outputFormat = 'None', config) => {
|
|
87
88
|
if ((0, isEmpty_1.isEmpty)(value) || typeof value === 'object' && (0, isEmpty_1.isEmpty)(value[0]))
|
|
88
89
|
return value;
|
|
89
90
|
switch (outputFormat.type) {
|
|
90
91
|
case 'DATE':
|
|
91
92
|
case 'DATETIME':
|
|
92
|
-
return formatDate(value, outputFormat.format);
|
|
93
|
+
return (config === null || config === void 0 ? void 0 : config.lang) && outputFormat.format === 'Default' ? (0, localization_1.formatWithLocale)(value, outputFormat, config) : formatDate(value, outputFormat.format);
|
|
93
94
|
case 'NUMERIC': {
|
|
94
95
|
const parse = parseFloat(value);
|
|
95
|
-
|
|
96
|
+
const withLocale = outputFormat.format !== 'Abbreviated' && outputFormat !== 'None' && (config === null || config === void 0 ? void 0 : config.lang);
|
|
97
|
+
return isNaN(parse) ? value : withLocale ? (0, localization_1.formatWithLocale)(value, outputFormat, config)
|
|
98
|
+
: formatNumber(parse, outputFormat, config);
|
|
96
99
|
}
|
|
97
100
|
case 'IMAGEUPLOAD':
|
|
98
101
|
case 'FILEUPLOAD':
|
|
@@ -101,7 +104,7 @@ const formatValue = (value, outputFormat = 'None', config) => {
|
|
|
101
104
|
return typeof value === 'number' ? value.toFixed(0) : value;
|
|
102
105
|
}
|
|
103
106
|
};
|
|
104
|
-
exports.
|
|
107
|
+
exports.addFormat = addFormat;
|
|
105
108
|
const parseFormulaType = (type) => {
|
|
106
109
|
switch (type) {
|
|
107
110
|
case FORMULA_1.FORMULA.NUMBER:
|
package/dist/cjs/format/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatWithLocale = exports.getLang = void 0;
|
|
4
|
+
const definition_1 = require("./definition");
|
|
5
|
+
const getLang = (locale) => {
|
|
6
|
+
if (!locale)
|
|
7
|
+
return;
|
|
8
|
+
else if (typeof locale === 'object')
|
|
9
|
+
return locale;
|
|
10
|
+
else
|
|
11
|
+
return { lang: locale === "browser" ? window.navigator.language : locale };
|
|
12
|
+
};
|
|
13
|
+
exports.getLang = getLang;
|
|
14
|
+
const formatWithLocale = (value, outputFormat, config = {}) => {
|
|
15
|
+
switch (outputFormat.type) {
|
|
16
|
+
case 'DATE':
|
|
17
|
+
case 'DATETIME':
|
|
18
|
+
return formatLocaleDate(value, config);
|
|
19
|
+
case 'NUMERIC':
|
|
20
|
+
return formatLocaleNumber(value, outputFormat, config);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.formatWithLocale = formatWithLocale;
|
|
24
|
+
function formatLocaleDate(value, config) {
|
|
25
|
+
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
26
|
+
const dateParam = new Date(value);
|
|
27
|
+
try {
|
|
28
|
+
return new Intl.DateTimeFormat([lang, definition_1.LANG_DEFAULT], options).format(dateParam);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return new Intl.DateTimeFormat(definition_1.LANG_DEFAULT, options).format(dateParam);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function formatLocaleNumber(value, outputFormat, config) {
|
|
35
|
+
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
36
|
+
const langOpts = options || getLocaleOptions(outputFormat);
|
|
37
|
+
try {
|
|
38
|
+
return new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts).format(value);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return new Intl.NumberFormat(definition_1.LANG_DEFAULT, langOpts).format(value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function getLocaleOptions(outputFormat) {
|
|
45
|
+
const { format, decimals, currency, backup_currency } = outputFormat;
|
|
46
|
+
switch (format) {
|
|
47
|
+
case "Currency" /* CURRENCY */: {
|
|
48
|
+
const iso = definition_1.currencyISO.find(item => item.text === (currency.text || backup_currency.text));
|
|
49
|
+
return { style: "currency" /* CURRENCY */, currency: iso.label, maximumFractionDigits: decimals, minimumFractionDigits: 0 };
|
|
50
|
+
}
|
|
51
|
+
case "Scientific" /* SCIENTIFIC */: return { style: "decimal" /* DECIMAL */,
|
|
52
|
+
notation: "scientific" /* SCIENTIFIC */, maximumFractionDigits: decimals };
|
|
53
|
+
case "Percentage" /* PERCENTAGE */: return { style: "percent" /* PERCENT */, maximumFractionDigits: decimals };
|
|
54
|
+
default: return { style: "decimal" /* DECIMAL */, maximumFractionDigits: decimals };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./IFormatConfig.Interface"), exports);
|
|
14
|
+
__exportStar(require("./IFormatOutputFormat.Interface"), exports);
|
|
15
|
+
__exportStar(require("./IFormatCurrency.Interface"), exports);
|
|
@@ -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,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValueWithSuffixes = void 0;
|
|
4
|
+
const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
5
|
+
const isNaNV2_1 = require("../../general/mix/isNaNV2");
|
|
6
|
+
/**
|
|
7
|
+
* Get a string value with suffixes if available.
|
|
8
|
+
* Add suffix into the value string. Prioritized for numeric values.
|
|
9
|
+
* @param value a number or string
|
|
10
|
+
* @param suffixes An object with singular or plural suffix string.
|
|
11
|
+
* @returns a string value with suffix
|
|
12
|
+
*/
|
|
13
|
+
function getValueWithSuffixes(value, settings) {
|
|
14
|
+
let suffix = '';
|
|
15
|
+
if (!(0, isNaNV2_1.isNaNV2)(value)) {
|
|
16
|
+
if (!(0, isEmpty_1.isEmpty)(settings.suffixTranslateLabel) && !(0, isEmpty_1.isEmpty)(settings.translate))
|
|
17
|
+
suffix = settings.translate(settings.suffixTranslateLabel, { count: +value });
|
|
18
|
+
if (!(0, isEmpty_1.isEmpty)(settings.suffixes))
|
|
19
|
+
suffix = (+value > 1 || +value === 0) ? settings.suffixes.plural : settings.suffixes.singular;
|
|
20
|
+
}
|
|
21
|
+
return value + (!(0, isEmpty_1.isEmpty)(suffix) ? ' ' + suffix : '');
|
|
22
|
+
}
|
|
23
|
+
exports.getValueWithSuffixes = getValueWithSuffixes;
|
|
@@ -12,3 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./getColumnsLabel"), exports);
|
|
14
14
|
__exportStar(require("./getPropertyLabel"), exports);
|
|
15
|
+
__exportStar(require("./getValueWithSuffixes"), exports);
|
|
16
|
+
__exportStar(require("./transformValue"), exports);
|
|
@@ -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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformValue = void 0;
|
|
4
|
+
const isDateColumn_1 = require("../../columns/helpers/isDateColumn");
|
|
5
|
+
const isNumericalColumn_1 = require("../../columns/helpers/isNumericalColumn");
|
|
6
|
+
const DATE_GROUPING_PROPERTY_1 = require("../../dates/constants/DATE_GROUPING_PROPERTY");
|
|
7
|
+
const format_1 = require("../../format/format");
|
|
8
|
+
const getI18nDateGroupLabel_1 = require("../../globalization/helpers/getI18nDateGroupLabel");
|
|
9
|
+
const getValueWithSuffixes_1 = require("./getValueWithSuffixes");
|
|
10
|
+
/**
|
|
11
|
+
* Transforms a value depending of localization/globalization and extras settings.
|
|
12
|
+
* @param value A value to transform
|
|
13
|
+
* @param settings The settings of the transformValue function
|
|
14
|
+
* @returns A transformed value
|
|
15
|
+
*/
|
|
16
|
+
function transformValue(value, settings) {
|
|
17
|
+
const valueWithI18n = (0, getI18nDateGroupLabel_1.getI18nDateGroupLabel)(value, settings.property, settings.translate);
|
|
18
|
+
const valueWithLocalization = (0, format_1.addFormat)(valueWithI18n, getOutputFormat(settings), getFormatConfig(settings));
|
|
19
|
+
return (0, getValueWithSuffixes_1.getValueWithSuffixes)(valueWithLocalization, { suffixTranslateLabel: settings.suffixTranslateLabel, translate: settings.translate });
|
|
20
|
+
}
|
|
21
|
+
exports.transformValue = transformValue;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the outputformat settings
|
|
24
|
+
* @param settings The settings of the transformValue function
|
|
25
|
+
* @returns the outputformat settings
|
|
26
|
+
*/
|
|
27
|
+
function getOutputFormat(settings) {
|
|
28
|
+
let type, format;
|
|
29
|
+
if ((0, isDateColumn_1.isDateColumn)(settings.column) && settings.property === DATE_GROUPING_PROPERTY_1.DATE_GROUPING_PROPERTY.DAY) {
|
|
30
|
+
type = 'DATE';
|
|
31
|
+
format = 'Default';
|
|
32
|
+
}
|
|
33
|
+
else if ((0, isNumericalColumn_1.isNumericalColumn)(settings.column)) {
|
|
34
|
+
type = 'NUMERIC';
|
|
35
|
+
}
|
|
36
|
+
return { type, format };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the format config
|
|
40
|
+
* @param settings The settings of the transformValue function
|
|
41
|
+
* @returns the format config
|
|
42
|
+
*/
|
|
43
|
+
function getFormatConfig(settings) {
|
|
44
|
+
return { lang: settings.locale };
|
|
45
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -15,3 +15,5 @@ __exportStar(require("./ICalculation"), exports);
|
|
|
15
15
|
__exportStar(require("./ICalculationInfo"), exports);
|
|
16
16
|
__exportStar(require("./ICalculationType"), exports);
|
|
17
17
|
__exportStar(require("./IDataset"), exports);
|
|
18
|
+
__exportStar(require("./IGetValueWithSuffixesSettings"), exports);
|
|
19
|
+
__exportStar(require("./ITransformValueSettings"), exports);
|
|
@@ -14,6 +14,7 @@ const BDatasetsToUIDatasets_adapter_1 = require("../adapters/BDatasetsToUIDatase
|
|
|
14
14
|
*/
|
|
15
15
|
function getDatasetColumns(config, qrveyid) {
|
|
16
16
|
return Request_1.default.post(Object.assign(Object.assign({}, config), { qrveyid, endpoint: CHART_ENDPOINT_1.CHART_ENDPOINT }), '/question/list', {
|
|
17
|
+
'lang': config.locale,
|
|
17
18
|
'optionsAttributes': ['id', 'text', 'type', 'property', 'linked', 'linkid', 'qrveyid', 'bucketId', 'formulaId', 'formulaType', 'geogroup', 'outputFormat'],
|
|
18
19
|
'extend': true
|
|
19
20
|
})
|
|
@@ -9,6 +9,7 @@ export function getFilterBuilderGeneralConfig(config = {}) {
|
|
|
9
9
|
apiKey: getAttribute(config, 'api_key') || config.apiKey,
|
|
10
10
|
appid: getAttribute(config, 'app_id') || config.appid,
|
|
11
11
|
domain: config.domain,
|
|
12
|
+
locale: config.locale,
|
|
12
13
|
qv_token: config.qv_token,
|
|
13
14
|
timezoneControl: getAttribute(config, 'timezone_control') || config.timezoneControl,
|
|
14
15
|
userid: getAttribute(config, 'user_id') || config.userid,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IFSFilter } from "../../interfaces/common/IFSFilter";
|
|
2
|
+
import { IFValue } from "../../interfaces/IFValue";
|
|
3
|
+
import { IFUTransformFilterValuesSettings } from "../../interfaces/ui/IFUTransformFilterValuesSettings";
|
|
4
|
+
export declare function transformFilterValues(filter: IFSFilter, settings: IFUTransformFilterValuesSettings): IFValue[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isEmpty } from "../../../general/mix/isEmpty";
|
|
2
|
+
import { transformValue } from "../../../qrvey/helpers/transformValue";
|
|
3
|
+
import { isRangeValidator } from "../common/isRangeValidator";
|
|
4
|
+
import { isRegularValidator } from "../common/isRegularValidator";
|
|
5
|
+
export function transformFilterValues(filter, settings) {
|
|
6
|
+
const transformValueSettings = Object.assign(Object.assign({}, settings), { column: filter.column, property: filter.property });
|
|
7
|
+
if (isEmpty(filter))
|
|
8
|
+
return [];
|
|
9
|
+
if (isRegularValidator(filter.validator)) {
|
|
10
|
+
return filter.values.map((value) => (Object.assign(Object.assign({}, value), { value: transformValue(value.value, transformValueSettings) })));
|
|
11
|
+
}
|
|
12
|
+
else if (isRangeValidator(filter.validator)) {
|
|
13
|
+
return filter.values.map((value) => (Object.assign(Object.assign({}, value), { min: transformValue(value.min, transformValueSettings), max: transformValue(value.max, transformValueSettings) })));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return filter.values;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|