@hestia-earth/schema-convert 27.0.0 → 27.2.0
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/default-values.d.ts +13 -2
- package/default-values.js +35 -6
- package/package.json +1 -1
- package/utils.d.ts +1 -0
- package/utils.js +9 -1
package/default-values.d.ts
CHANGED
|
@@ -2,8 +2,18 @@ import { SchemaType, JSON as HestiaJson, Cycle, Product, Site, Organisation, Ter
|
|
|
2
2
|
export declare const siteLocationName: (region?: Term, country?: Term) => string;
|
|
3
3
|
export declare const primaryProduct: (products?: Product[], defaultValue?: Product) => Product;
|
|
4
4
|
export declare const cycleDefaultName: ({ endDate, treatment, description }: Cycle, site?: Site, product?: Product) => string;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Parse date in format `YYYY-MM-DD, YYYY-MM, or YYYY`.
|
|
7
|
+
*
|
|
8
|
+
* @param date The date as a string;
|
|
9
|
+
* @param isStart If the date is a `startDate`, meaning `2000` will be set as `2000-01-01`.
|
|
10
|
+
* If it is an `endDate`, then `2000` will be set as `2000-12-31`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseDate: (date: string, isStart?: boolean) => Date;
|
|
13
|
+
export declare const calculateCycleDuration: ({ cycleDuration, startDate, endDate }: Partial<Cycle>) => boolean;
|
|
14
|
+
export declare const cycleDefaultDuration: ({ startDate, endDate }: Partial<Cycle>) => number;
|
|
15
|
+
export declare const calculateStartDate: ({ cycleDuration, startDate, endDate }: Partial<Cycle>) => boolean;
|
|
16
|
+
export declare const cycleStartDate: ({ cycleDuration, endDate }: Partial<Cycle>) => string;
|
|
7
17
|
export declare const extendCycle: (nodes: HestiaJson<SchemaType>[], cycle: Cycle) => Cycle;
|
|
8
18
|
export declare const impactAssessmentDefaultName: ({ product, country, region, endDate }: Partial<ImpactAssessment>) => string;
|
|
9
19
|
export declare const extendImpactAssessment: (nodes: HestiaJson<SchemaType>[], impactAssessment: ImpactAssessment) => {
|
|
@@ -35,6 +45,7 @@ export declare const extendImpactAssessment: (nodes: HestiaJson<SchemaType>[], i
|
|
|
35
45
|
updated?: string[];
|
|
36
46
|
updatedVersion?: string[];
|
|
37
47
|
aggregated?: boolean;
|
|
48
|
+
aggregatedDataValidated?: boolean;
|
|
38
49
|
aggregatedVersion?: string;
|
|
39
50
|
aggregatedQualityScore?: number;
|
|
40
51
|
aggregatedQualityScoreMax?: number;
|
package/default-values.js
CHANGED
|
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
var _a;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.setDefaultValues = exports.extendSite = exports.siteDefaultName = exports.extendImpactAssessment = exports.impactAssessmentDefaultName = exports.extendCycle = exports.cycleDefaultDuration = exports.calculateCycleDuration = exports.cycleDefaultName = exports.primaryProduct = exports.siteLocationName = void 0;
|
|
15
|
+
exports.setDefaultValues = exports.extendSite = exports.siteDefaultName = exports.extendImpactAssessment = exports.impactAssessmentDefaultName = exports.extendCycle = exports.cycleStartDate = exports.calculateStartDate = exports.cycleDefaultDuration = exports.calculateCycleDuration = exports.parseDate = exports.cycleDefaultName = exports.primaryProduct = exports.siteLocationName = void 0;
|
|
16
16
|
var schema_1 = require("@hestia-earth/schema");
|
|
17
17
|
var utils_1 = require("./utils");
|
|
18
18
|
var findLinkedNode = function (nodes, type, node) {
|
|
@@ -54,23 +54,52 @@ var cycleDefaultName = function (_a, site, product) {
|
|
|
54
54
|
};
|
|
55
55
|
exports.cycleDefaultName = cycleDefaultName;
|
|
56
56
|
var cycleDurationDefault = 365;
|
|
57
|
+
var lastDayOfMonth = function (date) {
|
|
58
|
+
return new Date(new Date(date.getFullYear(), date.getMonth() + 1, 0, 12).toJSON().substring(0, 10));
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Parse date in format `YYYY-MM-DD, YYYY-MM, or YYYY`.
|
|
62
|
+
*
|
|
63
|
+
* @param date The date as a string;
|
|
64
|
+
* @param isStart If the date is a `startDate`, meaning `2000` will be set as `2000-01-01`.
|
|
65
|
+
* If it is an `endDate`, then `2000` will be set as `2000-12-31`.
|
|
66
|
+
*/
|
|
67
|
+
var parseDate = function (date, isStart) {
|
|
68
|
+
if (isStart === void 0) { isStart = true; }
|
|
69
|
+
return date.length === 4
|
|
70
|
+
? new Date("".concat(date, "-").concat(isStart ? '01-01T12:00:00.000Z' : '12-31T12:00:00.000Z'))
|
|
71
|
+
: date.length === 7
|
|
72
|
+
? new Date("".concat(date, "-").concat(isStart
|
|
73
|
+
? '01'
|
|
74
|
+
: new Date(lastDayOfMonth(new Date("".concat(date, "-01T12:00:00.000Z")))).getDate().toString().padStart(2, '0')))
|
|
75
|
+
: new Date("".concat(date, "T12:00:00.000Z"));
|
|
76
|
+
};
|
|
77
|
+
exports.parseDate = parseDate;
|
|
57
78
|
var calculateCycleDuration = function (_a) {
|
|
58
79
|
var cycleDuration = _a.cycleDuration, startDate = _a.startDate, endDate = _a.endDate;
|
|
59
|
-
return
|
|
60
|
-
startDate &&
|
|
61
|
-
endDate &&
|
|
80
|
+
return [!cycleDuration || cycleDuration === cycleDurationDefault, !!startDate, !!endDate].every(Boolean) &&
|
|
62
81
|
new Date(startDate).getTime() < new Date(endDate).getTime();
|
|
63
82
|
};
|
|
64
83
|
exports.calculateCycleDuration = calculateCycleDuration;
|
|
65
84
|
var cycleDefaultDuration = function (_a) {
|
|
66
85
|
var startDate = _a.startDate, endDate = _a.endDate;
|
|
67
|
-
return (0, utils_1.diffInDays)(startDate, endDate);
|
|
86
|
+
return (0, utils_1.diffInDays)((0, exports.parseDate)(startDate, true), (0, exports.parseDate)(endDate, false));
|
|
68
87
|
};
|
|
69
88
|
exports.cycleDefaultDuration = cycleDefaultDuration;
|
|
89
|
+
var calculateStartDate = function (_a) {
|
|
90
|
+
var cycleDuration = _a.cycleDuration, startDate = _a.startDate, endDate = _a.endDate;
|
|
91
|
+
return [!!cycleDuration, !!endDate, !startDate].every(Boolean);
|
|
92
|
+
};
|
|
93
|
+
exports.calculateStartDate = calculateStartDate;
|
|
94
|
+
var cycleStartDate = function (_a) {
|
|
95
|
+
var cycleDuration = _a.cycleDuration, endDate = _a.endDate;
|
|
96
|
+
return (0, utils_1.daysBefore)((0, exports.parseDate)(endDate, false), cycleDuration).toJSON().substring(0, 10);
|
|
97
|
+
};
|
|
98
|
+
exports.cycleStartDate = cycleStartDate;
|
|
70
99
|
var extendCycle = function (nodes, cycle) {
|
|
71
100
|
var product = (0, exports.primaryProduct)(cycle.products);
|
|
72
101
|
var site = findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site);
|
|
73
|
-
return __assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, site, product) }), ((0, exports.calculateCycleDuration)(cycle) ? { cycleDuration: (0, exports.cycleDefaultDuration)(cycle) } : {}));
|
|
102
|
+
return __assign(__assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, site, product) }), ((0, exports.calculateCycleDuration)(cycle) ? { cycleDuration: (0, exports.cycleDefaultDuration)(cycle) } : {})), ((0, exports.calculateStartDate)(cycle) ? { startDate: (0, exports.cycleStartDate)(cycle) } : {}));
|
|
74
103
|
};
|
|
75
104
|
exports.extendCycle = extendCycle;
|
|
76
105
|
var impactAssessmentDefaultName = function (_a) {
|
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare const reduceUndefinedValues: <T>(obj: T, allowNull?: boolean) =>
|
|
|
10
10
|
export declare const ellipsis: (text?: string, maxlength?: number) => string;
|
|
11
11
|
export declare const keyToLabel: (key: string) => string;
|
|
12
12
|
export declare const diffInDays: (date1: Date | string, date2: Date | string) => number;
|
|
13
|
+
export declare const daysBefore: (date?: Date, days?: number) => Date;
|
package/utils.js
CHANGED
|
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.diffInDays = exports.keyToLabel = exports.ellipsis = exports.reduceUndefinedValues = exports.nonEmptyNode = exports.nonEmptyValue = exports.isEmpty = exports.isNumber = exports.isBoolean = exports.isIri = exports.isExpandable = exports.omit = void 0;
|
|
14
|
+
exports.daysBefore = exports.diffInDays = exports.keyToLabel = exports.ellipsis = exports.reduceUndefinedValues = exports.nonEmptyNode = exports.nonEmptyValue = exports.isEmpty = exports.isNumber = exports.isBoolean = exports.isIri = exports.isExpandable = exports.omit = void 0;
|
|
15
15
|
var unset = require('lodash.unset');
|
|
16
16
|
var omit = function (data, keys) {
|
|
17
17
|
var obj = __assign({}, data);
|
|
@@ -80,3 +80,11 @@ var diffInDays = function (date1, date2) {
|
|
|
80
80
|
return Math.abs(Math.round((new Date(date2).getTime() - new Date(date1).getTime()) / (24 * 60 * 60 * 1000)));
|
|
81
81
|
};
|
|
82
82
|
exports.diffInDays = diffInDays;
|
|
83
|
+
var daysBefore = function (date, days) {
|
|
84
|
+
if (date === void 0) { date = new Date(); }
|
|
85
|
+
if (days === void 0) { days = 1; }
|
|
86
|
+
var newDate = new Date(date);
|
|
87
|
+
newDate.setDate(newDate.getDate() - days);
|
|
88
|
+
return newDate;
|
|
89
|
+
};
|
|
90
|
+
exports.daysBefore = daysBefore;
|