@qrvey/utils 1.10.0-10 → 1.10.0-12

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.
Files changed (39) hide show
  1. package/dist/cjs/dates/helpers/getTimezoneObject.js +2 -1
  2. package/dist/cjs/general/array/getArrayByProperty.d.ts +1 -1
  3. package/dist/cjs/general/array/getUniqueArray.d.ts +1 -1
  4. package/dist/cjs/general/array/getUniqueArray.js +2 -0
  5. package/dist/cjs/general/mix/isNaNV2.d.ts +1 -0
  6. package/dist/cjs/general/mix/isNaNV2.js +7 -2
  7. package/dist/cjs/general/numeric/getSign.js +1 -1
  8. package/dist/cjs/general/object/applyTimezoneDeep.d.ts +1 -1
  9. package/dist/cjs/general/object/applyTimezoneDeep.js +9 -5
  10. package/dist/cjs/general/object/isObject.js +3 -1
  11. package/dist/cjs/general/object/objectCopy.d.ts +1 -1
  12. package/dist/cjs/general/object/removeUndefinedDeep.js +6 -3
  13. package/dist/cjs/general/string/fillLeadingZeros.d.ts +15 -0
  14. package/dist/cjs/general/string/fillLeadingZeros.js +56 -0
  15. package/dist/cjs/general/string/index.d.ts +1 -0
  16. package/dist/cjs/general/string/index.js +1 -0
  17. package/dist/cjs/general/string/padLeadingZeros.d.ts +14 -0
  18. package/dist/cjs/general/string/padLeadingZeros.js +47 -6
  19. package/dist/cjs/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +2 -2
  20. package/dist/dates/helpers/getTimezoneObject.js +2 -1
  21. package/dist/general/array/getArrayByProperty.d.ts +1 -1
  22. package/dist/general/array/getUniqueArray.d.ts +1 -1
  23. package/dist/general/array/getUniqueArray.js +2 -0
  24. package/dist/general/mix/isNaNV2.d.ts +1 -0
  25. package/dist/general/mix/isNaNV2.js +7 -2
  26. package/dist/general/numeric/getSign.js +1 -1
  27. package/dist/general/object/applyTimezoneDeep.d.ts +1 -1
  28. package/dist/general/object/applyTimezoneDeep.js +9 -5
  29. package/dist/general/object/isObject.js +3 -1
  30. package/dist/general/object/objectCopy.d.ts +1 -1
  31. package/dist/general/object/removeUndefinedDeep.js +6 -3
  32. package/dist/general/string/fillLeadingZeros.d.ts +15 -0
  33. package/dist/general/string/fillLeadingZeros.js +52 -0
  34. package/dist/general/string/index.d.ts +1 -0
  35. package/dist/general/string/index.js +1 -0
  36. package/dist/general/string/padLeadingZeros.d.ts +14 -0
  37. package/dist/general/string/padLeadingZeros.js +47 -6
  38. package/dist/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +2 -2
  39. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTimezoneObject = void 0;
4
4
  const isEmpty_1 = require("../../general/mix/isEmpty");
5
+ const isNaNV2_1 = require("../../general/mix/isNaNV2");
5
6
  const TIMEZONE_TYPE_1 = require("../constants/TIMEZONE_TYPE");
6
7
  const getTimezoneOffsetByType_1 = require("./getTimezoneOffsetByType");
7
8
  const getUTCFormatByOffset_1 = require("./getUTCFormatByOffset");
@@ -92,7 +93,7 @@ function getTypeByOffset(offset) {
92
93
  else if (offset === "browser") {
93
94
  return TIMEZONE_TYPE_1.TIMEZONE_TYPE.BROWSER;
94
95
  }
95
- else if ((0, isValidISOOffset_1.isValidISOOffset)(offset)) {
96
+ else if ((0, isValidISOOffset_1.isValidISOOffset)(offset) || !(0, isNaNV2_1.isNaNV2)(offset)) {
96
97
  return TIMEZONE_TYPE_1.TIMEZONE_TYPE.FIXED;
97
98
  }
98
99
  return TIMEZONE_TYPE_1.TIMEZONE_TYPE.DEFAULT;
@@ -4,4 +4,4 @@
4
4
  * @param property the property to get the value collection
5
5
  * @returns a collection of values by property
6
6
  */
7
- export declare function getArrayByProperty<T = any>(arr: T[], property: string): T[];
7
+ export declare function getArrayByProperty<T = any>(arr: T[], property: string | number): T[];
@@ -6,4 +6,4 @@
6
6
  * @param prop Property name to search duplicated values
7
7
  * @return Array without duplicated items.
8
8
  */
9
- export declare function getUniqueArray(arr: any[], prop: string): any[];
9
+ export declare function getUniqueArray<T = any>(arr: T[], prop: string | number): T[];
@@ -10,6 +10,8 @@ exports.getUniqueArray = void 0;
10
10
  * @return Array without duplicated items.
11
11
  */
12
12
  function getUniqueArray(arr, prop) {
13
+ if (!Array.isArray(arr))
14
+ return arr;
13
15
  return arr
14
16
  .map((e) => e[prop])
15
17
  .map((e, i, final) => final.indexOf(e) === i && i)
@@ -8,6 +8,7 @@
8
8
  * Special case for isNaN
9
9
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
10
10
  * - Boolean variables is considered as false statement.
11
+ * - Date objects is considered as true.
11
12
  *
12
13
  * @param variable the variable to validate
13
14
  * @return True: variable is a NaN; False: The variable is a number
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNaNV2 = void 0;
4
- const _1 = require(".");
4
+ const isValidDateObject_1 = require("../../dates/helpers/isValidDateObject");
5
+ const isEmpty_1 = require("./isEmpty");
5
6
  /**
6
7
  * Validates if the recieved number is NaN type.
7
8
  *
@@ -12,11 +13,15 @@ const _1 = require(".");
12
13
  * Special case for isNaN
13
14
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
14
15
  * - Boolean variables is considered as false statement.
16
+ * - Date objects is considered as true.
15
17
  *
16
18
  * @param variable the variable to validate
17
19
  * @return True: variable is a NaN; False: The variable is a number
18
20
  */
19
21
  function isNaNV2(variable) {
20
- return (0, _1.isEmpty)(variable) || typeof variable == "boolean" || isNaN(variable);
22
+ return ((0, isEmpty_1.isEmpty)(variable) ||
23
+ typeof variable == "boolean" ||
24
+ isNaN(variable) ||
25
+ (0, isValidDateObject_1.isValidDateObject)(variable));
21
26
  }
22
27
  exports.isNaNV2 = isNaNV2;
@@ -7,6 +7,6 @@ exports.getSign = void 0;
7
7
  * @returns {string} an string with the sign
8
8
  */
9
9
  function getSign(num) {
10
- return Math.sign(num) > -1 ? "+" : "-";
10
+ return Math.sign(num) < 0 ? "-" : "+";
11
11
  }
12
12
  exports.getSign = getSign;
@@ -5,4 +5,4 @@ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
5
5
  * @param {IDTimezone} timezone the timezone object
6
6
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
7
7
  */
8
- export declare function applyTimezoneDeep(obj: any, timezone: IDTimezone): any;
8
+ export declare function applyTimezoneDeep<T = any>(obj: T, timezone: IDTimezone): T;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyTimezoneDeep = void 0;
4
4
  const DATE_FORMAT_1 = require("../../dates/constants/DATE_FORMAT");
5
5
  const getDateByTimezone_1 = require("../../dates/helpers/getDateByTimezone");
6
+ const isValidDateObject_1 = require("../../dates/helpers/isValidDateObject");
6
7
  const validateDate_1 = require("../../dates/helpers/validateDate");
7
8
  const isEmpty_1 = require("../mix/isEmpty");
8
9
  const isObject_1 = require("./isObject");
@@ -13,7 +14,7 @@ const isObject_1 = require("./isObject");
13
14
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
14
15
  */
15
16
  function applyTimezoneDeep(obj, timezone) {
16
- if ((0, isEmpty_1.isEmpty)(obj))
17
+ if (!isValid(obj, timezone))
17
18
  return obj;
18
19
  let result;
19
20
  if ((0, isObject_1.isObject)(obj)) {
@@ -24,13 +25,13 @@ function applyTimezoneDeep(obj, timezone) {
24
25
  }
25
26
  try {
26
27
  for (const i in obj) {
27
- if ((0, isObject_1.isObject)(obj[i]) || Array.isArray(obj[i])) {
28
- result[i] = applyTimezoneDeep(obj[i], timezone);
29
- }
30
- else if (obj[i] instanceof Date ||
28
+ if ((0, isValidDateObject_1.isValidDateObject)(obj[i]) ||
31
29
  (0, validateDate_1.validateDate)(obj[i], DATE_FORMAT_1.DATE_FORMAT.HOUR)) {
32
30
  result[i] = (0, getDateByTimezone_1.getDateByTimezone)(obj[i], timezone);
33
31
  }
32
+ else if ((0, isObject_1.isObject)(obj[i]) || Array.isArray(obj[i])) {
33
+ result[i] = applyTimezoneDeep(obj[i], timezone);
34
+ }
34
35
  else {
35
36
  result[i] = obj[i];
36
37
  }
@@ -42,3 +43,6 @@ function applyTimezoneDeep(obj, timezone) {
42
43
  }
43
44
  }
44
45
  exports.applyTimezoneDeep = applyTimezoneDeep;
46
+ function isValid(obj, timezone) {
47
+ return (!(0, isEmpty_1.isEmpty)(obj) && (Array.isArray(obj) || (0, isObject_1.isObject)(obj)) && !(0, isEmpty_1.isEmpty)(timezone));
48
+ }
@@ -9,6 +9,8 @@ const getTag_1 = require("../mix/getTag");
9
9
  */
10
10
  function isObject(obj) {
11
11
  return (!Array.isArray(obj) &&
12
- (obj === Object(obj) || (0, getTag_1.getTag)(obj) === "[object Object]"));
12
+ obj === Object(obj) &&
13
+ (0, getTag_1.getTag)(obj) !== "[object Function]" &&
14
+ ((0, getTag_1.getTag)(obj) === "[object Object]" || (0, getTag_1.getTag)(obj) === "[object Date]"));
13
15
  }
14
16
  exports.isObject = isObject;
@@ -4,4 +4,4 @@
4
4
  * @param cache
5
5
  * @returns A new reference of the given argument
6
6
  */
7
- export declare function objectCopy(entity: any, cache?: WeakMap<object, any>): any;
7
+ export declare function objectCopy<T = any>(entity: T, cache?: WeakMap<object, any>): T;
@@ -1,17 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeUndefinedDeep = void 0;
4
- const cloneDeep_1 = require("./cloneDeep");
5
4
  const isObject_1 = require("./isObject");
5
+ const objectCopy_1 = require("./objectCopy");
6
6
  /**
7
7
  * Removes and returns the given object cleaning the undefined values
8
8
  * @param obj an object
9
9
  * @returns the new object with no undefined values
10
10
  */
11
11
  function removeUndefinedDeep(obj) {
12
- if (obj == null || !(0, isObject_1.isObject)(obj) || !Array.isArray(obj))
12
+ const isArray = Array.isArray(obj);
13
+ if (obj == null || (!(0, isObject_1.isObject)(obj) && !isArray))
13
14
  return obj;
14
- const _obj = (0, cloneDeep_1.cloneDeep)(obj);
15
+ let _obj = (0, objectCopy_1.objectCopy)(obj);
16
+ if (isArray)
17
+ _obj = _obj.filter(Boolean);
15
18
  Object.keys(_obj).forEach((key) => {
16
19
  if ((0, isObject_1.isObject)(_obj[key]) || Array.isArray(_obj[key])) {
17
20
  _obj[key] = removeUndefinedDeep(_obj[key]);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sets an amount of zeros as prefix of the given number
3
+ * @example
4
+ * num = 100
5
+ * size = 2
6
+ * => Returns "00100"
7
+ * @example
8
+ * num = 100
9
+ * size = 5
10
+ * => Returns "00000100"
11
+ * @param {number | string} num the number
12
+ * @param {number} amount the quantity of zeros to add
13
+ * @returns the string of the number with the prefixed zeros
14
+ */
15
+ export declare function fillLeadingZeros(num: number | string, amount?: number): string;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fillLeadingZeros = void 0;
4
+ const isNaNV2_1 = require("../mix/isNaNV2");
5
+ const getSign_1 = require("../numeric/getSign");
6
+ /**
7
+ * Sets an amount of zeros as prefix of the given number
8
+ * @example
9
+ * num = 100
10
+ * size = 2
11
+ * => Returns "00100"
12
+ * @example
13
+ * num = 100
14
+ * size = 5
15
+ * => Returns "00000100"
16
+ * @param {number | string} num the number
17
+ * @param {number} amount the quantity of zeros to add
18
+ * @returns the string of the number with the prefixed zeros
19
+ */
20
+ function fillLeadingZeros(num, amount = 0) {
21
+ if ((0, isNaNV2_1.isNaNV2)(num) || (0, isNaNV2_1.isNaNV2)(amount))
22
+ return num;
23
+ const sign = getNumSign(num);
24
+ let absoluteStringNumber = getAbsoluteNum(num, sign);
25
+ let i = 0;
26
+ while (i < amount) {
27
+ absoluteStringNumber = `0${absoluteStringNumber}`;
28
+ i = i + 1;
29
+ }
30
+ return `${sign}${absoluteStringNumber}`;
31
+ }
32
+ exports.fillLeadingZeros = fillLeadingZeros;
33
+ /**
34
+ * Gets the absolute number of the giving parameters
35
+ * @param {number | string} num the number
36
+ * @param {string} sign the sign of the number
37
+ * @returns {string} the absolute number
38
+ */
39
+ function getAbsoluteNum(num, sign = "") {
40
+ const stringNum = `${num}`;
41
+ return sign !== "" && `${stringNum}`.charAt(0) === sign
42
+ ? stringNum.substring(1)
43
+ : stringNum;
44
+ }
45
+ /**
46
+ * Gets the number sign
47
+ * @param {number | string} num the number
48
+ * @returns {string} the number sign
49
+ */
50
+ function getNumSign(num) {
51
+ const stringNum = `${num}`;
52
+ const sign = (0, getSign_1.getSign)(num);
53
+ if (stringNum.charAt(0) === sign)
54
+ return sign;
55
+ return "";
56
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./capitalize";
2
+ export * from "./fillLeadingZeros";
2
3
  export * from "./padLeadingZeros";
3
4
  export * from "./parseUrl";
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./capitalize"), exports);
18
+ __exportStar(require("./fillLeadingZeros"), exports);
18
19
  __exportStar(require("./padLeadingZeros"), exports);
19
20
  __exportStar(require("./parseUrl"), exports);
@@ -1 +1,15 @@
1
+ /**
2
+ * Sets an amount of zeros as prefix of the given number by its length
3
+ * @example
4
+ * num = 100
5
+ * size = 2
6
+ * => Returns "100"
7
+ * @example
8
+ * num = 100
9
+ * size = 5
10
+ * => Returns "00100"
11
+ * @param num the number
12
+ * @param size the quantity of zeros to add
13
+ * @returns the string of the number with the prefixed zeros
14
+ */
1
15
  export declare function padLeadingZeros(num: number | string, size?: number): string;
@@ -1,12 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.padLeadingZeros = void 0;
4
+ const isNaNV2_1 = require("../mix/isNaNV2");
5
+ const getSign_1 = require("../numeric/getSign");
6
+ /**
7
+ * Sets an amount of zeros as prefix of the given number by its length
8
+ * @example
9
+ * num = 100
10
+ * size = 2
11
+ * => Returns "100"
12
+ * @example
13
+ * num = 100
14
+ * size = 5
15
+ * => Returns "00100"
16
+ * @param num the number
17
+ * @param size the quantity of zeros to add
18
+ * @returns the string of the number with the prefixed zeros
19
+ */
4
20
  function padLeadingZeros(num, size = 0) {
5
- if (isNaN(Number(num)))
6
- return String(num);
7
- let s = `${num}`;
8
- while (s.length < size)
9
- s = `0${s}`;
10
- return s;
21
+ if ((0, isNaNV2_1.isNaNV2)(num) || (0, isNaNV2_1.isNaNV2)(size))
22
+ return num;
23
+ const sign = getNumSign(num);
24
+ let absoluteStringNumber = getAbsoluteNum(num, sign);
25
+ while (absoluteStringNumber.length < size)
26
+ absoluteStringNumber = `0${absoluteStringNumber}`;
27
+ return `${sign}${absoluteStringNumber}`;
11
28
  }
12
29
  exports.padLeadingZeros = padLeadingZeros;
30
+ /**
31
+ * Gets the absolute number of the giving parameters
32
+ * @param {number | string} num the number
33
+ * @param {string} sign the sign of the number
34
+ * @returns {string} the absolute number
35
+ */
36
+ function getAbsoluteNum(num, sign = "") {
37
+ const stringNum = `${num}`;
38
+ return sign !== "" && `${stringNum}`.charAt(0) === sign
39
+ ? stringNum.substring(1)
40
+ : stringNum;
41
+ }
42
+ /**
43
+ * Gets the number sign
44
+ * @param {number | string} num the number
45
+ * @returns {string} the number sign
46
+ */
47
+ function getNumSign(num) {
48
+ const stringNum = `${num}`;
49
+ const sign = (0, getSign_1.getSign)(num);
50
+ if (stringNum.charAt(0) === sign)
51
+ return sign;
52
+ return "";
53
+ }
@@ -341,7 +341,7 @@ exports.I18N_FORMULA_BUILDER = {
341
341
  function_placeholder: "String.length()",
342
342
  },
343
343
  function_now: {
344
- description: "Return a date with the current time. Returned dates will have this format yyyy-MM-ddTHH:mm:ssZ.",
344
+ description: "Returns a date with the current time in the current timezone with the following format: yyyy-MM-ddTHH:mm:ss.",
345
345
  function_placeholder: "now()",
346
346
  },
347
347
  function_date_parse: {
@@ -396,7 +396,7 @@ exports.I18N_FORMULA_BUILDER = {
396
396
  param_column_name: "column",
397
397
  param_column_description: "Date column to check.",
398
398
  param_replacement_name: "replacement",
399
- param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'dd/MM/yyyy\', \'dd/MM/yyyy\'))"',
399
+ param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'31/12/2021\', \'dd/MM/yyyy\'))"',
400
400
  },
401
401
  function_agg_sum: {
402
402
  description: "A single-value metrics aggregation that sums up numeric values that are extracted from the documents",
@@ -1,4 +1,5 @@
1
1
  import { isEmpty } from "../../general/mix/isEmpty";
2
+ import { isNaNV2 } from "../../general/mix/isNaNV2";
2
3
  import { TIMEZONE_TYPE } from "../constants/TIMEZONE_TYPE";
3
4
  import { getTimezoneOffsetByType } from "./getTimezoneOffsetByType";
4
5
  import { getUTCFormatByOffset } from "./getUTCFormatByOffset";
@@ -88,7 +89,7 @@ function getTypeByOffset(offset) {
88
89
  else if (offset === "browser") {
89
90
  return TIMEZONE_TYPE.BROWSER;
90
91
  }
91
- else if (isValidISOOffset(offset)) {
92
+ else if (isValidISOOffset(offset) || !isNaNV2(offset)) {
92
93
  return TIMEZONE_TYPE.FIXED;
93
94
  }
94
95
  return TIMEZONE_TYPE.DEFAULT;
@@ -4,4 +4,4 @@
4
4
  * @param property the property to get the value collection
5
5
  * @returns a collection of values by property
6
6
  */
7
- export declare function getArrayByProperty<T = any>(arr: T[], property: string): T[];
7
+ export declare function getArrayByProperty<T = any>(arr: T[], property: string | number): T[];
@@ -6,4 +6,4 @@
6
6
  * @param prop Property name to search duplicated values
7
7
  * @return Array without duplicated items.
8
8
  */
9
- export declare function getUniqueArray(arr: any[], prop: string): any[];
9
+ export declare function getUniqueArray<T = any>(arr: T[], prop: string | number): T[];
@@ -7,6 +7,8 @@
7
7
  * @return Array without duplicated items.
8
8
  */
9
9
  export function getUniqueArray(arr, prop) {
10
+ if (!Array.isArray(arr))
11
+ return arr;
10
12
  return arr
11
13
  .map((e) => e[prop])
12
14
  .map((e, i, final) => final.indexOf(e) === i && i)
@@ -8,6 +8,7 @@
8
8
  * Special case for isNaN
9
9
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
10
10
  * - Boolean variables is considered as false statement.
11
+ * - Date objects is considered as true.
11
12
  *
12
13
  * @param variable the variable to validate
13
14
  * @return True: variable is a NaN; False: The variable is a number
@@ -1,4 +1,5 @@
1
- import { isEmpty } from ".";
1
+ import { isValidDateObject } from "../../dates/helpers/isValidDateObject";
2
+ import { isEmpty } from "./isEmpty";
2
3
  /**
3
4
  * Validates if the recieved number is NaN type.
4
5
  *
@@ -9,10 +10,14 @@ import { isEmpty } from ".";
9
10
  * Special case for isNaN
10
11
  * - The isNaN('') is considered as false statement. The empty string is converted to 0 which is not NaN.
11
12
  * - Boolean variables is considered as false statement.
13
+ * - Date objects is considered as true.
12
14
  *
13
15
  * @param variable the variable to validate
14
16
  * @return True: variable is a NaN; False: The variable is a number
15
17
  */
16
18
  export function isNaNV2(variable) {
17
- return isEmpty(variable) || typeof variable == "boolean" || isNaN(variable);
19
+ return (isEmpty(variable) ||
20
+ typeof variable == "boolean" ||
21
+ isNaN(variable) ||
22
+ isValidDateObject(variable));
18
23
  }
@@ -4,5 +4,5 @@
4
4
  * @returns {string} an string with the sign
5
5
  */
6
6
  export function getSign(num) {
7
- return Math.sign(num) > -1 ? "+" : "-";
7
+ return Math.sign(num) < 0 ? "-" : "+";
8
8
  }
@@ -5,4 +5,4 @@ import { IDTimezone } from "../../dates/interfaces/IDTimezone";
5
5
  * @param {IDTimezone} timezone the timezone object
6
6
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
7
7
  */
8
- export declare function applyTimezoneDeep(obj: any, timezone: IDTimezone): any;
8
+ export declare function applyTimezoneDeep<T = any>(obj: T, timezone: IDTimezone): T;
@@ -1,5 +1,6 @@
1
1
  import { DATE_FORMAT } from "../../dates/constants/DATE_FORMAT";
2
2
  import { getDateByTimezone } from "../../dates/helpers/getDateByTimezone";
3
+ import { isValidDateObject } from "../../dates/helpers/isValidDateObject";
3
4
  import { validateDate } from "../../dates/helpers/validateDate";
4
5
  import { isEmpty } from "../mix/isEmpty";
5
6
  import { isObject } from "./isObject";
@@ -10,7 +11,7 @@ import { isObject } from "./isObject";
10
11
  * @returns {IFSData | IFUData} the new filter data with the transformed datetime values
11
12
  */
12
13
  export function applyTimezoneDeep(obj, timezone) {
13
- if (isEmpty(obj))
14
+ if (!isValid(obj, timezone))
14
15
  return obj;
15
16
  let result;
16
17
  if (isObject(obj)) {
@@ -21,13 +22,13 @@ export function applyTimezoneDeep(obj, timezone) {
21
22
  }
22
23
  try {
23
24
  for (const i in obj) {
24
- if (isObject(obj[i]) || Array.isArray(obj[i])) {
25
- result[i] = applyTimezoneDeep(obj[i], timezone);
26
- }
27
- else if (obj[i] instanceof Date ||
25
+ if (isValidDateObject(obj[i]) ||
28
26
  validateDate(obj[i], DATE_FORMAT.HOUR)) {
29
27
  result[i] = getDateByTimezone(obj[i], timezone);
30
28
  }
29
+ else if (isObject(obj[i]) || Array.isArray(obj[i])) {
30
+ result[i] = applyTimezoneDeep(obj[i], timezone);
31
+ }
31
32
  else {
32
33
  result[i] = obj[i];
33
34
  }
@@ -38,3 +39,6 @@ export function applyTimezoneDeep(obj, timezone) {
38
39
  return obj;
39
40
  }
40
41
  }
42
+ function isValid(obj, timezone) {
43
+ return (!isEmpty(obj) && (Array.isArray(obj) || isObject(obj)) && !isEmpty(timezone));
44
+ }
@@ -6,5 +6,7 @@ import { getTag } from "../mix/getTag";
6
6
  */
7
7
  export function isObject(obj) {
8
8
  return (!Array.isArray(obj) &&
9
- (obj === Object(obj) || getTag(obj) === "[object Object]"));
9
+ obj === Object(obj) &&
10
+ getTag(obj) !== "[object Function]" &&
11
+ (getTag(obj) === "[object Object]" || getTag(obj) === "[object Date]"));
10
12
  }
@@ -4,4 +4,4 @@
4
4
  * @param cache
5
5
  * @returns A new reference of the given argument
6
6
  */
7
- export declare function objectCopy(entity: any, cache?: WeakMap<object, any>): any;
7
+ export declare function objectCopy<T = any>(entity: T, cache?: WeakMap<object, any>): T;
@@ -1,14 +1,17 @@
1
- import { cloneDeep } from "./cloneDeep";
2
1
  import { isObject } from "./isObject";
2
+ import { objectCopy } from "./objectCopy";
3
3
  /**
4
4
  * Removes and returns the given object cleaning the undefined values
5
5
  * @param obj an object
6
6
  * @returns the new object with no undefined values
7
7
  */
8
8
  export function removeUndefinedDeep(obj) {
9
- if (obj == null || !isObject(obj) || !Array.isArray(obj))
9
+ const isArray = Array.isArray(obj);
10
+ if (obj == null || (!isObject(obj) && !isArray))
10
11
  return obj;
11
- const _obj = cloneDeep(obj);
12
+ let _obj = objectCopy(obj);
13
+ if (isArray)
14
+ _obj = _obj.filter(Boolean);
12
15
  Object.keys(_obj).forEach((key) => {
13
16
  if (isObject(_obj[key]) || Array.isArray(_obj[key])) {
14
17
  _obj[key] = removeUndefinedDeep(_obj[key]);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sets an amount of zeros as prefix of the given number
3
+ * @example
4
+ * num = 100
5
+ * size = 2
6
+ * => Returns "00100"
7
+ * @example
8
+ * num = 100
9
+ * size = 5
10
+ * => Returns "00000100"
11
+ * @param {number | string} num the number
12
+ * @param {number} amount the quantity of zeros to add
13
+ * @returns the string of the number with the prefixed zeros
14
+ */
15
+ export declare function fillLeadingZeros(num: number | string, amount?: number): string;
@@ -0,0 +1,52 @@
1
+ import { isNaNV2 } from "../mix/isNaNV2";
2
+ import { getSign } from "../numeric/getSign";
3
+ /**
4
+ * Sets an amount of zeros as prefix of the given number
5
+ * @example
6
+ * num = 100
7
+ * size = 2
8
+ * => Returns "00100"
9
+ * @example
10
+ * num = 100
11
+ * size = 5
12
+ * => Returns "00000100"
13
+ * @param {number | string} num the number
14
+ * @param {number} amount the quantity of zeros to add
15
+ * @returns the string of the number with the prefixed zeros
16
+ */
17
+ export function fillLeadingZeros(num, amount = 0) {
18
+ if (isNaNV2(num) || isNaNV2(amount))
19
+ return num;
20
+ const sign = getNumSign(num);
21
+ let absoluteStringNumber = getAbsoluteNum(num, sign);
22
+ let i = 0;
23
+ while (i < amount) {
24
+ absoluteStringNumber = `0${absoluteStringNumber}`;
25
+ i = i + 1;
26
+ }
27
+ return `${sign}${absoluteStringNumber}`;
28
+ }
29
+ /**
30
+ * Gets the absolute number of the giving parameters
31
+ * @param {number | string} num the number
32
+ * @param {string} sign the sign of the number
33
+ * @returns {string} the absolute number
34
+ */
35
+ function getAbsoluteNum(num, sign = "") {
36
+ const stringNum = `${num}`;
37
+ return sign !== "" && `${stringNum}`.charAt(0) === sign
38
+ ? stringNum.substring(1)
39
+ : stringNum;
40
+ }
41
+ /**
42
+ * Gets the number sign
43
+ * @param {number | string} num the number
44
+ * @returns {string} the number sign
45
+ */
46
+ function getNumSign(num) {
47
+ const stringNum = `${num}`;
48
+ const sign = getSign(num);
49
+ if (stringNum.charAt(0) === sign)
50
+ return sign;
51
+ return "";
52
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./capitalize";
2
+ export * from "./fillLeadingZeros";
2
3
  export * from "./padLeadingZeros";
3
4
  export * from "./parseUrl";
@@ -1,3 +1,4 @@
1
1
  export * from "./capitalize";
2
+ export * from "./fillLeadingZeros";
2
3
  export * from "./padLeadingZeros";
3
4
  export * from "./parseUrl";
@@ -1 +1,15 @@
1
+ /**
2
+ * Sets an amount of zeros as prefix of the given number by its length
3
+ * @example
4
+ * num = 100
5
+ * size = 2
6
+ * => Returns "100"
7
+ * @example
8
+ * num = 100
9
+ * size = 5
10
+ * => Returns "00100"
11
+ * @param num the number
12
+ * @param size the quantity of zeros to add
13
+ * @returns the string of the number with the prefixed zeros
14
+ */
1
15
  export declare function padLeadingZeros(num: number | string, size?: number): string;
@@ -1,8 +1,49 @@
1
+ import { isNaNV2 } from "../mix/isNaNV2";
2
+ import { getSign } from "../numeric/getSign";
3
+ /**
4
+ * Sets an amount of zeros as prefix of the given number by its length
5
+ * @example
6
+ * num = 100
7
+ * size = 2
8
+ * => Returns "100"
9
+ * @example
10
+ * num = 100
11
+ * size = 5
12
+ * => Returns "00100"
13
+ * @param num the number
14
+ * @param size the quantity of zeros to add
15
+ * @returns the string of the number with the prefixed zeros
16
+ */
1
17
  export function padLeadingZeros(num, size = 0) {
2
- if (isNaN(Number(num)))
3
- return String(num);
4
- let s = `${num}`;
5
- while (s.length < size)
6
- s = `0${s}`;
7
- return s;
18
+ if (isNaNV2(num) || isNaNV2(size))
19
+ return num;
20
+ const sign = getNumSign(num);
21
+ let absoluteStringNumber = getAbsoluteNum(num, sign);
22
+ while (absoluteStringNumber.length < size)
23
+ absoluteStringNumber = `0${absoluteStringNumber}`;
24
+ return `${sign}${absoluteStringNumber}`;
25
+ }
26
+ /**
27
+ * Gets the absolute number of the giving parameters
28
+ * @param {number | string} num the number
29
+ * @param {string} sign the sign of the number
30
+ * @returns {string} the absolute number
31
+ */
32
+ function getAbsoluteNum(num, sign = "") {
33
+ const stringNum = `${num}`;
34
+ return sign !== "" && `${stringNum}`.charAt(0) === sign
35
+ ? stringNum.substring(1)
36
+ : stringNum;
37
+ }
38
+ /**
39
+ * Gets the number sign
40
+ * @param {number | string} num the number
41
+ * @returns {string} the number sign
42
+ */
43
+ function getNumSign(num) {
44
+ const stringNum = `${num}`;
45
+ const sign = getSign(num);
46
+ if (stringNum.charAt(0) === sign)
47
+ return sign;
48
+ return "";
8
49
  }
@@ -338,7 +338,7 @@ export const I18N_FORMULA_BUILDER = {
338
338
  function_placeholder: "String.length()",
339
339
  },
340
340
  function_now: {
341
- description: "Return a date with the current time. Returned dates will have this format yyyy-MM-ddTHH:mm:ssZ.",
341
+ description: "Returns a date with the current time in the current timezone with the following format: yyyy-MM-ddTHH:mm:ss.",
342
342
  function_placeholder: "now()",
343
343
  },
344
344
  function_date_parse: {
@@ -393,7 +393,7 @@ export const I18N_FORMULA_BUILDER = {
393
393
  param_column_name: "column",
394
394
  param_column_description: "Date column to check.",
395
395
  param_replacement_name: "replacement",
396
- param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'dd/MM/yyyy\', \'dd/MM/yyyy\'))"',
396
+ param_replacement_description: 'Date replacement value.<br>Common Replacement Value Formats:<br>○ Using another date column "dateIsNull(Column1, Column2)"<br>○ Using another date function "dateIsNull(Column, now())"<br>○ Using specified date "dateIsNull(Column, dateParse(\'31/12/2021\', \'dd/MM/yyyy\'))"',
397
397
  },
398
398
  function_agg_sum: {
399
399
  description: "A single-value metrics aggregation that sums up numeric values that are extracted from the documents",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.10.0-10",
3
+ "version": "1.10.0-12",
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",