@hestia-earth/utils 0.10.21 → 0.10.24
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/date.d.ts +2 -0
- package/dist/date.js +17 -1
- package/dist/term.js +9 -6
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare const dayMs: number;
|
|
|
5
5
|
export declare const diffInDays: (date1: Date | string, date2: Date | string) => number;
|
|
6
6
|
export declare const diffInYears: (date1: Date | string, date2: Date | string) => number;
|
|
7
7
|
export declare const daysBefore: (date?: Date, days?: number) => Date;
|
|
8
|
+
export declare const hoursBefore: (date?: Date, hours?: number) => Date;
|
|
9
|
+
export declare const minutesBefore: (date?: Date, minutes?: number) => Date;
|
package/dist/date.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.daysBefore = exports.diffInYears = exports.diffInDays = exports.dayMs = exports.hourMs = exports.minuteMs = exports.secondMs = void 0;
|
|
3
|
+
exports.minutesBefore = exports.hoursBefore = exports.daysBefore = exports.diffInYears = exports.diffInDays = exports.dayMs = exports.hourMs = exports.minuteMs = exports.secondMs = void 0;
|
|
4
4
|
exports.secondMs = 1000;
|
|
5
5
|
exports.minuteMs = 60 * exports.secondMs;
|
|
6
6
|
exports.hourMs = 60 * exports.minuteMs;
|
|
@@ -22,3 +22,19 @@ var daysBefore = function (date, days) {
|
|
|
22
22
|
return newDate;
|
|
23
23
|
};
|
|
24
24
|
exports.daysBefore = daysBefore;
|
|
25
|
+
var hoursBefore = function (date, hours) {
|
|
26
|
+
if (date === void 0) { date = new Date(); }
|
|
27
|
+
if (hours === void 0) { hours = 1; }
|
|
28
|
+
var newDate = new Date(date);
|
|
29
|
+
newDate.setHours(date.getHours() - hours);
|
|
30
|
+
return newDate;
|
|
31
|
+
};
|
|
32
|
+
exports.hoursBefore = hoursBefore;
|
|
33
|
+
var minutesBefore = function (date, minutes) {
|
|
34
|
+
if (date === void 0) { date = new Date(); }
|
|
35
|
+
if (minutes === void 0) { minutes = 1; }
|
|
36
|
+
var newDate = new Date(date);
|
|
37
|
+
newDate.setMinutes(date.getMinutes() - minutes);
|
|
38
|
+
return newDate;
|
|
39
|
+
};
|
|
40
|
+
exports.minutesBefore = minutesBefore;
|
package/dist/term.js
CHANGED
|
@@ -4,16 +4,19 @@ 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
6
|
var arrayValue = function (values, isAverage) {
|
|
7
|
+
if (values === void 0) { values = []; }
|
|
7
8
|
if (isAverage === void 0) { isAverage = false; }
|
|
8
|
-
return
|
|
9
|
+
return values.every(utils_1.isEmpty)
|
|
10
|
+
? null
|
|
11
|
+
: values.filter(function (v) { return typeof v !== 'undefined'; }).reduce(function (prev, curr) { return prev + (utils_1.isEmpty(curr) ? 0 : parseFloat("" + curr)); }, 0) / (isAverage ? values.filter(function (v) { return !utils_1.isEmpty(v); }).length : 1);
|
|
9
12
|
};
|
|
10
13
|
exports.arrayValue = arrayValue;
|
|
11
14
|
var propertyValue = function (value, termId) {
|
|
12
|
-
return typeof value === 'undefined' || value === null
|
|
13
|
-
null
|
|
14
|
-
|
|
15
|
-
exports.arrayValue(value, (termId ? glossary_1.getArrayTreatment(termId) : null) === 'mean')
|
|
16
|
-
parseFloat("" + value)
|
|
15
|
+
return typeof value === 'undefined' || value === null
|
|
16
|
+
? null
|
|
17
|
+
: Array.isArray(value)
|
|
18
|
+
? exports.arrayValue(value, (termId ? glossary_1.getArrayTreatment(termId) : null) === 'mean')
|
|
19
|
+
: parseFloat("" + value);
|
|
17
20
|
};
|
|
18
21
|
exports.propertyValue = propertyValue;
|
|
19
22
|
var emptyValue = function (value, termId) { return utils_1.isEmpty(value) || isNaN(exports.propertyValue(value, termId)); };
|