@qrvey/utils 1.10.0-11 → 1.10.0-13
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/dist/cjs/dates/adapters/ISOToNumericOffset.js +4 -1
- package/dist/cjs/general/array/getArrayByProperty.d.ts +1 -1
- package/dist/cjs/general/array/getUniqueArray.d.ts +1 -1
- package/dist/cjs/general/array/getUniqueArray.js +2 -0
- package/dist/cjs/general/mix/isEmpty.js +2 -0
- package/dist/cjs/general/mix/isNaNV2.d.ts +1 -0
- package/dist/cjs/general/mix/isNaNV2.js +7 -2
- package/dist/cjs/general/numeric/getSign.js +1 -1
- package/dist/cjs/general/object/applyTimezoneDeep.d.ts +1 -1
- package/dist/cjs/general/object/applyTimezoneDeep.js +9 -5
- package/dist/cjs/general/object/isObject.js +3 -1
- package/dist/cjs/general/object/objectCopy.d.ts +1 -1
- package/dist/cjs/general/object/removeUndefinedDeep.js +6 -3
- package/dist/cjs/general/string/padLeadingZeros.d.ts +28 -1
- package/dist/cjs/general/string/padLeadingZeros.js +75 -7
- package/dist/cjs/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +2 -2
- package/dist/dates/adapters/ISOToNumericOffset.js +4 -1
- package/dist/general/array/getArrayByProperty.d.ts +1 -1
- package/dist/general/array/getUniqueArray.d.ts +1 -1
- package/dist/general/array/getUniqueArray.js +2 -0
- package/dist/general/mix/isEmpty.js +2 -0
- package/dist/general/mix/isNaNV2.d.ts +1 -0
- package/dist/general/mix/isNaNV2.js +7 -2
- package/dist/general/numeric/getSign.js +1 -1
- package/dist/general/object/applyTimezoneDeep.d.ts +1 -1
- package/dist/general/object/applyTimezoneDeep.js +9 -5
- package/dist/general/object/isObject.js +3 -1
- package/dist/general/object/objectCopy.d.ts +1 -1
- package/dist/general/object/removeUndefinedDeep.js +6 -3
- package/dist/general/string/padLeadingZeros.d.ts +28 -1
- package/dist/general/string/padLeadingZeros.js +75 -7
- package/dist/globalization/labels/formula_builder/I18N_FORMULA_BUILDER.js +2 -2
- package/package.json +4 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ISOToNumericOffset = void 0;
|
|
4
4
|
const isNaNV2_1 = require("../../general/mix/isNaNV2");
|
|
5
|
+
const getSign_1 = require("../../general/numeric/getSign");
|
|
5
6
|
const isValidISOOffset_1 = require("../helpers/isValidISOOffset");
|
|
6
7
|
/**
|
|
7
8
|
* Gets the numeric offset (minutes) from the ISO offset (string)
|
|
@@ -16,6 +17,8 @@ function ISOToNumericOffset(offset) {
|
|
|
16
17
|
if (!(0, isValidISOOffset_1.isValidISOOffset)(offset))
|
|
17
18
|
return 0;
|
|
18
19
|
const [hours, minutes] = offset.split(":").map(Number);
|
|
19
|
-
|
|
20
|
+
const sign = (0, getSign_1.getSign)(hours);
|
|
21
|
+
const absoluteOffset = Math.abs(hours) * 60 + minutes;
|
|
22
|
+
return sign === "-" ? -1 * absoluteOffset : absoluteOffset;
|
|
20
23
|
}
|
|
21
24
|
exports.ISOToNumericOffset = ISOToNumericOffset;
|
|
@@ -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[];
|
|
@@ -26,6 +26,8 @@ function isEmpty(variable, includeFalsy = false) {
|
|
|
26
26
|
(!(variable instanceof Date) &&
|
|
27
27
|
typeof variable !== "function" &&
|
|
28
28
|
(0, isObject_1.isObject)(variable) &&
|
|
29
|
+
Object.entries(variable).length === 0) ||
|
|
30
|
+
((0, getTag_1.getTag)(variable) === "[object NodeList]" &&
|
|
29
31
|
Object.entries(variable).length === 0));
|
|
30
32
|
}
|
|
31
33
|
exports.isEmpty = isEmpty;
|
|
@@ -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
|
|
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,
|
|
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;
|
|
@@ -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:
|
|
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 ((
|
|
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,
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
12
|
+
const isArray = Array.isArray(obj);
|
|
13
|
+
if (obj == null || (!(0, isObject_1.isObject)(obj) && !isArray))
|
|
13
14
|
return obj;
|
|
14
|
-
|
|
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]);
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
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
|
+
* padding = true
|
|
7
|
+
* => Returns "100"
|
|
8
|
+
* @example
|
|
9
|
+
* num = 100
|
|
10
|
+
* size = 5
|
|
11
|
+
* padding = true
|
|
12
|
+
* => Returns "00100"
|
|
13
|
+
* @example
|
|
14
|
+
* num = 100
|
|
15
|
+
* size = 2
|
|
16
|
+
* padding = false
|
|
17
|
+
* => Returns "00100"
|
|
18
|
+
* @example
|
|
19
|
+
* num = 100
|
|
20
|
+
* size = 5
|
|
21
|
+
* padding = false
|
|
22
|
+
* => Returns "00000100"
|
|
23
|
+
* @param {number | string} num the number
|
|
24
|
+
* @param {number} size the quantity of zeros to add
|
|
25
|
+
* @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
|
|
26
|
+
* @returns the string of the number with the prefixed zeros
|
|
27
|
+
*/
|
|
28
|
+
export declare function padLeadingZeros(num: number | string, amount?: number, padding?: boolean): string;
|
|
@@ -1,12 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.padLeadingZeros = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const mix_1 = require("../mix");
|
|
5
|
+
const isNaNV2_1 = require("../mix/isNaNV2");
|
|
6
|
+
const getSign_1 = require("../numeric/getSign");
|
|
7
|
+
/**
|
|
8
|
+
* Sets an amount of zeros as prefix of the given number by its length
|
|
9
|
+
* @example
|
|
10
|
+
* num = 100
|
|
11
|
+
* size = 2
|
|
12
|
+
* padding = true
|
|
13
|
+
* => Returns "100"
|
|
14
|
+
* @example
|
|
15
|
+
* num = 100
|
|
16
|
+
* size = 5
|
|
17
|
+
* padding = true
|
|
18
|
+
* => Returns "00100"
|
|
19
|
+
* @example
|
|
20
|
+
* num = 100
|
|
21
|
+
* size = 2
|
|
22
|
+
* padding = false
|
|
23
|
+
* => Returns "00100"
|
|
24
|
+
* @example
|
|
25
|
+
* num = 100
|
|
26
|
+
* size = 5
|
|
27
|
+
* padding = false
|
|
28
|
+
* => Returns "00000100"
|
|
29
|
+
* @param {number | string} num the number
|
|
30
|
+
* @param {number} size the quantity of zeros to add
|
|
31
|
+
* @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
|
|
32
|
+
* @returns the string of the number with the prefixed zeros
|
|
33
|
+
*/
|
|
34
|
+
function padLeadingZeros(num, amount = 0, padding = true) {
|
|
35
|
+
if (isValidLeadingZerosParams(num, amount))
|
|
36
|
+
return num;
|
|
37
|
+
const newPadding = !(0, mix_1.isEmpty)(padding, true);
|
|
38
|
+
const sign = getNumSign(num);
|
|
39
|
+
let absoluteStringNumber = getAbsoluteNum(num, sign);
|
|
40
|
+
if (newPadding) {
|
|
41
|
+
while (absoluteStringNumber.length < amount)
|
|
42
|
+
absoluteStringNumber = `0${absoluteStringNumber}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
let i = 0;
|
|
46
|
+
while (i < amount) {
|
|
47
|
+
absoluteStringNumber = `0${absoluteStringNumber}`;
|
|
48
|
+
i = i + 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return `${sign}${absoluteStringNumber}`;
|
|
11
52
|
}
|
|
12
53
|
exports.padLeadingZeros = padLeadingZeros;
|
|
54
|
+
function isValidLeadingZerosParams(num, amount) {
|
|
55
|
+
return (0, isNaNV2_1.isNaNV2)(num) || (0, isNaNV2_1.isNaNV2)(amount);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the absolute number of the giving parameters
|
|
59
|
+
* @param {number | string} num the number
|
|
60
|
+
* @param {string} sign the sign of the number
|
|
61
|
+
* @returns {string} the absolute number
|
|
62
|
+
*/
|
|
63
|
+
function getAbsoluteNum(num, sign = "") {
|
|
64
|
+
const stringNum = `${num}`;
|
|
65
|
+
return sign !== "" && `${stringNum}`.charAt(0) === sign
|
|
66
|
+
? stringNum.substring(1)
|
|
67
|
+
: stringNum;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the number sign
|
|
71
|
+
* @param {number | string} num the number
|
|
72
|
+
* @returns {string} the number sign
|
|
73
|
+
*/
|
|
74
|
+
function getNumSign(num) {
|
|
75
|
+
const stringNum = `${num}`;
|
|
76
|
+
const sign = (0, getSign_1.getSign)(num);
|
|
77
|
+
if (stringNum.charAt(0) === sign)
|
|
78
|
+
return sign;
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
@@ -341,7 +341,7 @@ exports.I18N_FORMULA_BUILDER = {
|
|
|
341
341
|
function_placeholder: "String.length()",
|
|
342
342
|
},
|
|
343
343
|
function_now: {
|
|
344
|
-
description: "
|
|
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(\'
|
|
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 { isNaNV2 } from "../../general/mix/isNaNV2";
|
|
2
|
+
import { getSign } from "../../general/numeric/getSign";
|
|
2
3
|
import { isValidISOOffset } from "../helpers/isValidISOOffset";
|
|
3
4
|
/**
|
|
4
5
|
* Gets the numeric offset (minutes) from the ISO offset (string)
|
|
@@ -13,5 +14,7 @@ export function ISOToNumericOffset(offset) {
|
|
|
13
14
|
if (!isValidISOOffset(offset))
|
|
14
15
|
return 0;
|
|
15
16
|
const [hours, minutes] = offset.split(":").map(Number);
|
|
16
|
-
|
|
17
|
+
const sign = getSign(hours);
|
|
18
|
+
const absoluteOffset = Math.abs(hours) * 60 + minutes;
|
|
19
|
+
return sign === "-" ? -1 * absoluteOffset : absoluteOffset;
|
|
17
20
|
}
|
|
@@ -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[];
|
|
@@ -23,5 +23,7 @@ export function isEmpty(variable, includeFalsy = false) {
|
|
|
23
23
|
(!(variable instanceof Date) &&
|
|
24
24
|
typeof variable !== "function" &&
|
|
25
25
|
isObject(variable) &&
|
|
26
|
+
Object.entries(variable).length === 0) ||
|
|
27
|
+
(getTag(variable) === "[object NodeList]" &&
|
|
26
28
|
Object.entries(variable).length === 0));
|
|
27
29
|
}
|
|
@@ -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 {
|
|
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) ||
|
|
19
|
+
return (isEmpty(variable) ||
|
|
20
|
+
typeof variable == "boolean" ||
|
|
21
|
+
isNaN(variable) ||
|
|
22
|
+
isValidDateObject(variable));
|
|
18
23
|
}
|
|
@@ -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:
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
9
|
+
obj === Object(obj) &&
|
|
10
|
+
getTag(obj) !== "[object Function]" &&
|
|
11
|
+
(getTag(obj) === "[object Object]" || getTag(obj) === "[object Date]"));
|
|
10
12
|
}
|
|
@@ -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
|
-
|
|
9
|
+
const isArray = Array.isArray(obj);
|
|
10
|
+
if (obj == null || (!isObject(obj) && !isArray))
|
|
10
11
|
return obj;
|
|
11
|
-
|
|
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]);
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
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
|
+
* padding = true
|
|
7
|
+
* => Returns "100"
|
|
8
|
+
* @example
|
|
9
|
+
* num = 100
|
|
10
|
+
* size = 5
|
|
11
|
+
* padding = true
|
|
12
|
+
* => Returns "00100"
|
|
13
|
+
* @example
|
|
14
|
+
* num = 100
|
|
15
|
+
* size = 2
|
|
16
|
+
* padding = false
|
|
17
|
+
* => Returns "00100"
|
|
18
|
+
* @example
|
|
19
|
+
* num = 100
|
|
20
|
+
* size = 5
|
|
21
|
+
* padding = false
|
|
22
|
+
* => Returns "00000100"
|
|
23
|
+
* @param {number | string} num the number
|
|
24
|
+
* @param {number} size the quantity of zeros to add
|
|
25
|
+
* @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
|
|
26
|
+
* @returns the string of the number with the prefixed zeros
|
|
27
|
+
*/
|
|
28
|
+
export declare function padLeadingZeros(num: number | string, amount?: number, padding?: boolean): string;
|
|
@@ -1,8 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { isEmpty } from "../mix";
|
|
2
|
+
import { isNaNV2 } from "../mix/isNaNV2";
|
|
3
|
+
import { getSign } from "../numeric/getSign";
|
|
4
|
+
/**
|
|
5
|
+
* Sets an amount of zeros as prefix of the given number by its length
|
|
6
|
+
* @example
|
|
7
|
+
* num = 100
|
|
8
|
+
* size = 2
|
|
9
|
+
* padding = true
|
|
10
|
+
* => Returns "100"
|
|
11
|
+
* @example
|
|
12
|
+
* num = 100
|
|
13
|
+
* size = 5
|
|
14
|
+
* padding = true
|
|
15
|
+
* => Returns "00100"
|
|
16
|
+
* @example
|
|
17
|
+
* num = 100
|
|
18
|
+
* size = 2
|
|
19
|
+
* padding = false
|
|
20
|
+
* => Returns "00100"
|
|
21
|
+
* @example
|
|
22
|
+
* num = 100
|
|
23
|
+
* size = 5
|
|
24
|
+
* padding = false
|
|
25
|
+
* => Returns "00000100"
|
|
26
|
+
* @param {number | string} num the number
|
|
27
|
+
* @param {number} size the quantity of zeros to add
|
|
28
|
+
* @param {number} padding True: to pad with missing zeros; depending on the num length. False: to fill zeros by the amount.
|
|
29
|
+
* @returns the string of the number with the prefixed zeros
|
|
30
|
+
*/
|
|
31
|
+
export function padLeadingZeros(num, amount = 0, padding = true) {
|
|
32
|
+
if (isValidLeadingZerosParams(num, amount))
|
|
33
|
+
return num;
|
|
34
|
+
const newPadding = !isEmpty(padding, true);
|
|
35
|
+
const sign = getNumSign(num);
|
|
36
|
+
let absoluteStringNumber = getAbsoluteNum(num, sign);
|
|
37
|
+
if (newPadding) {
|
|
38
|
+
while (absoluteStringNumber.length < amount)
|
|
39
|
+
absoluteStringNumber = `0${absoluteStringNumber}`;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
let i = 0;
|
|
43
|
+
while (i < amount) {
|
|
44
|
+
absoluteStringNumber = `0${absoluteStringNumber}`;
|
|
45
|
+
i = i + 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return `${sign}${absoluteStringNumber}`;
|
|
49
|
+
}
|
|
50
|
+
function isValidLeadingZerosParams(num, amount) {
|
|
51
|
+
return isNaNV2(num) || isNaNV2(amount);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the absolute number of the giving parameters
|
|
55
|
+
* @param {number | string} num the number
|
|
56
|
+
* @param {string} sign the sign of the number
|
|
57
|
+
* @returns {string} the absolute number
|
|
58
|
+
*/
|
|
59
|
+
function getAbsoluteNum(num, sign = "") {
|
|
60
|
+
const stringNum = `${num}`;
|
|
61
|
+
return sign !== "" && `${stringNum}`.charAt(0) === sign
|
|
62
|
+
? stringNum.substring(1)
|
|
63
|
+
: stringNum;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the number sign
|
|
67
|
+
* @param {number | string} num the number
|
|
68
|
+
* @returns {string} the number sign
|
|
69
|
+
*/
|
|
70
|
+
function getNumSign(num) {
|
|
71
|
+
const stringNum = `${num}`;
|
|
72
|
+
const sign = getSign(num);
|
|
73
|
+
if (stringNum.charAt(0) === sign)
|
|
74
|
+
return sign;
|
|
75
|
+
return "";
|
|
8
76
|
}
|
|
@@ -338,7 +338,7 @@ export const I18N_FORMULA_BUILDER = {
|
|
|
338
338
|
function_placeholder: "String.length()",
|
|
339
339
|
},
|
|
340
340
|
function_now: {
|
|
341
|
-
description: "
|
|
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(\'
|
|
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-
|
|
3
|
+
"version": "1.10.0-13",
|
|
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",
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
"publishing.beta.1": "node ./scripts/publishing --np-new-version=$npm_config_np_new_version --np-any-branch=$npm_config_np_any_branch --np-tag=$npm_config_np_tag",
|
|
16
16
|
"publishing": "node ./scripts/clean-build && np $npm_config_np_new_version --any-branch --tag=$npm_config_np_tag",
|
|
17
17
|
"publishing.win": "node ./scripts/clean-build && np %npm_config_np_new_version% --any-branch --tag=%npm_config_np_tag%",
|
|
18
|
-
"test": "jest test",
|
|
19
|
-
"test.
|
|
18
|
+
"test": "jest test --verbose",
|
|
19
|
+
"test.coverage": "jest test --collect-coverage",
|
|
20
|
+
"test.watch": "jest test --watch ",
|
|
20
21
|
"version": "auto-changelog -p && git add CHANGELOG.md"
|
|
21
22
|
},
|
|
22
23
|
"author": "Qrvey Inc",
|