@qrvey/utils 1.5.0-0 → 1.5.0-1
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 +1 -1
- package/dist/cjs/column_format/constants/DURATION_PARTS_LIST.d.ts +1 -0
- package/dist/cjs/column_format/constants/DURATION_PARTS_LIST.js +12 -0
- package/dist/cjs/column_format/constants/index.d.ts +1 -0
- package/dist/cjs/column_format/constants/index.js +1 -0
- package/dist/cjs/column_format/helpers/defineXYChartFormat.js +4 -1
- package/dist/cjs/format/definition.d.ts +2 -1
- package/dist/cjs/format/format.js +4 -1
- package/dist/cjs/format/localization.js +18 -2
- package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
- package/dist/column_format/constants/DURATION_PARTS_LIST.d.ts +1 -0
- package/dist/column_format/constants/DURATION_PARTS_LIST.js +9 -0
- package/dist/column_format/constants/index.d.ts +1 -0
- package/dist/column_format/constants/index.js +1 -0
- package/dist/column_format/helpers/defineXYChartFormat.js +4 -1
- package/dist/format/definition.d.ts +2 -1
- package/dist/format/format.js +4 -1
- package/dist/format/localization.js +18 -2
- package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DURATION_PARTS_LIST: string[];
|
|
@@ -20,3 +20,4 @@ __exportStar(require("./DATEGROUP_WITHOUT_FORMAT"), exports);
|
|
|
20
20
|
__exportStar(require("./SHELF_TYPE"), exports);
|
|
21
21
|
__exportStar(require("./STRING_FORMAT"), exports);
|
|
22
22
|
__exportStar(require("./TABLE_TYPE"), exports);
|
|
23
|
+
__exportStar(require("./DURATION_PARTS_LIST"), exports);
|
|
@@ -7,6 +7,7 @@ const isEmpty_1 = require("../../general/mix/isEmpty");
|
|
|
7
7
|
const CALCULATION_LABEL_1 = require("../../qrvey/constants/CALCULATION_LABEL");
|
|
8
8
|
const CHART_GROUP_1 = require("../constants/CHART_GROUP");
|
|
9
9
|
const DATEGROUP_UNSUPPORT_FORMAT_1 = require("../constants/DATEGROUP_UNSUPPORT_FORMAT");
|
|
10
|
+
const DURATION_PARTS_LIST_1 = require("../constants/DURATION_PARTS_LIST");
|
|
10
11
|
const STRING_FORMAT_1 = require("../constants/STRING_FORMAT");
|
|
11
12
|
const columnTypeByChart_1 = require("./columnTypeByChart");
|
|
12
13
|
/**
|
|
@@ -37,6 +38,8 @@ const defineXYChartFormat = (column, settings) => {
|
|
|
37
38
|
const hasDefaultFormat = (0, isEmpty_1.isEmpty)(selectedFormat) ||
|
|
38
39
|
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === defaultText ||
|
|
39
40
|
(selectedFormat === null || selectedFormat === void 0 ? void 0 : selectedFormat.format) === defaultText;
|
|
41
|
+
const newOutputFormat = DURATION_PARTS_LIST_1.DURATION_PARTS_LIST.includes(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format)
|
|
42
|
+
? Object.assign(Object.assign({}, outputFormat), { template: outputFormat.format, format: "Duration" }) : outputFormat;
|
|
40
43
|
switch (columnType) {
|
|
41
44
|
case COLUMN_1.COLUMN.YES_NO:
|
|
42
45
|
case COLUMN_1.COLUMN.PHONE:
|
|
@@ -82,7 +85,7 @@ const defineXYChartFormat = (column, settings) => {
|
|
|
82
85
|
return columnDefaultFormat;
|
|
83
86
|
}
|
|
84
87
|
else if (hasDefaultFormat) {
|
|
85
|
-
return Object.assign({},
|
|
88
|
+
return Object.assign({}, newOutputFormat);
|
|
86
89
|
}
|
|
87
90
|
else
|
|
88
91
|
return selectedFormat;
|
|
@@ -18,7 +18,8 @@ export declare const enum LOCALE_FORMATS {
|
|
|
18
18
|
CURRENCY = "Currency",
|
|
19
19
|
PERCENTAGE = "Percentage",
|
|
20
20
|
SCIENTIFIC = "Scientific",
|
|
21
|
-
ABBREVIATED = "Abbreviated"
|
|
21
|
+
ABBREVIATED = "Abbreviated",
|
|
22
|
+
DURATION = "Duration"
|
|
22
23
|
}
|
|
23
24
|
export declare const enum LOCALE_STYLES {
|
|
24
25
|
DECIMAL = "decimal",
|
|
@@ -14,6 +14,7 @@ const COLUMN_1 = require("../columns/constants/COLUMN");
|
|
|
14
14
|
const FORMULA_1 = require("../formulas/constants/FORMULA");
|
|
15
15
|
const localization_1 = require("./localization");
|
|
16
16
|
const isObject_1 = require("../general/object/isObject");
|
|
17
|
+
const DURATION_PARTS_LIST_1 = require("../column_format/constants/DURATION_PARTS_LIST");
|
|
17
18
|
dayjs_1.default.extend(advancedFormat_1.default); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
|
|
18
19
|
/**
|
|
19
20
|
* Apply to the given date format to a date value
|
|
@@ -114,7 +115,9 @@ const addFormat = (value, outputFormat = "None", config) => {
|
|
|
114
115
|
: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
|
|
115
116
|
case "NUMERIC": {
|
|
116
117
|
const parse = parseFloat(value);
|
|
117
|
-
const withLocale = outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)
|
|
118
|
+
const withLocale = (outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)) ||
|
|
119
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" ||
|
|
120
|
+
DURATION_PARTS_LIST_1.DURATION_PARTS_LIST.includes[outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format];
|
|
118
121
|
return isNaN(parse)
|
|
119
122
|
? value
|
|
120
123
|
: withLocale
|
|
@@ -4,6 +4,7 @@ exports.formatWithLocale = exports.chooseLang = exports.getLang = void 0;
|
|
|
4
4
|
const DATETIME_COLUMN_FORMAT_1 = require("../dates/constants/DATETIME_COLUMN_FORMAT");
|
|
5
5
|
const isEmpty_1 = require("../general/mix/isEmpty");
|
|
6
6
|
const definition_1 = require("./definition");
|
|
7
|
+
const durationFormatter_1 = require("./duration/durationFormatter");
|
|
7
8
|
const getLang = (locale) => {
|
|
8
9
|
if (!locale)
|
|
9
10
|
return;
|
|
@@ -61,10 +62,20 @@ function formatLocaleNumber(value, outputFormat, config) {
|
|
|
61
62
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
62
63
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* LOCALE_FORMATS.PERCENTAGE */ ? value / 100 : value;
|
|
63
64
|
try {
|
|
64
|
-
const key =
|
|
65
|
+
const key = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) +
|
|
66
|
+
lang +
|
|
67
|
+
JSON.stringify(langOpts) +
|
|
68
|
+
((outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template) ? outputFormat.template : "");
|
|
65
69
|
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
66
70
|
if (!formatter) {
|
|
67
|
-
|
|
71
|
+
const intlNumberFormat = new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts);
|
|
72
|
+
formatter =
|
|
73
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" /* LOCALE_FORMATS.DURATION */
|
|
74
|
+
? new durationFormatter_1.DurationFormatter({
|
|
75
|
+
template: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template,
|
|
76
|
+
intlNumberFormat,
|
|
77
|
+
})
|
|
78
|
+
: intlNumberFormat;
|
|
68
79
|
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
69
80
|
}
|
|
70
81
|
return formatter.format(valueToFormat);
|
|
@@ -113,6 +124,11 @@ function getLocaleOptions(outputFormat) {
|
|
|
113
124
|
maximumFractionDigits: decimals,
|
|
114
125
|
minimumFractionDigits: decimals,
|
|
115
126
|
};
|
|
127
|
+
case "Duration" /* LOCALE_FORMATS.DURATION */:
|
|
128
|
+
return {
|
|
129
|
+
maximumFractionDigits: 0,
|
|
130
|
+
minimumFractionDigits: 0,
|
|
131
|
+
};
|
|
116
132
|
default:
|
|
117
133
|
return {
|
|
118
134
|
style: "decimal" /* LOCALE_STYLES.DECIMAL */,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DURATION_PARTS_LIST: string[];
|
|
@@ -4,6 +4,7 @@ import { isEmpty } from "../../general/mix/isEmpty";
|
|
|
4
4
|
import { CALCULATION_LABEL } from "../../qrvey/constants/CALCULATION_LABEL";
|
|
5
5
|
import { CHART_GROUPS } from "../constants/CHART_GROUP";
|
|
6
6
|
import { DATEGROUP_UNSUPPORT_FORMAT } from "../constants/DATEGROUP_UNSUPPORT_FORMAT";
|
|
7
|
+
import { DURATION_PARTS_LIST } from "../constants/DURATION_PARTS_LIST";
|
|
7
8
|
import { STRING_FORMAT } from "../constants/STRING_FORMAT";
|
|
8
9
|
import { columnTypeByChart } from "./columnTypeByChart";
|
|
9
10
|
/**
|
|
@@ -34,6 +35,8 @@ export const defineXYChartFormat = (column, settings) => {
|
|
|
34
35
|
const hasDefaultFormat = isEmpty(selectedFormat) ||
|
|
35
36
|
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === defaultText ||
|
|
36
37
|
(selectedFormat === null || selectedFormat === void 0 ? void 0 : selectedFormat.format) === defaultText;
|
|
38
|
+
const newOutputFormat = DURATION_PARTS_LIST.includes(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format)
|
|
39
|
+
? Object.assign(Object.assign({}, outputFormat), { template: outputFormat.format, format: "Duration" }) : outputFormat;
|
|
37
40
|
switch (columnType) {
|
|
38
41
|
case COLUMN.YES_NO:
|
|
39
42
|
case COLUMN.PHONE:
|
|
@@ -79,7 +82,7 @@ export const defineXYChartFormat = (column, settings) => {
|
|
|
79
82
|
return columnDefaultFormat;
|
|
80
83
|
}
|
|
81
84
|
else if (hasDefaultFormat) {
|
|
82
|
-
return Object.assign({},
|
|
85
|
+
return Object.assign({}, newOutputFormat);
|
|
83
86
|
}
|
|
84
87
|
else
|
|
85
88
|
return selectedFormat;
|
|
@@ -18,7 +18,8 @@ export declare const enum LOCALE_FORMATS {
|
|
|
18
18
|
CURRENCY = "Currency",
|
|
19
19
|
PERCENTAGE = "Percentage",
|
|
20
20
|
SCIENTIFIC = "Scientific",
|
|
21
|
-
ABBREVIATED = "Abbreviated"
|
|
21
|
+
ABBREVIATED = "Abbreviated",
|
|
22
|
+
DURATION = "Duration"
|
|
22
23
|
}
|
|
23
24
|
export declare const enum LOCALE_STYLES {
|
|
24
25
|
DECIMAL = "decimal",
|
package/dist/format/format.js
CHANGED
|
@@ -8,6 +8,7 @@ import { COLUMN } from "../columns/constants/COLUMN";
|
|
|
8
8
|
import { FORMULA } from "../formulas/constants/FORMULA";
|
|
9
9
|
import { formatWithLocale } from "./localization";
|
|
10
10
|
import { isObject } from "../general/object/isObject";
|
|
11
|
+
import { DURATION_PARTS_LIST } from "../column_format/constants/DURATION_PARTS_LIST";
|
|
11
12
|
dayjs.extend(advancedFormat); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
|
|
12
13
|
/**
|
|
13
14
|
* Apply to the given date format to a date value
|
|
@@ -105,7 +106,9 @@ export const addFormat = (value, outputFormat = "None", config) => {
|
|
|
105
106
|
: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
|
|
106
107
|
case "NUMERIC": {
|
|
107
108
|
const parse = parseFloat(value);
|
|
108
|
-
const withLocale = outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)
|
|
109
|
+
const withLocale = (outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)) ||
|
|
110
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" ||
|
|
111
|
+
DURATION_PARTS_LIST.includes[outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format];
|
|
109
112
|
return isNaN(parse)
|
|
110
113
|
? value
|
|
111
114
|
: withLocale
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DATETIME_COLUMN_FORMAT } from "../dates/constants/DATETIME_COLUMN_FORMAT";
|
|
2
2
|
import { isEmpty } from "../general/mix/isEmpty";
|
|
3
3
|
import { currencyISO, LANG_DEFAULT, CURRENCY_DEFAULT, DATETIME_OPTIONS, } from "./definition";
|
|
4
|
+
import { DurationFormatter } from "./duration/durationFormatter";
|
|
4
5
|
export const getLang = (locale) => {
|
|
5
6
|
if (!locale)
|
|
6
7
|
return;
|
|
@@ -55,10 +56,20 @@ function formatLocaleNumber(value, outputFormat, config) {
|
|
|
55
56
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
56
57
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* LOCALE_FORMATS.PERCENTAGE */ ? value / 100 : value;
|
|
57
58
|
try {
|
|
58
|
-
const key =
|
|
59
|
+
const key = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) +
|
|
60
|
+
lang +
|
|
61
|
+
JSON.stringify(langOpts) +
|
|
62
|
+
((outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template) ? outputFormat.template : "");
|
|
59
63
|
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
60
64
|
if (!formatter) {
|
|
61
|
-
|
|
65
|
+
const intlNumberFormat = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
66
|
+
formatter =
|
|
67
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" /* LOCALE_FORMATS.DURATION */
|
|
68
|
+
? new DurationFormatter({
|
|
69
|
+
template: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template,
|
|
70
|
+
intlNumberFormat,
|
|
71
|
+
})
|
|
72
|
+
: intlNumberFormat;
|
|
62
73
|
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
63
74
|
}
|
|
64
75
|
return formatter.format(valueToFormat);
|
|
@@ -107,6 +118,11 @@ function getLocaleOptions(outputFormat) {
|
|
|
107
118
|
maximumFractionDigits: decimals,
|
|
108
119
|
minimumFractionDigits: decimals,
|
|
109
120
|
};
|
|
121
|
+
case "Duration" /* LOCALE_FORMATS.DURATION */:
|
|
122
|
+
return {
|
|
123
|
+
maximumFractionDigits: 0,
|
|
124
|
+
minimumFractionDigits: 0,
|
|
125
|
+
};
|
|
110
126
|
default:
|
|
111
127
|
return {
|
|
112
128
|
style: "decimal" /* LOCALE_STYLES.DECIMAL */,
|