@hestia-earth/schema-convert 27.2.0 → 28.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Hestia Schema Converter
1
+ # HESTIA Schema Converter
2
2
 
3
- Module to convert CSV to JSON or JSON to CSV following Hestia's Schema
3
+ Module to convert CSV to JSON or JSON to CSV following HESTIA's Schema
4
4
 
5
5
  ## Install
6
6
 
@@ -2,18 +2,6 @@ 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
- * 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;
17
5
  export declare const extendCycle: (nodes: HestiaJson<SchemaType>[], cycle: Cycle) => Cycle;
18
6
  export declare const impactAssessmentDefaultName: ({ product, country, region, endDate }: Partial<ImpactAssessment>) => string;
19
7
  export declare const extendImpactAssessment: (nodes: HestiaJson<SchemaType>[], impactAssessment: ImpactAssessment) => {
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.cycleStartDate = exports.calculateStartDate = exports.cycleDefaultDuration = exports.calculateCycleDuration = exports.parseDate = exports.cycleDefaultName = exports.primaryProduct = exports.siteLocationName = void 0;
15
+ exports.setDefaultValues = exports.extendSite = exports.siteDefaultName = exports.extendImpactAssessment = exports.impactAssessmentDefaultName = exports.extendCycle = 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) {
@@ -53,53 +53,15 @@ var cycleDefaultName = function (_a, site, product) {
53
53
  return defaultName(product === null || product === void 0 ? void 0 : product.term, site === null || site === void 0 ? void 0 : site.country, site === null || site === void 0 ? void 0 : site.region, endDate, treatment, description);
54
54
  };
55
55
  exports.cycleDefaultName = cycleDefaultName;
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));
56
+ var defaultSiteArea = function (cycle) {
57
+ return (0, utils_1.reduceUndefinedValues)({
58
+ siteArea: cycle.functionalUnit === schema_1.CycleFunctionalUnit['1 ha'] ? cycle.siteArea || 1 : undefined
59
+ });
59
60
  };
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;
78
- var calculateCycleDuration = function (_a) {
79
- var cycleDuration = _a.cycleDuration, startDate = _a.startDate, endDate = _a.endDate;
80
- return [!cycleDuration || cycleDuration === cycleDurationDefault, !!startDate, !!endDate].every(Boolean) &&
81
- new Date(startDate).getTime() < new Date(endDate).getTime();
82
- };
83
- exports.calculateCycleDuration = calculateCycleDuration;
84
- var cycleDefaultDuration = function (_a) {
85
- var startDate = _a.startDate, endDate = _a.endDate;
86
- return (0, utils_1.diffInDays)((0, exports.parseDate)(startDate, true), (0, exports.parseDate)(endDate, false));
87
- };
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;
99
61
  var extendCycle = function (nodes, cycle) {
100
62
  var product = (0, exports.primaryProduct)(cycle.products);
101
63
  var site = findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site);
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) } : {}));
64
+ return __assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, site, product) }), defaultSiteArea(cycle));
103
65
  };
104
66
  exports.extendCycle = extendCycle;
105
67
  var impactAssessmentDefaultName = function (_a) {
package/json.d.ts CHANGED
@@ -39,9 +39,9 @@ export declare const cleanStringValue: (value: string) => string;
39
39
  export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, ignoreInternal: boolean, top?: boolean) => any;
40
40
  export declare const filterEmptyNode: (schemas: definitions, node: any) => boolean;
41
41
  /**
42
- * Convert CSV to Hestia JSON-LD format.
42
+ * Convert CSV to HESTIA JSON-LD format.
43
43
  *
44
- * @param schemas The definitions of the Hestia Schema (`import { loadSchemas } from "@hestia-earth/json-schema"`)
44
+ * @param schemas The definitions of the HESTIA Schema (`import { loadSchemas } from "@hestia-earth/json-schema"`)
45
45
  * @param content The content of the CSV as a string
46
46
  * @returns A list of JSON-LD content.
47
47
  */
package/json.js CHANGED
@@ -576,9 +576,9 @@ var convetToNode = function (schemas) { return function (data) {
576
576
  .filter(function (node) { return (0, exports.filterEmptyNode)(schemas, node); });
577
577
  }; };
578
578
  /**
579
- * Convert CSV to Hestia JSON-LD format.
579
+ * Convert CSV to HESTIA JSON-LD format.
580
580
  *
581
- * @param schemas The definitions of the Hestia Schema (`import { loadSchemas } from "@hestia-earth/json-schema"`)
581
+ * @param schemas The definitions of the HESTIA Schema (`import { loadSchemas } from "@hestia-earth/json-schema"`)
582
582
  * @param content The content of the CSV as a string
583
583
  * @returns A list of JSON-LD content.
584
584
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "27.2.0",
4
- "description": "Hestia Schema Converters",
3
+ "version": "28.1.0",
4
+ "description": "HESTIA Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "bin": {
package/utils.d.ts CHANGED
@@ -11,3 +11,4 @@ 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
13
  export declare const daysBefore: (date?: Date, days?: number) => Date;
14
+ export declare const daysInYear: (year: number) => 366 | 365;
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.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;
14
+ exports.daysInYear = 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);
@@ -88,3 +88,5 @@ var daysBefore = function (date, days) {
88
88
  return newDate;
89
89
  };
90
90
  exports.daysBefore = daysBefore;
91
+ var daysInYear = function (year) { return ((year % 4 === 0 && year % 100 > 0) || year % 400 === 0 ? 366 : 365); };
92
+ exports.daysInYear = daysInYear;