@qrvey/utils 1.2.9-25 → 1.2.9-26

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.
@@ -43,17 +43,18 @@ function formatLocaleDate(value, outputFormat, config) {
43
43
  return new Intl.DateTimeFormat([lang, definition_1.LANG_DEFAULT], langOpts).format(dateParam);
44
44
  }
45
45
  catch (error) {
46
- return new Intl.DateTimeFormat(definition_1.LANG_DEFAULT, langOpts).format(dateParam);
46
+ return (0, isEmpty_1.isEmpty)(dateParam) ? value : new Intl.DateTimeFormat(definition_1.LANG_DEFAULT, langOpts).format(dateParam);
47
47
  }
48
48
  }
49
49
  function formatLocaleNumber(value, outputFormat, config) {
50
50
  const { lang = definition_1.LANG_DEFAULT, options } = config;
51
51
  const langOpts = options || getLocaleOptions(outputFormat);
52
+ const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
52
53
  try {
53
- return new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts).format(value);
54
+ return new Intl.NumberFormat([lang, definition_1.LANG_DEFAULT], langOpts).format(valueToFormat);
54
55
  }
55
56
  catch (e) {
56
- return new Intl.NumberFormat(definition_1.LANG_DEFAULT, langOpts).format(value);
57
+ return new Intl.NumberFormat(definition_1.LANG_DEFAULT, langOpts).format(valueToFormat);
57
58
  }
58
59
  }
59
60
  function getLocaleOptions(outputFormat) {
@@ -37,17 +37,18 @@ function formatLocaleDate(value, outputFormat, config) {
37
37
  return new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts).format(dateParam);
38
38
  }
39
39
  catch (error) {
40
- return new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
40
+ return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
41
41
  }
42
42
  }
43
43
  function formatLocaleNumber(value, outputFormat, config) {
44
44
  const { lang = LANG_DEFAULT, options } = config;
45
45
  const langOpts = options || getLocaleOptions(outputFormat);
46
+ const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* PERCENTAGE */ ? value / 100 : value;
46
47
  try {
47
- return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(value);
48
+ return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(valueToFormat);
48
49
  }
49
50
  catch (e) {
50
- return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(value);
51
+ return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
51
52
  }
52
53
  }
53
54
  function getLocaleOptions(outputFormat) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.2.9-25",
3
+ "version": "1.2.9-26",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",
@@ -38,17 +38,18 @@ function formatLocaleDate(value: any, outputFormat: IFormatOutputFormat, config:
38
38
  try {
39
39
  return new Intl.DateTimeFormat([lang, LANG_DEFAULT], langOpts).format(dateParam);
40
40
  } catch (error) {
41
- return new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
41
+ return isEmpty(dateParam) ? value : new Intl.DateTimeFormat(LANG_DEFAULT, langOpts).format(dateParam);
42
42
  }
43
43
  }
44
44
 
45
45
  function formatLocaleNumber(value: any, outputFormat: IFormatOutputFormat, config: IFormatConfig,) {
46
46
  const { lang = LANG_DEFAULT, options } = config;
47
47
  const langOpts = options || getLocaleOptions(outputFormat);
48
+ const valueToFormat = outputFormat?.format === LOCALE_FORMATS.PERCENTAGE ? value/100 : value;
48
49
  try {
49
- return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(value);
50
+ return new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts).format(valueToFormat);
50
51
  } catch (e) {
51
- return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(value);
52
+ return new Intl.NumberFormat(LANG_DEFAULT, langOpts).format(valueToFormat);
52
53
  }
53
54
  }
54
55