@hestia-earth/utils 0.10.30 → 0.10.31

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/array.d.ts CHANGED
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Return list of unique values.
3
+ *
4
+ * @param values List of values
5
+ */
1
6
  export declare const unique: <T>(values: T[]) => T[];
7
+ /**
8
+ * Return an array containing all values that appear in both arrays.
9
+ *
10
+ * @param array1 List of values
11
+ * @param array2 List of values
12
+ */
2
13
  export declare const intersection: <T>(array1: T[], array2: T[]) => T[];
14
+ /**
15
+ * Checks if both arrays are equal.
16
+ *
17
+ * @param array1 List of values
18
+ * @param array2 List of values
19
+ */
3
20
  export declare const isEqual: <T>(array1: T[], array2: T[]) => boolean;
package/dist/array.js CHANGED
@@ -22,12 +22,29 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.isEqual = exports.intersection = exports.unique = void 0;
25
+ /**
26
+ * Return list of unique values.
27
+ *
28
+ * @param values List of values
29
+ */
25
30
  var unique = function (values) {
26
31
  return values.some(function (v) { return typeof v === 'object'; }) ?
27
32
  __spreadArray([], __read(new Set(values.map(function (v) { return JSON.stringify(v); })))).map(function (v) { return JSON.parse(v); }) : __spreadArray([], __read(new Set(values)));
28
33
  };
29
34
  exports.unique = unique;
35
+ /**
36
+ * Return an array containing all values that appear in both arrays.
37
+ *
38
+ * @param array1 List of values
39
+ * @param array2 List of values
40
+ */
30
41
  var intersection = function (array1, array2) { return array1.filter(function (x) { return array2.includes(x); }); };
31
42
  exports.intersection = intersection;
43
+ /**
44
+ * Checks if both arrays are equal.
45
+ *
46
+ * @param array1 List of values
47
+ * @param array2 List of values
48
+ */
32
49
  var isEqual = function (array1, array2) { return JSON.stringify(array1) === JSON.stringify(array2); };
33
50
  exports.isEqual = isEqual;
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /* eslint-disable no-console */
4
5
  var validate_terms_1 = require("../validate-terms");
5
6
  validate_terms_1.run()
6
7
  .then(function (paths) {
package/dist/date.d.ts CHANGED
@@ -2,8 +2,48 @@ export declare const secondMs = 1000;
2
2
  export declare const minuteMs: number;
3
3
  export declare const hourMs: number;
4
4
  export declare const dayMs: number;
5
+ /**
6
+ * Get the difference in days between two dates.
7
+ *
8
+ * @param date1 The left date
9
+ * @param date2 The right date
10
+ *
11
+ * @returns The difference between date1 and date2 in days (rounded).
12
+ */
5
13
  export declare const diffInDays: (date1: Date | string, date2: Date | string) => number;
14
+ /**
15
+ * Get the difference in years between two dates.
16
+ *
17
+ * @param date1 The left date
18
+ * @param date2 The right date
19
+ *
20
+ * @returns The difference between date1 and date2 in years (precision: 1).
21
+ */
6
22
  export declare const diffInYears: (date1: Date | string, date2: Date | string) => number;
23
+ /**
24
+ * Remove days on the date.
25
+ *
26
+ * @param date The date.
27
+ * @param days How many days to remove. Note: you can use a negative number to add days.
28
+ *
29
+ * @returns New date.
30
+ */
7
31
  export declare const daysBefore: (date?: Date, days?: number) => Date;
32
+ /**
33
+ * Remove hours on the date.
34
+ *
35
+ * @param date The date.
36
+ * @param minutes How many hours to remove. Note: you can use a negative number to add hours.
37
+ *
38
+ * @returns New date.
39
+ */
8
40
  export declare const hoursBefore: (date?: Date, hours?: number) => Date;
41
+ /**
42
+ * Remove minutes on the date.
43
+ *
44
+ * @param date The date.
45
+ * @param minutes How many minutes to remove. Note: you can use a negative number to add minutes.
46
+ *
47
+ * @returns New date.
48
+ */
9
49
  export declare const minutesBefore: (date?: Date, minutes?: number) => Date;
package/dist/date.js CHANGED
@@ -6,14 +6,38 @@ exports.minuteMs = 60 * exports.secondMs;
6
6
  exports.hourMs = 60 * exports.minuteMs;
7
7
  exports.dayMs = 24 * exports.hourMs;
8
8
  var year = 365.2425;
9
+ /**
10
+ * Get the difference in days between two dates.
11
+ *
12
+ * @param date1 The left date
13
+ * @param date2 The right date
14
+ *
15
+ * @returns The difference between date1 and date2 in days (rounded).
16
+ */
9
17
  var diffInDays = function (date1, date2) {
10
18
  return Math.abs(Math.round((new Date(date2).getTime() - new Date(date1).getTime()) / exports.dayMs));
11
19
  };
12
20
  exports.diffInDays = diffInDays;
21
+ /**
22
+ * Get the difference in years between two dates.
23
+ *
24
+ * @param date1 The left date
25
+ * @param date2 The right date
26
+ *
27
+ * @returns The difference between date1 and date2 in years (precision: 1).
28
+ */
13
29
  var diffInYears = function (date1, date2) {
14
30
  return Math.round((exports.diffInDays(date1, date2) / year) * 10) / 10;
15
31
  };
16
32
  exports.diffInYears = diffInYears;
33
+ /**
34
+ * Remove days on the date.
35
+ *
36
+ * @param date The date.
37
+ * @param days How many days to remove. Note: you can use a negative number to add days.
38
+ *
39
+ * @returns New date.
40
+ */
17
41
  var daysBefore = function (date, days) {
18
42
  if (date === void 0) { date = new Date(); }
19
43
  if (days === void 0) { days = 1; }
@@ -22,6 +46,14 @@ var daysBefore = function (date, days) {
22
46
  return newDate;
23
47
  };
24
48
  exports.daysBefore = daysBefore;
49
+ /**
50
+ * Remove hours on the date.
51
+ *
52
+ * @param date The date.
53
+ * @param minutes How many hours to remove. Note: you can use a negative number to add hours.
54
+ *
55
+ * @returns New date.
56
+ */
25
57
  var hoursBefore = function (date, hours) {
26
58
  if (date === void 0) { date = new Date(); }
27
59
  if (hours === void 0) { hours = 1; }
@@ -30,6 +62,14 @@ var hoursBefore = function (date, hours) {
30
62
  return newDate;
31
63
  };
32
64
  exports.hoursBefore = hoursBefore;
65
+ /**
66
+ * Remove minutes on the date.
67
+ *
68
+ * @param date The date.
69
+ * @param minutes How many minutes to remove. Note: you can use a negative number to add minutes.
70
+ *
71
+ * @returns New date.
72
+ */
33
73
  var minutesBefore = function (date, minutes) {
34
74
  if (date === void 0) { date = new Date(); }
35
75
  if (minutes === void 0) { minutes = 1; }
package/dist/delta.d.ts CHANGED
@@ -8,5 +8,15 @@ declare type deltaTypeMapping = {
8
8
  export declare const customDeltaFuncs: {
9
9
  percent: (recalculated: number, original: number) => number;
10
10
  };
11
+ /**
12
+ * Calculate the delta between 2 values.
13
+ *
14
+ * @param value
15
+ * @param originalValue
16
+ * @param displayType
17
+ * @param mapping
18
+ * @param termId If calculating delta for a specific Term.
19
+ * @returns
20
+ */
11
21
  export declare const delta: (value: any, originalValue: any, displayType?: DeltaDisplayType, mapping?: deltaTypeMapping, termId?: string) => number;
12
22
  export {};
package/dist/delta.js CHANGED
@@ -35,6 +35,7 @@ var calculatePercentDeltaConditions = (_b = {},
35
35
  _b);
36
36
  var calculatePercentDeltaResult = (_c = {},
37
37
  _c[PercentDeltaConditions.recalculated0] = function (original, recalculated) { return (recalculated - original) / (original + 1); },
38
+ // Always considered an error so deliberately exceed SUCCESS_CRITERION_MAX_DELTA_PERCENT
38
39
  _c[PercentDeltaConditions.original0] = function (original, recalculated) { return Math.sign(recalculated - original); },
39
40
  _c.default = function (original, recalculated) { return (recalculated - original) / original; },
40
41
  _c);
@@ -47,6 +48,16 @@ var calculatePercentDelta = function (recalculated, original) {
47
48
  exports.customDeltaFuncs = (_d = {},
48
49
  _d[DeltaDisplayType.percent] = calculatePercentDelta,
49
50
  _d);
51
+ /**
52
+ * Calculate the delta between 2 values.
53
+ *
54
+ * @param value
55
+ * @param originalValue
56
+ * @param displayType
57
+ * @param mapping
58
+ * @param termId If calculating delta for a specific Term.
59
+ * @returns
60
+ */
50
61
  var delta = function (value, originalValue, displayType, mapping, termId) {
51
62
  if (displayType === void 0) { displayType = DeltaDisplayType.percent; }
52
63
  var vvalue = roundValue(term_1.propertyValue(value, termId));
package/dist/number.d.ts CHANGED
@@ -1,5 +1,23 @@
1
+ /**
2
+ * Check if the value is a number.
3
+ *
4
+ * @param n Number as string or number
5
+ * @returns true if the value is a number, false otherwise
6
+ */
1
7
  export declare const isNumber: (n: string | number) => boolean;
8
+ /**
9
+ * Returns a number with significant figures.
10
+ * Example: 3645.875 with 3 significant figures will return 3650.
11
+ *
12
+ * @param n The value
13
+ * @param precision The number of significant figures
14
+ */
2
15
  export declare const toPrecision: (n: number, precision?: number) => number;
16
+ /**
17
+ * Returns the number formatted with commas every thousand.
18
+ *
19
+ * @param n The value
20
+ */
3
21
  export declare const toComma: (n: number) => string;
4
22
  export declare enum ConvertUnits {
5
23
  m3 = "m3",
@@ -45,4 +63,14 @@ export declare const converters: {
45
63
  [toUnit in ConvertUnits]?: (value: number, args: IConvertArgs) => number;
46
64
  };
47
65
  };
66
+ /**
67
+ * Converts a value of unit into a different unit.
68
+ * Depending on the destination unit, additional arguments might be provided.
69
+ *
70
+ * @param n The value to convert, usually a float or an integer.
71
+ * @param fromUnit The unit the value is specified in.
72
+ * @param toUnit The unit the converted value should be.
73
+ * @param args Optional arguments to provide depending on the conversion.
74
+ * @returns The converted value.
75
+ */
48
76
  export declare const convertValue: (n: number, fromUnit: ConvertUnits, toUnit: ConvertUnits, args?: IConvertArgs) => number;
package/dist/number.js CHANGED
@@ -18,6 +18,12 @@ var __read = (this && this.__read) || function (o, n) {
18
18
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.convertValue = exports.converters = exports.ConvertUnits = exports.toComma = exports.toPrecision = exports.isNumber = void 0;
21
+ /**
22
+ * Check if the value is a number.
23
+ *
24
+ * @param n Number as string or number
25
+ * @returns true if the value is a number, false otherwise
26
+ */
21
27
  var isNumber = function (n) {
22
28
  var _a;
23
29
  return [
@@ -27,13 +33,29 @@ var isNumber = function (n) {
27
33
  ].every(Boolean);
28
34
  };
29
35
  exports.isNumber = isNumber;
36
+ /**
37
+ * Returns a number with significant figures.
38
+ * Example: 3645.875 with 3 significant figures will return 3650.
39
+ *
40
+ * @param n The value
41
+ * @param precision The number of significant figures
42
+ */
30
43
  var toPrecision = function (n, precision) {
31
44
  if (precision === void 0) { precision = 3; }
32
45
  var mult = Math.pow(10, precision - Math.floor(Math.log(n < 0 ? -n : n) / Math.LN10) - 1);
33
- var multiplier = +("" + mult).replace(/[0]([1-9])\1+/g, function (v) { return "" + (+(v.substring(0, 1)) + 1); });
46
+ var multiplier = Math.max(
47
+ // handle floating errors like 0.00009999999999999999
48
+ +("" + mult).replace(/[0]([1-9])\1+/g, function (v) { return "" + (+(v.substring(0, 1)) + 1); }),
49
+ // dividing by 0.00001 will give floating point error
50
+ 0.0001);
34
51
  return n === 0 ? 0 : Math.round(n * multiplier) / multiplier;
35
52
  };
36
53
  exports.toPrecision = toPrecision;
54
+ /**
55
+ * Returns the number formatted with commas every thousand.
56
+ *
57
+ * @param n The value
58
+ */
37
59
  var toComma = function (n) {
38
60
  var _a = __read(n.toString().split('.'), 2), numberPart = _a[0], decimalPart = _a[1];
39
61
  var thousands = /\B(?=(\d{3})+(?!\d))/g;
@@ -159,6 +181,16 @@ exports.converters = (_a = {},
159
181
  _z[ConvertUnits.kgNH4N] = function (value) { return value * (N + H * 4) / N; },
160
182
  _z),
161
183
  _a);
184
+ /**
185
+ * Converts a value of unit into a different unit.
186
+ * Depending on the destination unit, additional arguments might be provided.
187
+ *
188
+ * @param n The value to convert, usually a float or an integer.
189
+ * @param fromUnit The unit the value is specified in.
190
+ * @param toUnit The unit the converted value should be.
191
+ * @param args Optional arguments to provide depending on the conversion.
192
+ * @returns The converted value.
193
+ */
162
194
  var convertValue = function (n, fromUnit, toUnit, args) {
163
195
  return exports.converters[fromUnit][toUnit](n, args);
164
196
  };
package/dist/string.d.ts CHANGED
@@ -1,4 +1,22 @@
1
+ /**
2
+ * Trims the string to a certain max length and replace with `...`.
3
+ *
4
+ * @param text The text to ellipsize.
5
+ * @param maxlength The maximum length of the text (including `...`).
6
+ * @returns
7
+ */
1
8
  export declare const ellipsis: (text?: string, maxlength?: number) => string;
2
9
  export declare const keyToLabel: (key: string) => string;
10
+ /**
11
+ * Convert a Term ID into a dash string. Use it to generate link to documentation.
12
+ *
13
+ * @param value The original value.
14
+ * @returns A dash case version of the value.
15
+ */
3
16
  export declare const toDashCase: (value?: string) => string;
17
+ /**
18
+ * Returns current date in YYYY-MM-DD format.
19
+ *
20
+ * @returns Date as a string.
21
+ */
4
22
  export declare const now: () => string;
package/dist/string.js CHANGED
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.now = exports.toDashCase = exports.keyToLabel = exports.ellipsis = void 0;
4
+ /**
5
+ * Trims the string to a certain max length and replace with `...`.
6
+ *
7
+ * @param text The text to ellipsize.
8
+ * @param maxlength The maximum length of the text (including `...`).
9
+ * @returns
10
+ */
4
11
  var ellipsis = function (text, maxlength) {
5
12
  if (text === void 0) { text = ''; }
6
13
  if (maxlength === void 0) { maxlength = 20; }
@@ -11,10 +18,18 @@ var keyToLabel = function (key) {
11
18
  return "" + key[0].toUpperCase() + key.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/([_])([a-zA-Z])/g, function (g) { return " " + g[1].toUpperCase(); }).substring(1);
12
19
  };
13
20
  exports.keyToLabel = keyToLabel;
21
+ /**
22
+ * Convert a Term ID into a dash string. Use it to generate link to documentation.
23
+ *
24
+ * @param value The original value.
25
+ * @returns A dash case version of the value.
26
+ */
14
27
  var toDashCase = function (value) {
15
28
  return value
16
29
  ? value
30
+ // handle dates followed by capital letter
17
31
  .replace(/([\d]{4})([A-Z]{1})/g, function (g) { return g.substring(0, 4) + "-" + g[4].toLowerCase(); })
32
+ // handle molecules
18
33
  .replace(/([\d]{1}[A-Z]{1}?)([A-Z]{1})/g, function (_g) {
19
34
  var args = [];
20
35
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -22,11 +37,19 @@ var toDashCase = function (value) {
22
37
  }
23
38
  return (args[0] + "-" + args[1]).toLowerCase();
24
39
  })
40
+ // handle all capital letters
25
41
  .replace(/([A-Z])/g, function (g) { return "-" + g[0].toLowerCase(); })
42
+ // handle years
26
43
  .replace(/([0-9]{4})/g, function (g) { return "-" + g; })
44
+ // handle underscores
27
45
  .replace(/[\_\.]/g, '-')
28
46
  : null;
29
47
  };
30
48
  exports.toDashCase = toDashCase;
49
+ /**
50
+ * Returns current date in YYYY-MM-DD format.
51
+ *
52
+ * @returns Date as a string.
53
+ */
31
54
  var now = function () { return new Date().toJSON().substring(0, 10); };
32
55
  exports.now = now;
package/dist/term.d.ts CHANGED
@@ -1,3 +1,16 @@
1
1
  export declare const arrayValue: (values?: any[], isAverage?: boolean) => number;
2
+ /**
3
+ * Calculate the final value of a property.
4
+ *
5
+ * @param value The value as an array or a string/number.
6
+ * @param termId Optional - us if the term should handle an array in a specific way.
7
+ * @returns The value as a number.
8
+ */
2
9
  export declare const propertyValue: (value: string | number | ((string | number)[]), termId?: string) => number;
10
+ /**
11
+ * Checks if the value is empty or if the property value is empty.
12
+ *
13
+ * @param value
14
+ * @returns
15
+ */
3
16
  export declare const emptyValue: (value: any, termId?: string) => boolean;
package/dist/term.js CHANGED
@@ -11,6 +11,13 @@ var arrayValue = function (values, isAverage) {
11
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);
12
12
  };
13
13
  exports.arrayValue = arrayValue;
14
+ /**
15
+ * Calculate the final value of a property.
16
+ *
17
+ * @param value The value as an array or a string/number.
18
+ * @param termId Optional - us if the term should handle an array in a specific way.
19
+ * @returns The value as a number.
20
+ */
14
21
  var propertyValue = function (value, termId) {
15
22
  return typeof value === 'undefined' || value === null
16
23
  ? null
@@ -19,5 +26,11 @@ var propertyValue = function (value, termId) {
19
26
  : parseFloat("" + value);
20
27
  };
21
28
  exports.propertyValue = propertyValue;
29
+ /**
30
+ * Checks if the value is empty or if the property value is empty.
31
+ *
32
+ * @param value
33
+ * @returns
34
+ */
22
35
  var emptyValue = function (value, termId) { return utils_1.isEmpty(value) || isNaN(exports.propertyValue(value, termId)); };
23
36
  exports.emptyValue = emptyValue;
@@ -2,6 +2,12 @@ declare class Term {
2
2
  '@id': string;
3
3
  name: string;
4
4
  }
5
+ /**
6
+ * Validate a list of Terms.
7
+ *
8
+ * @param terms The list of Terms to validate.
9
+ * @returns The list of ids/names that could not be found (invalid).
10
+ */
5
11
  export declare const validateTerms: (terms: Term[]) => Promise<(string | true)[]>;
6
12
  export declare const run: () => Promise<string[]>;
7
13
  export {};
@@ -66,7 +66,7 @@ var API_URL = process.env.API_URL;
66
66
  var _a = __read(process.argv.slice(2), 1), folder = _a[0];
67
67
  var readdir = fs_1.promises.readdir, lstat = fs_1.promises.lstat, readFile = fs_1.promises.readFile;
68
68
  var encoding = 'utf8';
69
- var Term = (function () {
69
+ var Term = /** @class */ (function () {
70
70
  function Term() {
71
71
  }
72
72
  return Term;
@@ -91,26 +91,26 @@ var recursiveFiles = function (directory) { return __awaiter(void 0, void 0, voi
91
91
  switch (_c.label) {
92
92
  case 0:
93
93
  _b = (_a = Promise).all;
94
- return [4, readdir(directory)];
95
- case 1: return [4, _b.apply(_a, [(_c.sent()).map(function (entry) { return __awaiter(void 0, void 0, void 0, function () {
94
+ return [4 /*yield*/, readdir(directory)];
95
+ case 1: return [4 /*yield*/, _b.apply(_a, [(_c.sent()).map(function (entry) { return __awaiter(void 0, void 0, void 0, function () {
96
96
  var _a;
97
97
  return __generator(this, function (_b) {
98
98
  switch (_b.label) {
99
- case 0: return [4, lstat(path_1.join(directory, entry))];
99
+ case 0: return [4 /*yield*/, lstat(path_1.join(directory, entry))];
100
100
  case 1:
101
- if (!(_b.sent()).isDirectory()) return [3, 3];
102
- return [4, recursiveFiles(path_1.join(directory, entry))];
101
+ if (!(_b.sent()).isDirectory()) return [3 /*break*/, 3];
102
+ return [4 /*yield*/, recursiveFiles(path_1.join(directory, entry))];
103
103
  case 2:
104
104
  _a = _b.sent();
105
- return [3, 4];
105
+ return [3 /*break*/, 4];
106
106
  case 3:
107
107
  _a = (path_1.join(directory, entry).endsWith('.jsonld') ? [path_1.join(directory, entry)] : []);
108
108
  _b.label = 4;
109
- case 4: return [2, _a];
109
+ case 4: return [2 /*return*/, _a];
110
110
  }
111
111
  });
112
112
  }); })])];
113
- case 2: return [2, (_c.sent()).flat()];
113
+ case 2: return [2 /*return*/, (_c.sent()).flat()];
114
114
  }
115
115
  });
116
116
  }); };
@@ -124,6 +124,7 @@ var getAllTerms = function (data) {
124
124
  })
125
125
  .filter(function (term) { return (!!term) && (term['@type'] === 'Term') && (!!term['@id'] || !!term.name); });
126
126
  };
127
+ // search is limited to 1000 parameters
127
128
  var searchLimit = 500;
128
129
  var searchTerms = function (terms) { return __awaiter(void 0, void 0, void 0, function () {
129
130
  var searchedTerms, results, _a, _b, _c;
@@ -131,8 +132,8 @@ var searchTerms = function (terms) { return __awaiter(void 0, void 0, void 0, fu
131
132
  switch (_d.label) {
132
133
  case 0:
133
134
  searchedTerms = terms.slice(0, searchLimit);
134
- if (!searchedTerms.length) return [3, 2];
135
- return [4, search({
135
+ if (!searchedTerms.length) return [3 /*break*/, 2];
136
+ return [4 /*yield*/, search({
136
137
  limit: searchLimit,
137
138
  fields: ['@id', 'name'],
138
139
  query: {
@@ -151,33 +152,39 @@ var searchTerms = function (terms) { return __awaiter(void 0, void 0, void 0, fu
151
152
  })];
152
153
  case 1:
153
154
  _a = _d.sent();
154
- return [3, 3];
155
+ return [3 /*break*/, 3];
155
156
  case 2:
156
157
  _a = { results: [] };
157
158
  _d.label = 3;
158
159
  case 3:
159
160
  results = (_a).results;
160
161
  _b = [__spreadArray([], __read(results))];
161
- if (!(terms.length > searchLimit)) return [3, 5];
162
- return [4, searchTerms(terms.slice(searchLimit))];
162
+ if (!(terms.length > searchLimit)) return [3 /*break*/, 5];
163
+ return [4 /*yield*/, searchTerms(terms.slice(searchLimit))];
163
164
  case 4:
164
165
  _c = _d.sent();
165
- return [3, 6];
166
+ return [3 /*break*/, 6];
166
167
  case 5:
167
168
  _c = [];
168
169
  _d.label = 6;
169
- case 6: return [2, __spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c)])]))];
170
+ case 6: return [2 /*return*/, __spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c)])]))];
170
171
  }
171
172
  });
172
173
  }); };
174
+ /**
175
+ * Validate a list of Terms.
176
+ *
177
+ * @param terms The list of Terms to validate.
178
+ * @returns The list of ids/names that could not be found (invalid).
179
+ */
173
180
  var validateTerms = function (terms) { return __awaiter(void 0, void 0, void 0, function () {
174
181
  var results;
175
182
  return __generator(this, function (_a) {
176
183
  switch (_a.label) {
177
- case 0: return [4, searchTerms(terms)];
184
+ case 0: return [4 /*yield*/, searchTerms(terms)];
178
185
  case 1:
179
186
  results = _a.sent();
180
- return [2, terms.map(function (_a) {
187
+ return [2 /*return*/, terms.map(function (_a) {
181
188
  var id = _a["@id"], name = _a.name;
182
189
  var exists = results.find(function (res) { return res['@id'] === id || res.name === name; });
183
190
  return exists ? true : id || name;
@@ -209,8 +216,8 @@ var loadFile = function (filepath) { return __awaiter(void 0, void 0, void 0, fu
209
216
  };
210
217
  _a = getAllTerms;
211
218
  _c = (_b = JSON).parse;
212
- return [4, readFile(filepath, encoding)];
213
- case 1: return [2, (_d.terms = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]),
219
+ return [4 /*yield*/, readFile(filepath, encoding)];
220
+ case 1: return [2 /*return*/, (_d.terms = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]),
214
221
  _d)];
215
222
  }
216
223
  });
@@ -219,17 +226,17 @@ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
219
226
  var filepaths, fileData, allTerms, existingTerms, results, missingFiles;
220
227
  return __generator(this, function (_a) {
221
228
  switch (_a.label) {
222
- case 0: return [4, recursiveFiles(folder)];
229
+ case 0: return [4 /*yield*/, recursiveFiles(folder)];
223
230
  case 1:
224
231
  filepaths = _a.sent();
225
- return [4, Promise.all(filepaths.map(loadFile))];
232
+ return [4 /*yield*/, Promise.all(filepaths.map(loadFile))];
226
233
  case 2:
227
234
  fileData = _a.sent();
228
235
  allTerms = array_1.unique(fileData.flatMap(function (_a) {
229
236
  var terms = _a.terms;
230
237
  return terms;
231
238
  }));
232
- return [4, searchTerms(allTerms)];
239
+ return [4 /*yield*/, searchTerms(allTerms)];
233
240
  case 3:
234
241
  existingTerms = _a.sent();
235
242
  results = fileData.map(validateFile(existingTerms)).filter(Boolean);
@@ -243,7 +250,7 @@ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
243
250
  return "- " + filepath + ": " + missing.join(', ');
244
251
  }).join('\n\t') + "\n ").trim());
245
252
  }
246
- return [2, filepaths];
253
+ return [2 /*return*/, filepaths];
247
254
  }
248
255
  });
249
256
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/utils",
3
- "version": "0.10.30",
3
+ "version": "0.10.31",
4
4
  "description": "Hestia Utils library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "javascript",
26
26
  "typescript"
27
27
  ],
28
- "author": "Guillaume Royer <guillaumeroyer@gmail.com>",
29
- "license": "GPL-3.0-or-later",
28
+ "author": "Guillaume Royer <guillaume@hestia.earth>",
29
+ "license": "MIT",
30
30
  "bugs": {
31
31
  "url": "https://gitlab.com/hestia-earth/hestia-utils/issues"
32
32
  },