@qrvey/utils 1.2.9-34 → 1.2.9-35
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 +783 -783
- package/dist/cjs/format/localization.js +16 -2
- package/dist/format/localization.js +16 -2
- package/package.json +1 -1
- package/src/format/localization.ts +16 -2
|
@@ -30,6 +30,7 @@ const formatWithLocale = (value, outputFormat, config = {}) => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
exports.formatWithLocale = formatWithLocale;
|
|
33
|
+
const DATE_FORMAT_CACHE = [];
|
|
33
34
|
function formatLocaleDate(value, outputFormat, config) {
|
|
34
35
|
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
35
36
|
const dateValue = value === null || value === void 0 ? void 0 : value.replace(/Z$/i, '');
|
|
@@ -41,18 +42,31 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
41
42
|
langOpts = definition_1.DATETIME_OPTIONS;
|
|
42
43
|
}
|
|
43
44
|
try {
|
|
44
|
-
|
|
45
|
+
const key = lang + JSON.stringify(langOpts);
|
|
46
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
47
|
+
if (!formatter) {
|
|
48
|
+
formatter = new Intl.DateTimeFormat([lang, definition_1.LANG_DEFAULT], langOpts);
|
|
49
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
50
|
+
}
|
|
51
|
+
return formatter.format(dateParam);
|
|
45
52
|
}
|
|
46
53
|
catch (error) {
|
|
47
54
|
return (0, isEmpty_1.isEmpty)(dateParam) ? value : new Intl.DateTimeFormat(definition_1.LANG_DEFAULT, langOpts).format(dateParam);
|
|
48
55
|
}
|
|
49
56
|
}
|
|
57
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
50
58
|
function formatLocaleNumber(value, outputFormat, config) {
|
|
51
59
|
const { lang = definition_1.LANG_DEFAULT, options } = config;
|
|
52
60
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
53
61
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
|
|
54
62
|
try {
|
|
55
|
-
|
|
63
|
+
const key = lang + JSON.stringify(langOpts);
|
|
64
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
65
|
+
if (!formatter) {
|
|
66
|
+
formatter = new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts);
|
|
67
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
68
|
+
}
|
|
69
|
+
return formatter.format(valueToFormat);
|
|
56
70
|
}
|
|
57
71
|
catch (e) {
|
|
58
72
|
return new Intl.NumberFormat(definition_1.LANG_DEFAULT, langOpts).format(valueToFormat);
|
|
@@ -24,6 +24,7 @@ export const formatWithLocale = (value, outputFormat, config = {}) => {
|
|
|
24
24
|
return formatLocaleNumber(value, outputFormat, config);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
+
const DATE_FORMAT_CACHE = [];
|
|
27
28
|
function formatLocaleDate(value, outputFormat, config) {
|
|
28
29
|
const { lang = LANG_DEFAULT, options } = config;
|
|
29
30
|
const dateValue = value === null || value === void 0 ? void 0 : value.replace(/Z$/i, '');
|
|
@@ -35,18 +36,31 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
35
36
|
langOpts = DATETIME_OPTIONS;
|
|
36
37
|
}
|
|
37
38
|
try {
|
|
38
|
-
|
|
39
|
+
const key = lang + JSON.stringify(langOpts);
|
|
40
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
41
|
+
if (!formatter) {
|
|
42
|
+
formatter = new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts);
|
|
43
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
44
|
+
}
|
|
45
|
+
return formatter.format(dateParam);
|
|
39
46
|
}
|
|
40
47
|
catch (error) {
|
|
41
48
|
return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
|
|
42
49
|
}
|
|
43
50
|
}
|
|
51
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
44
52
|
function formatLocaleNumber(value, outputFormat, config) {
|
|
45
53
|
const { lang = LANG_DEFAULT, options } = config;
|
|
46
54
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
47
55
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
|
|
48
56
|
try {
|
|
49
|
-
|
|
57
|
+
const key = lang + JSON.stringify(langOpts);
|
|
58
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
59
|
+
if (!formatter) {
|
|
60
|
+
formatter = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
61
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
62
|
+
}
|
|
63
|
+
return formatter.format(valueToFormat);
|
|
50
64
|
}
|
|
51
65
|
catch (e) {
|
|
52
66
|
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
|
package/package.json
CHANGED
|
@@ -27,6 +27,7 @@ export const formatWithLocale = (value: any, outputFormat: IFormatOutputFormat,
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
const DATE_FORMAT_CACHE = [];
|
|
30
31
|
function formatLocaleDate(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig) {
|
|
31
32
|
const { lang = LANG_DEFAULT, options } = config;
|
|
32
33
|
const dateValue = value?.replace(/Z$/i, '');
|
|
@@ -37,18 +38,31 @@ function formatLocaleDate(value: any, outputFormat: IFormatOutputFormat, config:
|
|
|
37
38
|
if (DATETIME_COLUMN_FORMAT.includes(format)) langOpts = DATETIME_OPTIONS;
|
|
38
39
|
}
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
+
const key = lang + JSON.stringify(langOpts);
|
|
42
|
+
let formatter = DATE_FORMAT_CACHE[key];
|
|
43
|
+
if (!formatter) {
|
|
44
|
+
formatter = new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts);
|
|
45
|
+
DATE_FORMAT_CACHE[key] = formatter;
|
|
46
|
+
}
|
|
47
|
+
return formatter.format(dateParam);
|
|
41
48
|
} catch (error) {
|
|
42
49
|
return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
52
|
|
|
53
|
+
const NUMBER_FORMAT_CACHE = [];
|
|
46
54
|
function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
|
|
47
55
|
const { lang = LANG_DEFAULT, options } = config;
|
|
48
56
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
49
57
|
const valueToFormat = outputFormat?.format === LOCALE_FORMATS.PERCENTAGE ? value/100 : value;
|
|
50
58
|
try {
|
|
51
|
-
|
|
59
|
+
const key = lang + JSON.stringify(langOpts);
|
|
60
|
+
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
61
|
+
if (!formatter) {
|
|
62
|
+
formatter = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
63
|
+
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
64
|
+
}
|
|
65
|
+
return formatter.format(valueToFormat);
|
|
52
66
|
} catch (e) {
|
|
53
67
|
return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
|
|
54
68
|
}
|