@hestia-earth/schema-validation 32.1.1 → 32.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/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Ajv, SchemaValidateFunction } from 'ajv';
|
|
2
|
+
export declare const isFutureDate: (date: string) => boolean;
|
|
2
3
|
export declare const isValidDate: (date: string, withTime?: boolean) => boolean;
|
|
3
4
|
export declare const keyword = "datePattern";
|
|
4
5
|
export declare const validate: SchemaValidateFunction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.init = exports.validate = exports.keyword = exports.isValidDate = void 0;
|
|
3
|
+
exports.init = exports.validate = exports.keyword = exports.isValidDate = exports.isFutureDate = void 0;
|
|
4
4
|
var formatDate = function (date) { return new Date("".concat(new Date(date).toJSON().substring(0, 10), "T12:00:00.000Z")); };
|
|
5
5
|
/**
|
|
6
6
|
* JavaScript does a lenient parsing of dates, so even `2000-30-30` will return a date.
|
|
@@ -15,11 +15,14 @@ var isValidDateRange = function (value) {
|
|
|
15
15
|
var month = values[1] || 1;
|
|
16
16
|
var day = values[2] || 1;
|
|
17
17
|
var date = new Date(year, month - 1, day, 12); // Months are 0-indexed
|
|
18
|
-
return
|
|
19
|
-
date.getFullYear() === year
|
|
20
|
-
date.getMonth() === month - 1
|
|
21
|
-
date.getDate() === day
|
|
18
|
+
return [
|
|
19
|
+
date.getFullYear() === year,
|
|
20
|
+
date.getMonth() === month - 1,
|
|
21
|
+
date.getDate() === day
|
|
22
|
+
].every(Boolean);
|
|
22
23
|
};
|
|
24
|
+
var isFutureDate = function (date) { return formatDate(date) > formatDate(new Date()); };
|
|
25
|
+
exports.isFutureDate = isFutureDate;
|
|
23
26
|
var isValidDate = function (date, withTime) {
|
|
24
27
|
if (withTime === void 0) { withTime = true; }
|
|
25
28
|
return (date.length <= 10 || withTime) && isFinite(new Date(date).getTime()) && isValidDateRange(date);
|
|
@@ -31,7 +34,15 @@ var validate = function (_schema, value, _parentSchema, dataPath) {
|
|
|
31
34
|
var errors = values
|
|
32
35
|
.map(function (v, index) {
|
|
33
36
|
return (0, exports.isValidDate)(v, false)
|
|
34
|
-
?
|
|
37
|
+
? (0, exports.isFutureDate)(v)
|
|
38
|
+
? {
|
|
39
|
+
dataPath: "".concat(dataPath).concat(Array.isArray(value) ? "[".concat(index, "]") : ''),
|
|
40
|
+
keyword: exports.keyword,
|
|
41
|
+
schemaPath: '#/invalid',
|
|
42
|
+
message: 'date cannot be in the future',
|
|
43
|
+
params: {}
|
|
44
|
+
}
|
|
45
|
+
: null
|
|
35
46
|
: {
|
|
36
47
|
dataPath: "".concat(dataPath).concat(Array.isArray(value) ? "[".concat(index, "]") : ''),
|
|
37
48
|
keyword: exports.keyword,
|
|
@@ -8,7 +8,15 @@ var validate = function (_schema, value, _parentSchema, dataPath) {
|
|
|
8
8
|
var errors = values
|
|
9
9
|
.map(function (v, index) {
|
|
10
10
|
return (0, datePattern_1.isValidDate)(v)
|
|
11
|
-
?
|
|
11
|
+
? (0, datePattern_1.isFutureDate)(v)
|
|
12
|
+
? {
|
|
13
|
+
dataPath: "".concat(dataPath).concat(Array.isArray(value) ? "[".concat(index, "]") : ''),
|
|
14
|
+
keyword: exports.keyword,
|
|
15
|
+
schemaPath: '#/invalid',
|
|
16
|
+
message: 'date cannot be in the future',
|
|
17
|
+
params: {}
|
|
18
|
+
}
|
|
19
|
+
: null
|
|
12
20
|
: {
|
|
13
21
|
dataPath: "".concat(dataPath).concat(Array.isArray(value) ? "[".concat(index, "]") : ''),
|
|
14
22
|
keyword: exports.keyword,
|