@hestia-earth/utils 0.12.3 → 0.12.5
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/boolean.d.ts +1 -1
- package/dist/boolean.js +3 -1
- package/dist/term.d.ts +5 -5
- package/dist/term.js +19 -10
- package/package.json +2 -2
package/dist/boolean.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isBoolean: (value: string) => boolean;
|
|
1
|
+
export declare const isBoolean: (value: string | boolean) => boolean;
|
package/dist/boolean.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBoolean = void 0;
|
|
4
|
-
var isBoolean = function (value) {
|
|
4
|
+
var isBoolean = function (value) {
|
|
5
|
+
return typeof value === 'boolean' || value.toLowerCase() === 'true' || value.toLowerCase() === 'false';
|
|
6
|
+
};
|
|
5
7
|
exports.isBoolean = isBoolean;
|
package/dist/term.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare type propertyValueType = string | number | boolean | null;
|
|
2
|
+
export declare const arrayValue: (values?: propertyValueType[], isAverage?: boolean) => string | number | boolean;
|
|
2
3
|
/**
|
|
3
4
|
* Calculate the final value of a property.
|
|
4
5
|
*
|
|
5
|
-
* @param value The value as an array or a string/number.
|
|
6
|
+
* @param value The value as an array or a string/number/boolean.
|
|
6
7
|
* @param termId Optional - us if the term should handle an array in a specific way.
|
|
7
|
-
* @returns The value as a number.
|
|
8
8
|
*/
|
|
9
|
-
export declare const propertyValue: (value:
|
|
9
|
+
export declare const propertyValue: (value: propertyValueType | propertyValueType[], termId?: string) => propertyValueType;
|
|
10
10
|
/**
|
|
11
11
|
* Checks if the value is empty or if the property value is empty.
|
|
12
12
|
*
|
|
13
13
|
* @param value
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
export declare const emptyValue: (value:
|
|
16
|
+
export declare const emptyValue: (value: propertyValueType, termId?: string) => boolean;
|
package/dist/term.js
CHANGED
|
@@ -3,30 +3,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.emptyValue = exports.propertyValue = exports.arrayValue = void 0;
|
|
4
4
|
var glossary_1 = require("@hestia-earth/glossary");
|
|
5
5
|
var utils_1 = require("./utils");
|
|
6
|
+
var number_1 = require("./number");
|
|
7
|
+
var boolean_1 = require("./boolean");
|
|
6
8
|
var arrayValue = function (values, isAverage) {
|
|
7
9
|
if (values === void 0) { values = []; }
|
|
8
10
|
if (isAverage === void 0) { isAverage = false; }
|
|
9
|
-
|
|
11
|
+
var filteredValues = values.filter(function (v) { return !utils_1.isEmpty(v); });
|
|
12
|
+
return filteredValues.length === 0
|
|
10
13
|
? null
|
|
11
|
-
:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
: filteredValues.every(number_1.isNumber)
|
|
15
|
+
? filteredValues
|
|
16
|
+
.filter(function (v) { return typeof v !== 'undefined'; })
|
|
17
|
+
.reduce(function (prev, curr) { return prev + parseFloat("" + curr); }, 0) / (isAverage ? filteredValues.length : 1)
|
|
18
|
+
: filteredValues.every(boolean_1.isBoolean)
|
|
19
|
+
? filteredValues.every(Boolean)
|
|
20
|
+
: filteredValues.join(';');
|
|
15
21
|
};
|
|
16
22
|
exports.arrayValue = arrayValue;
|
|
17
23
|
/**
|
|
18
24
|
* Calculate the final value of a property.
|
|
19
25
|
*
|
|
20
|
-
* @param value The value as an array or a string/number.
|
|
26
|
+
* @param value The value as an array or a string/number/boolean.
|
|
21
27
|
* @param termId Optional - us if the term should handle an array in a specific way.
|
|
22
|
-
* @returns The value as a number.
|
|
23
28
|
*/
|
|
24
29
|
var propertyValue = function (value, termId) {
|
|
25
|
-
return
|
|
30
|
+
return utils_1.isUndefined(value)
|
|
26
31
|
? null
|
|
27
32
|
: Array.isArray(value)
|
|
28
33
|
? exports.arrayValue(value, (termId ? glossary_1.getArrayTreatment(termId) : null) === 'mean')
|
|
29
|
-
:
|
|
34
|
+
: number_1.isNumber(value)
|
|
35
|
+
? parseFloat("" + value)
|
|
36
|
+
: value;
|
|
30
37
|
};
|
|
31
38
|
exports.propertyValue = propertyValue;
|
|
32
39
|
/**
|
|
@@ -35,5 +42,7 @@ exports.propertyValue = propertyValue;
|
|
|
35
42
|
* @param value
|
|
36
43
|
* @returns
|
|
37
44
|
*/
|
|
38
|
-
var emptyValue = function (value, termId) {
|
|
45
|
+
var emptyValue = function (value, termId) {
|
|
46
|
+
return utils_1.isEmpty(value) || isNaN(exports.propertyValue(value, termId));
|
|
47
|
+
};
|
|
39
48
|
exports.emptyValue = emptyValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hestia-earth/utils",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"description": "Hestia Utils library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"homepage": "https://gitlab.com/hestia-earth/hestia-utils#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hestia-earth/eslint-config": "^0.1.0",
|
|
36
|
-
"@hestia-earth/glossary": "^0.
|
|
36
|
+
"@hestia-earth/glossary": "^0.44.0",
|
|
37
37
|
"@types/chai": "^4.2.21",
|
|
38
38
|
"@types/mocha": "^7.0.2",
|
|
39
39
|
"@types/node": "^16.18.59",
|