@hestia-earth/schema-validation 24.2.0 → 25.0.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/package.json +1 -1
- package/validators/geojson.js +39 -4
package/package.json
CHANGED
package/validators/geojson.js
CHANGED
|
@@ -1,23 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
2
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
30
|
exports.init = exports.validate = exports.keyword = void 0;
|
|
4
31
|
var gjv = require("geojson-validation");
|
|
5
32
|
exports.keyword = 'geojson';
|
|
33
|
+
var invalidCoordinatesError = 'invalid coordinates';
|
|
34
|
+
var maxLongitude = 180;
|
|
35
|
+
var maxLatitude = 90;
|
|
36
|
+
gjv.define('Position', function (_a) {
|
|
37
|
+
var _b = __read(_a, 2), longitude = _b[0], latitude = _b[1];
|
|
38
|
+
return [longitude < maxLongitude, longitude > -maxLongitude, latitude < maxLatitude, latitude > -maxLatitude].every(Boolean) || [invalidCoordinatesError];
|
|
39
|
+
});
|
|
6
40
|
var validate = function (_schema, value, _parentSchema, dataPath) {
|
|
7
|
-
var
|
|
41
|
+
var validationErrors = gjv.valid(value, true);
|
|
42
|
+
var isInvalidCoordinates = validationErrors.every(function (error) { return error.includes(invalidCoordinatesError); });
|
|
8
43
|
var errors = [
|
|
9
|
-
|
|
44
|
+
validationErrors.length === 0
|
|
10
45
|
? null
|
|
11
46
|
: {
|
|
12
47
|
dataPath: dataPath,
|
|
13
48
|
keyword: exports.keyword,
|
|
14
49
|
schemaPath: '#/invalid',
|
|
15
50
|
message: 'not a valid GeoJSON',
|
|
16
|
-
params: {}
|
|
51
|
+
params: __assign({}, (isInvalidCoordinates ? { invalidCoordinates: true } : {}))
|
|
17
52
|
}
|
|
18
53
|
].filter(Boolean);
|
|
19
54
|
exports.validate.errors = errors;
|
|
20
|
-
return
|
|
55
|
+
return validationErrors.length === 0;
|
|
21
56
|
};
|
|
22
57
|
exports.validate = validate;
|
|
23
58
|
var init = function (ajv) {
|