@qrvey/utils 1.10.0-15 → 1.10.0-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.
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Checks if the given date is allowed to continue the process for adapting dates
3
+ * - If the string is a token or a combination of tokens is not valid
3
4
  * @param {string | Date | number} date String, object or millisencond number of the date
4
5
  * @returns true: the date is valid.
5
6
  */
@@ -2,17 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isValidPotentialDate = void 0;
4
4
  const isEmpty_1 = require("../../general/mix/isEmpty");
5
- const isTokenLabel_1 = require("../../tokens/isTokenLabel");
5
+ const DATE_FORMATS_1 = require("../constants/DATE_FORMATS");
6
+ const areIncludedDateTokens_1 = require("./areIncludedDateTokens");
6
7
  /**
7
8
  * Checks if the given date is allowed to continue the process for adapting dates
9
+ * - If the string is a token or a combination of tokens is not valid
8
10
  * @param {string | Date | number} date String, object or millisencond number of the date
9
11
  * @returns true: the date is valid.
10
12
  */
11
13
  function isValidPotentialDate(date) {
12
14
  return (!(0, isEmpty_1.isEmpty)(date) &&
13
- !(0, isTokenLabel_1.isTokenLabel)(date) &&
14
- ((date instanceof Date && !isNaN(date)) ||
15
- typeof date === "string" ||
16
- typeof date === "number"));
15
+ !includingDateTokens(date) &&
16
+ (isDateInstance(date) || isStringDate(date) || typeof date === "number"));
17
17
  }
18
18
  exports.isValidPotentialDate = isValidPotentialDate;
19
+ function includingDateTokens(date) {
20
+ return DATE_FORMATS_1.DATE_FORMATS.some((dateFormat) => (0, areIncludedDateTokens_1.areIncludedDateTokens)(date, dateFormat));
21
+ }
22
+ function isDateInstance(date) {
23
+ return date instanceof Date && !isNaN(date);
24
+ }
25
+ function isStringDate(date) {
26
+ return (typeof date === "string" && new Date(date).toString() !== "Invalid Date");
27
+ }
@@ -4,4 +4,5 @@ export interface II18nDashboardTooltips {
4
4
  buckets: string;
5
5
  download: string;
6
6
  embed_analyze: string;
7
+ histogram: string;
7
8
  }
@@ -37,6 +37,7 @@ exports.I18N_DASHBOARD = {
37
37
  download: "Download",
38
38
  embed_analyze: "Embed Analyze View",
39
39
  formulas: "Formulas",
40
+ histogram: "Histogram",
40
41
  style_themes: "Style Themes",
41
42
  },
42
43
  views: {
@@ -59,17 +59,13 @@ function getDefaultSettings(settings) {
59
59
  */
60
60
  function getOutputFormat(settings) {
61
61
  var _a, _b;
62
- let type, format, decimals;
63
- const isDateTime = [
64
- DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.HOUR,
65
- DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.MINUTE,
66
- DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.SECOND,
67
- undefined,
68
- ].includes(settings.property);
62
+ let type, format, decimals, originalFormat;
63
+ const isDateTime = isDateWithTime(settings.property);
69
64
  const isDate = [DATE_GROUPING_PROPERTY_1.DATE_GROUPING_PROPERTY.DAY, undefined].includes(settings.property);
70
65
  if ((0, isDateColumn_1.isDateColumn)(settings.column) && (isDate || isDateTime)) {
71
66
  type = "DATE";
72
67
  format = "Default";
68
+ originalFormat = getOutputFormatByPoperty(settings);
73
69
  }
74
70
  else if (settings.column.type === COLUMN_1.COLUMN.TIME) {
75
71
  type = "TIME";
@@ -84,7 +80,7 @@ function getOutputFormat(settings) {
84
80
  type,
85
81
  format,
86
82
  decimals,
87
- originalFormat: isDateTime ? settings.column.outputFormat : undefined,
83
+ originalFormat,
88
84
  };
89
85
  }
90
86
  /**
@@ -96,3 +92,30 @@ function getFormatConfig(settings) {
96
92
  var _a, _b;
97
93
  return ((_a = settings.i18n) === null || _a === void 0 ? void 0 : _a.locale) && { lang: (_b = settings.i18n) === null || _b === void 0 ? void 0 : _b.locale };
98
94
  }
95
+ /**
96
+ * If the property is a day, return the date format without the time, otherwise return the original
97
+ * format.
98
+ * @param {ITransformValueSettings} settings - ITransformValueSettings
99
+ * @returns The outputFormat of the column.
100
+ */
101
+ function getOutputFormatByPoperty(settings) {
102
+ if (settings.property === DATE_GROUPING_PROPERTY_1.DATE_GROUPING_PROPERTY.DAY) {
103
+ return Object.assign(Object.assign({}, settings.column.outputFormat), { format: settings.column.outputFormat.format.split(" ")[0] });
104
+ }
105
+ else if (isDateWithTime(settings.property))
106
+ return settings.column.outputFormat;
107
+ }
108
+ /**
109
+ * Get the format related to the columnn property.
110
+ * If the property is hour, minute, second, or undefined, return true.
111
+ * @param {IColumnPropertyType} property - The property of the date to group by.
112
+ * @returns {boolean} A boolean value.
113
+ */
114
+ function isDateWithTime(property) {
115
+ return [
116
+ DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.HOUR,
117
+ DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.MINUTE,
118
+ DATE_GROUPING_TIME_PROPERTY_1.DATE_GROUPING_TIME_PROPERTY.SECOND,
119
+ undefined,
120
+ ].includes(property);
121
+ }
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Checks if the given date is allowed to continue the process for adapting dates
3
+ * - If the string is a token or a combination of tokens is not valid
3
4
  * @param {string | Date | number} date String, object or millisencond number of the date
4
5
  * @returns true: the date is valid.
5
6
  */
@@ -1,14 +1,23 @@
1
1
  import { isEmpty } from "../../general/mix/isEmpty";
2
- import { isTokenLabel } from "../../tokens/isTokenLabel";
2
+ import { DATE_FORMATS } from "../constants/DATE_FORMATS";
3
+ import { areIncludedDateTokens } from "./areIncludedDateTokens";
3
4
  /**
4
5
  * Checks if the given date is allowed to continue the process for adapting dates
6
+ * - If the string is a token or a combination of tokens is not valid
5
7
  * @param {string | Date | number} date String, object or millisencond number of the date
6
8
  * @returns true: the date is valid.
7
9
  */
8
10
  export function isValidPotentialDate(date) {
9
11
  return (!isEmpty(date) &&
10
- !isTokenLabel(date) &&
11
- ((date instanceof Date && !isNaN(date)) ||
12
- typeof date === "string" ||
13
- typeof date === "number"));
12
+ !includingDateTokens(date) &&
13
+ (isDateInstance(date) || isStringDate(date) || typeof date === "number"));
14
+ }
15
+ function includingDateTokens(date) {
16
+ return DATE_FORMATS.some((dateFormat) => areIncludedDateTokens(date, dateFormat));
17
+ }
18
+ function isDateInstance(date) {
19
+ return date instanceof Date && !isNaN(date);
20
+ }
21
+ function isStringDate(date) {
22
+ return (typeof date === "string" && new Date(date).toString() !== "Invalid Date");
14
23
  }
@@ -4,4 +4,5 @@ export interface II18nDashboardTooltips {
4
4
  buckets: string;
5
5
  download: string;
6
6
  embed_analyze: string;
7
+ histogram: string;
7
8
  }
@@ -34,6 +34,7 @@ export const I18N_DASHBOARD = {
34
34
  download: "Download",
35
35
  embed_analyze: "Embed Analyze View",
36
36
  formulas: "Formulas",
37
+ histogram: "Histogram",
37
38
  style_themes: "Style Themes",
38
39
  },
39
40
  views: {
@@ -55,17 +55,13 @@ function getDefaultSettings(settings) {
55
55
  */
56
56
  function getOutputFormat(settings) {
57
57
  var _a, _b;
58
- let type, format, decimals;
59
- const isDateTime = [
60
- DATE_GROUPING_TIME_PROPERTY.HOUR,
61
- DATE_GROUPING_TIME_PROPERTY.MINUTE,
62
- DATE_GROUPING_TIME_PROPERTY.SECOND,
63
- undefined,
64
- ].includes(settings.property);
58
+ let type, format, decimals, originalFormat;
59
+ const isDateTime = isDateWithTime(settings.property);
65
60
  const isDate = [DATE_GROUPING_PROPERTY.DAY, undefined].includes(settings.property);
66
61
  if (isDateColumn(settings.column) && (isDate || isDateTime)) {
67
62
  type = "DATE";
68
63
  format = "Default";
64
+ originalFormat = getOutputFormatByPoperty(settings);
69
65
  }
70
66
  else if (settings.column.type === COLUMN.TIME) {
71
67
  type = "TIME";
@@ -80,7 +76,7 @@ function getOutputFormat(settings) {
80
76
  type,
81
77
  format,
82
78
  decimals,
83
- originalFormat: isDateTime ? settings.column.outputFormat : undefined,
79
+ originalFormat,
84
80
  };
85
81
  }
86
82
  /**
@@ -92,3 +88,30 @@ function getFormatConfig(settings) {
92
88
  var _a, _b;
93
89
  return ((_a = settings.i18n) === null || _a === void 0 ? void 0 : _a.locale) && { lang: (_b = settings.i18n) === null || _b === void 0 ? void 0 : _b.locale };
94
90
  }
91
+ /**
92
+ * If the property is a day, return the date format without the time, otherwise return the original
93
+ * format.
94
+ * @param {ITransformValueSettings} settings - ITransformValueSettings
95
+ * @returns The outputFormat of the column.
96
+ */
97
+ function getOutputFormatByPoperty(settings) {
98
+ if (settings.property === DATE_GROUPING_PROPERTY.DAY) {
99
+ return Object.assign(Object.assign({}, settings.column.outputFormat), { format: settings.column.outputFormat.format.split(" ")[0] });
100
+ }
101
+ else if (isDateWithTime(settings.property))
102
+ return settings.column.outputFormat;
103
+ }
104
+ /**
105
+ * Get the format related to the columnn property.
106
+ * If the property is hour, minute, second, or undefined, return true.
107
+ * @param {IColumnPropertyType} property - The property of the date to group by.
108
+ * @returns {boolean} A boolean value.
109
+ */
110
+ function isDateWithTime(property) {
111
+ return [
112
+ DATE_GROUPING_TIME_PROPERTY.HOUR,
113
+ DATE_GROUPING_TIME_PROPERTY.MINUTE,
114
+ DATE_GROUPING_TIME_PROPERTY.SECOND,
115
+ undefined,
116
+ ].includes(property);
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.10.0-15",
3
+ "version": "1.10.0-16",
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",