@cfworker/json-schema 4.0.3 → 4.1.1
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/commonjs/format.d.ts +1 -2
- package/dist/commonjs/format.js +2 -13
- package/dist/commonjs/validate.js +2 -2
- package/dist/esm/format.d.ts +1 -2
- package/dist/esm/format.js +1 -12
- package/dist/esm/validate.js +3 -3
- package/package.json +5 -5
- package/src/format.ts +12 -20
- package/src/validate.ts +3 -3
- package/src/deep-compare-strict.js +0 -39
- package/src/dereference.js +0 -148
- package/src/format.js +0 -137
- package/src/index.js +0 -8
- package/src/pointer.js +0 -6
- package/src/types.js +0 -6
- package/src/ucs2-length.js +0 -17
- package/src/validate.js +0 -1099
- package/src/validator.js +0 -29
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const fastFormat: Record<string, (s: string) => boolean>;
|
|
1
|
+
export declare const format: Record<string, (s: string) => boolean>;
|
package/dist/commonjs/format.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.format = void 0;
|
|
4
4
|
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
5
5
|
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6
6
|
const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
@@ -12,10 +12,6 @@ const UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
|
12
12
|
const JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
13
13
|
const JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
14
14
|
const RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
15
|
-
const FASTDATE = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
|
|
16
|
-
const FASTTIME = /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
17
|
-
const FASTDATETIME = /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i;
|
|
18
|
-
const FASTURIREFERENCE = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i;
|
|
19
15
|
const EMAIL = (input) => {
|
|
20
16
|
if (input[0] === '"')
|
|
21
17
|
return false;
|
|
@@ -45,7 +41,7 @@ const DURATION = (input) => input.length > 1 &&
|
|
|
45
41
|
function bind(r) {
|
|
46
42
|
return r.test.bind(r);
|
|
47
43
|
}
|
|
48
|
-
exports.
|
|
44
|
+
exports.format = {
|
|
49
45
|
date,
|
|
50
46
|
time: time.bind(undefined, false),
|
|
51
47
|
'date-time': date_time,
|
|
@@ -64,13 +60,6 @@ exports.fullFormat = {
|
|
|
64
60
|
'json-pointer-uri-fragment': bind(JSON_POINTER_URI_FRAGMENT),
|
|
65
61
|
'relative-json-pointer': bind(RELATIVE_JSON_POINTER)
|
|
66
62
|
};
|
|
67
|
-
exports.fastFormat = {
|
|
68
|
-
...exports.fullFormat,
|
|
69
|
-
date: bind(FASTDATE),
|
|
70
|
-
time: bind(FASTTIME),
|
|
71
|
-
'date-time': bind(FASTDATETIME),
|
|
72
|
-
'uri-reference': bind(FASTURIREFERENCE)
|
|
73
|
-
};
|
|
74
63
|
function isLeapYear(year) {
|
|
75
64
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
76
65
|
}
|
|
@@ -791,8 +791,8 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
791
791
|
});
|
|
792
792
|
}
|
|
793
793
|
if ($format !== undefined &&
|
|
794
|
-
format_js_1.
|
|
795
|
-
!format_js_1.
|
|
794
|
+
format_js_1.format[$format] &&
|
|
795
|
+
!format_js_1.format[$format](instance)) {
|
|
796
796
|
errors.push({
|
|
797
797
|
instanceLocation,
|
|
798
798
|
keyword: 'format',
|
package/dist/esm/format.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const fastFormat: Record<string, (s: string) => boolean>;
|
|
1
|
+
export declare const format: Record<string, (s: string) => boolean>;
|
package/dist/esm/format.js
CHANGED
|
@@ -9,10 +9,6 @@ const UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
|
9
9
|
const JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
10
10
|
const JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
11
11
|
const RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
12
|
-
const FASTDATE = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
|
|
13
|
-
const FASTTIME = /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
14
|
-
const FASTDATETIME = /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i;
|
|
15
|
-
const FASTURIREFERENCE = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i;
|
|
16
12
|
const EMAIL = (input) => {
|
|
17
13
|
if (input[0] === '"')
|
|
18
14
|
return false;
|
|
@@ -42,7 +38,7 @@ const DURATION = (input) => input.length > 1 &&
|
|
|
42
38
|
function bind(r) {
|
|
43
39
|
return r.test.bind(r);
|
|
44
40
|
}
|
|
45
|
-
export const
|
|
41
|
+
export const format = {
|
|
46
42
|
date,
|
|
47
43
|
time: time.bind(undefined, false),
|
|
48
44
|
'date-time': date_time,
|
|
@@ -61,13 +57,6 @@ export const fullFormat = {
|
|
|
61
57
|
'json-pointer-uri-fragment': bind(JSON_POINTER_URI_FRAGMENT),
|
|
62
58
|
'relative-json-pointer': bind(RELATIVE_JSON_POINTER)
|
|
63
59
|
};
|
|
64
|
-
export const fastFormat = {
|
|
65
|
-
...fullFormat,
|
|
66
|
-
date: bind(FASTDATE),
|
|
67
|
-
time: bind(FASTTIME),
|
|
68
|
-
'date-time': bind(FASTDATETIME),
|
|
69
|
-
'uri-reference': bind(FASTURIREFERENCE)
|
|
70
|
-
};
|
|
71
60
|
function isLeapYear(year) {
|
|
72
61
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
73
62
|
}
|
package/dist/esm/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deepCompareStrict } from './deep-compare-strict.js';
|
|
2
2
|
import { dereference } from './dereference.js';
|
|
3
|
-
import {
|
|
3
|
+
import { format } from './format.js';
|
|
4
4
|
import { encodePointer } from './pointer.js';
|
|
5
5
|
import { ucs2length } from './ucs2-length.js';
|
|
6
6
|
export function validate(instance, schema, draft = '2019-09', lookup = dereference(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = '#', schemaLocation = '#', evaluated = Object.create(null)) {
|
|
@@ -788,8 +788,8 @@ export function validate(instance, schema, draft = '2019-09', lookup = dereferen
|
|
|
788
788
|
});
|
|
789
789
|
}
|
|
790
790
|
if ($format !== undefined &&
|
|
791
|
-
|
|
792
|
-
!
|
|
791
|
+
format[$format] &&
|
|
792
|
+
!format[$format](instance)) {
|
|
793
793
|
errors.push({
|
|
794
794
|
instanceLocation,
|
|
795
795
|
keyword: 'format',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfworker/json-schema",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "A JSON schema validator that will run on Cloudflare workers. Supports drafts 4, 7, 2019-09, and 2020-12.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json-schema",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"@types/mocha": "^10.0.10",
|
|
55
55
|
"chai": "^5.1.2",
|
|
56
56
|
"json-schema-test-suite": "git+https://github.com/json-schema-org/JSON-Schema-Test-Suite#76b529f",
|
|
57
|
-
"esbuild": "^0.24.
|
|
58
|
-
"mocha": "^11.0
|
|
59
|
-
"typescript": "^5.7.
|
|
60
|
-
"wrangler": "^3.
|
|
57
|
+
"esbuild": "^0.24.2",
|
|
58
|
+
"mocha": "^11.1.0",
|
|
59
|
+
"typescript": "^5.7.3",
|
|
60
|
+
"wrangler": "^3.107.2"
|
|
61
61
|
},
|
|
62
62
|
"tshy": {
|
|
63
63
|
"exports": {
|
package/src/format.ts
CHANGED
|
@@ -22,17 +22,17 @@ const JSON_POINTER_URI_FRAGMENT =
|
|
|
22
22
|
const RELATIVE_JSON_POINTER =
|
|
23
23
|
/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
24
24
|
|
|
25
|
-
// date: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
26
|
-
const FASTDATE = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
|
|
27
|
-
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
28
|
-
const FASTTIME =
|
|
29
|
-
|
|
30
|
-
const FASTDATETIME =
|
|
31
|
-
|
|
32
|
-
// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
|
|
33
|
-
// const FASTURI = /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i;
|
|
34
|
-
const FASTURIREFERENCE =
|
|
35
|
-
|
|
25
|
+
// // date: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
26
|
+
// const FASTDATE = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
|
|
27
|
+
// // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
28
|
+
// const FASTTIME =
|
|
29
|
+
// /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
30
|
+
// const FASTDATETIME =
|
|
31
|
+
// /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i;
|
|
32
|
+
// // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
|
|
33
|
+
// // const FASTURI = /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i;
|
|
34
|
+
// const FASTURIREFERENCE =
|
|
35
|
+
// /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i;
|
|
36
36
|
|
|
37
37
|
// https://github.com/ExodusMovement/schemasafe/blob/master/src/formats.js
|
|
38
38
|
const EMAIL = (input: string) => {
|
|
@@ -79,7 +79,7 @@ function bind(r: RegExp) {
|
|
|
79
79
|
return r.test.bind(r);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export const
|
|
82
|
+
export const format: Record<string, (s: string) => boolean> = {
|
|
83
83
|
date,
|
|
84
84
|
time: time.bind(undefined, false),
|
|
85
85
|
'date-time': date_time,
|
|
@@ -99,14 +99,6 @@ export const fullFormat: Record<string, (s: string) => boolean> = {
|
|
|
99
99
|
'relative-json-pointer': bind(RELATIVE_JSON_POINTER)
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
export const fastFormat: Record<string, (s: string) => boolean> = {
|
|
103
|
-
...fullFormat,
|
|
104
|
-
date: bind(FASTDATE),
|
|
105
|
-
time: bind(FASTTIME),
|
|
106
|
-
'date-time': bind(FASTDATETIME),
|
|
107
|
-
'uri-reference': bind(FASTURIREFERENCE)
|
|
108
|
-
};
|
|
109
|
-
|
|
110
102
|
function isLeapYear(year: number) {
|
|
111
103
|
// https://tools.ietf.org/html/rfc3339#appendix-C
|
|
112
104
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
package/src/validate.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deepCompareStrict } from './deep-compare-strict.js';
|
|
2
2
|
import { dereference } from './dereference.js';
|
|
3
|
-
import {
|
|
3
|
+
import { format } from './format.js';
|
|
4
4
|
import { encodePointer } from './pointer.js';
|
|
5
5
|
import {
|
|
6
6
|
InstanceType,
|
|
@@ -1152,8 +1152,8 @@ export function validate(
|
|
|
1152
1152
|
}
|
|
1153
1153
|
if (
|
|
1154
1154
|
$format !== undefined &&
|
|
1155
|
-
|
|
1156
|
-
!
|
|
1155
|
+
format[$format] &&
|
|
1156
|
+
!format[$format](instance)
|
|
1157
1157
|
) {
|
|
1158
1158
|
errors.push({
|
|
1159
1159
|
instanceLocation,
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function deepCompareStrict(a, b) {
|
|
2
|
-
const typeofa = typeof a;
|
|
3
|
-
if (typeofa !== typeof b) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
if (Array.isArray(a)) {
|
|
7
|
-
if (!Array.isArray(b)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const length = a.length;
|
|
11
|
-
if (length !== b.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
if (!deepCompareStrict(a[i], b[i])) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (typeofa === 'object') {
|
|
22
|
-
if (!a || !b) {
|
|
23
|
-
return a === b;
|
|
24
|
-
}
|
|
25
|
-
const aKeys = Object.keys(a);
|
|
26
|
-
const bKeys = Object.keys(b);
|
|
27
|
-
const length = aKeys.length;
|
|
28
|
-
if (length !== bKeys.length) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
for (const k of aKeys) {
|
|
32
|
-
if (!deepCompareStrict(a[k], b[k])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return a === b;
|
|
39
|
-
}
|
package/src/dereference.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { encodePointer } from './pointer.js';
|
|
2
|
-
export const schemaKeyword = {
|
|
3
|
-
additionalItems: true,
|
|
4
|
-
unevaluatedItems: true,
|
|
5
|
-
items: true,
|
|
6
|
-
contains: true,
|
|
7
|
-
additionalProperties: true,
|
|
8
|
-
unevaluatedProperties: true,
|
|
9
|
-
propertyNames: true,
|
|
10
|
-
not: true,
|
|
11
|
-
if: true,
|
|
12
|
-
then: true,
|
|
13
|
-
else: true
|
|
14
|
-
};
|
|
15
|
-
export const schemaArrayKeyword = {
|
|
16
|
-
prefixItems: true,
|
|
17
|
-
items: true,
|
|
18
|
-
allOf: true,
|
|
19
|
-
anyOf: true,
|
|
20
|
-
oneOf: true
|
|
21
|
-
};
|
|
22
|
-
export const schemaMapKeyword = {
|
|
23
|
-
$defs: true,
|
|
24
|
-
definitions: true,
|
|
25
|
-
properties: true,
|
|
26
|
-
patternProperties: true,
|
|
27
|
-
dependentSchemas: true
|
|
28
|
-
};
|
|
29
|
-
export const ignoredKeyword = {
|
|
30
|
-
id: true,
|
|
31
|
-
$id: true,
|
|
32
|
-
$ref: true,
|
|
33
|
-
$schema: true,
|
|
34
|
-
$anchor: true,
|
|
35
|
-
$vocabulary: true,
|
|
36
|
-
$comment: true,
|
|
37
|
-
default: true,
|
|
38
|
-
enum: true,
|
|
39
|
-
const: true,
|
|
40
|
-
required: true,
|
|
41
|
-
type: true,
|
|
42
|
-
maximum: true,
|
|
43
|
-
minimum: true,
|
|
44
|
-
exclusiveMaximum: true,
|
|
45
|
-
exclusiveMinimum: true,
|
|
46
|
-
multipleOf: true,
|
|
47
|
-
maxLength: true,
|
|
48
|
-
minLength: true,
|
|
49
|
-
pattern: true,
|
|
50
|
-
format: true,
|
|
51
|
-
maxItems: true,
|
|
52
|
-
minItems: true,
|
|
53
|
-
uniqueItems: true,
|
|
54
|
-
maxProperties: true,
|
|
55
|
-
minProperties: true
|
|
56
|
-
};
|
|
57
|
-
export let initialBaseURI =
|
|
58
|
-
typeof self !== 'undefined' &&
|
|
59
|
-
self.location &&
|
|
60
|
-
self.location.origin !== 'null'
|
|
61
|
-
? new URL(self.location.origin + self.location.pathname + location.search)
|
|
62
|
-
: new URL('https://github.com/cfworker');
|
|
63
|
-
export function dereference(
|
|
64
|
-
schema,
|
|
65
|
-
lookup = Object.create(null),
|
|
66
|
-
baseURI = initialBaseURI,
|
|
67
|
-
basePointer = ''
|
|
68
|
-
) {
|
|
69
|
-
if (schema && typeof schema === 'object' && !Array.isArray(schema)) {
|
|
70
|
-
const id = schema.$id || schema.id;
|
|
71
|
-
if (id) {
|
|
72
|
-
const url = new URL(id, baseURI.href);
|
|
73
|
-
if (url.hash.length > 1) {
|
|
74
|
-
lookup[url.href] = schema;
|
|
75
|
-
} else {
|
|
76
|
-
url.hash = '';
|
|
77
|
-
if (basePointer === '') {
|
|
78
|
-
baseURI = url;
|
|
79
|
-
} else {
|
|
80
|
-
dereference(schema, lookup, baseURI);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} else if (schema !== true && schema !== false) {
|
|
85
|
-
return lookup;
|
|
86
|
-
}
|
|
87
|
-
const schemaURI = baseURI.href + (basePointer ? '#' + basePointer : '');
|
|
88
|
-
if (lookup[schemaURI] !== undefined) {
|
|
89
|
-
throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
90
|
-
}
|
|
91
|
-
lookup[schemaURI] = schema;
|
|
92
|
-
if (schema === true || schema === false) {
|
|
93
|
-
return lookup;
|
|
94
|
-
}
|
|
95
|
-
if (schema.__absolute_uri__ === undefined) {
|
|
96
|
-
Object.defineProperty(schema, '__absolute_uri__', {
|
|
97
|
-
enumerable: false,
|
|
98
|
-
value: schemaURI
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
if (schema.$ref && schema.__absolute_ref__ === undefined) {
|
|
102
|
-
const url = new URL(schema.$ref, baseURI.href);
|
|
103
|
-
url.hash = url.hash;
|
|
104
|
-
Object.defineProperty(schema, '__absolute_ref__', {
|
|
105
|
-
enumerable: false,
|
|
106
|
-
value: url.href
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === undefined) {
|
|
110
|
-
const url = new URL(schema.$recursiveRef, baseURI.href);
|
|
111
|
-
url.hash = url.hash;
|
|
112
|
-
Object.defineProperty(schema, '__absolute_recursive_ref__', {
|
|
113
|
-
enumerable: false,
|
|
114
|
-
value: url.href
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (schema.$anchor) {
|
|
118
|
-
const url = new URL('#' + schema.$anchor, baseURI.href);
|
|
119
|
-
lookup[url.href] = schema;
|
|
120
|
-
}
|
|
121
|
-
for (let key in schema) {
|
|
122
|
-
if (ignoredKeyword[key]) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
const keyBase = `${basePointer}/${encodePointer(key)}`;
|
|
126
|
-
const subSchema = schema[key];
|
|
127
|
-
if (Array.isArray(subSchema)) {
|
|
128
|
-
if (schemaArrayKeyword[key]) {
|
|
129
|
-
const length = subSchema.length;
|
|
130
|
-
for (let i = 0; i < length; i++) {
|
|
131
|
-
dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
} else if (schemaMapKeyword[key]) {
|
|
135
|
-
for (let subKey in subSchema) {
|
|
136
|
-
dereference(
|
|
137
|
-
subSchema[subKey],
|
|
138
|
-
lookup,
|
|
139
|
-
baseURI,
|
|
140
|
-
`${keyBase}/${encodePointer(subKey)}`
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
dereference(subSchema, lookup, baseURI, keyBase);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return lookup;
|
|
148
|
-
}
|
package/src/format.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
2
|
-
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3
|
-
const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
4
|
-
const HOSTNAME =
|
|
5
|
-
/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;
|
|
6
|
-
const URIREF =
|
|
7
|
-
/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
8
|
-
const URITEMPLATE =
|
|
9
|
-
/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
|
|
10
|
-
const URL_ =
|
|
11
|
-
/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu;
|
|
12
|
-
const UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
|
|
13
|
-
const JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
14
|
-
const JSON_POINTER_URI_FRAGMENT =
|
|
15
|
-
/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
16
|
-
const RELATIVE_JSON_POINTER =
|
|
17
|
-
/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
18
|
-
const FASTDATE = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
|
|
19
|
-
const FASTTIME =
|
|
20
|
-
/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
21
|
-
const FASTDATETIME =
|
|
22
|
-
/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i;
|
|
23
|
-
const FASTURIREFERENCE =
|
|
24
|
-
/^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i;
|
|
25
|
-
const EMAIL = input => {
|
|
26
|
-
if (input[0] === '"') return false;
|
|
27
|
-
const [name, host, ...rest] = input.split('@');
|
|
28
|
-
if (
|
|
29
|
-
!name ||
|
|
30
|
-
!host ||
|
|
31
|
-
rest.length !== 0 ||
|
|
32
|
-
name.length > 64 ||
|
|
33
|
-
host.length > 253
|
|
34
|
-
)
|
|
35
|
-
return false;
|
|
36
|
-
if (name[0] === '.' || name.endsWith('.') || name.includes('..'))
|
|
37
|
-
return false;
|
|
38
|
-
if (
|
|
39
|
-
!/^[a-z0-9.-]+$/i.test(host) ||
|
|
40
|
-
!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name)
|
|
41
|
-
)
|
|
42
|
-
return false;
|
|
43
|
-
return host
|
|
44
|
-
.split('.')
|
|
45
|
-
.every(part => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));
|
|
46
|
-
};
|
|
47
|
-
const IPV4 =
|
|
48
|
-
/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
|
|
49
|
-
const IPV6 =
|
|
50
|
-
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i;
|
|
51
|
-
const DURATION = input =>
|
|
52
|
-
input.length > 1 &&
|
|
53
|
-
input.length < 80 &&
|
|
54
|
-
(/^P\d+([.,]\d+)?W$/.test(input) ||
|
|
55
|
-
(/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(input) &&
|
|
56
|
-
/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(
|
|
57
|
-
input
|
|
58
|
-
)));
|
|
59
|
-
function bind(r) {
|
|
60
|
-
return r.test.bind(r);
|
|
61
|
-
}
|
|
62
|
-
export const fullFormat = {
|
|
63
|
-
date,
|
|
64
|
-
time: time.bind(undefined, false),
|
|
65
|
-
'date-time': date_time,
|
|
66
|
-
duration: DURATION,
|
|
67
|
-
uri,
|
|
68
|
-
'uri-reference': bind(URIREF),
|
|
69
|
-
'uri-template': bind(URITEMPLATE),
|
|
70
|
-
url: bind(URL_),
|
|
71
|
-
email: EMAIL,
|
|
72
|
-
hostname: bind(HOSTNAME),
|
|
73
|
-
ipv4: bind(IPV4),
|
|
74
|
-
ipv6: bind(IPV6),
|
|
75
|
-
regex: regex,
|
|
76
|
-
uuid: bind(UUID),
|
|
77
|
-
'json-pointer': bind(JSON_POINTER),
|
|
78
|
-
'json-pointer-uri-fragment': bind(JSON_POINTER_URI_FRAGMENT),
|
|
79
|
-
'relative-json-pointer': bind(RELATIVE_JSON_POINTER)
|
|
80
|
-
};
|
|
81
|
-
export const fastFormat = {
|
|
82
|
-
...fullFormat,
|
|
83
|
-
date: bind(FASTDATE),
|
|
84
|
-
time: bind(FASTTIME),
|
|
85
|
-
'date-time': bind(FASTDATETIME),
|
|
86
|
-
'uri-reference': bind(FASTURIREFERENCE)
|
|
87
|
-
};
|
|
88
|
-
function isLeapYear(year) {
|
|
89
|
-
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
90
|
-
}
|
|
91
|
-
function date(str) {
|
|
92
|
-
const matches = str.match(DATE);
|
|
93
|
-
if (!matches) return false;
|
|
94
|
-
const year = +matches[1];
|
|
95
|
-
const month = +matches[2];
|
|
96
|
-
const day = +matches[3];
|
|
97
|
-
return (
|
|
98
|
-
month >= 1 &&
|
|
99
|
-
month <= 12 &&
|
|
100
|
-
day >= 1 &&
|
|
101
|
-
day <= (month == 2 && isLeapYear(year) ? 29 : DAYS[month])
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
function time(full, str) {
|
|
105
|
-
const matches = str.match(TIME);
|
|
106
|
-
if (!matches) return false;
|
|
107
|
-
const hour = +matches[1];
|
|
108
|
-
const minute = +matches[2];
|
|
109
|
-
const second = +matches[3];
|
|
110
|
-
const timeZone = !!matches[5];
|
|
111
|
-
return (
|
|
112
|
-
((hour <= 23 && minute <= 59 && second <= 59) ||
|
|
113
|
-
(hour == 23 && minute == 59 && second == 60)) &&
|
|
114
|
-
(!full || timeZone)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
118
|
-
function date_time(str) {
|
|
119
|
-
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
120
|
-
return dateTime.length == 2 && date(dateTime[0]) && time(true, dateTime[1]);
|
|
121
|
-
}
|
|
122
|
-
const NOT_URI_FRAGMENT = /\/|:/;
|
|
123
|
-
const URI_PATTERN =
|
|
124
|
-
/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
125
|
-
function uri(str) {
|
|
126
|
-
return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);
|
|
127
|
-
}
|
|
128
|
-
const Z_ANCHOR = /[^\\]\\Z/;
|
|
129
|
-
function regex(str) {
|
|
130
|
-
if (Z_ANCHOR.test(str)) return false;
|
|
131
|
-
try {
|
|
132
|
-
new RegExp(str, 'u');
|
|
133
|
-
return true;
|
|
134
|
-
} catch (e) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './deep-compare-strict.js';
|
|
2
|
-
export * from './dereference.js';
|
|
3
|
-
export * from './format.js';
|
|
4
|
-
export * from './pointer.js';
|
|
5
|
-
export * from './types.js';
|
|
6
|
-
export * from './ucs2-length.js';
|
|
7
|
-
export * from './validate.js';
|
|
8
|
-
export * from './validator.js';
|
package/src/pointer.js
DELETED
package/src/types.js
DELETED
package/src/ucs2-length.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function ucs2length(s) {
|
|
2
|
-
let result = 0;
|
|
3
|
-
let length = s.length;
|
|
4
|
-
let index = 0;
|
|
5
|
-
let charCode;
|
|
6
|
-
while (index < length) {
|
|
7
|
-
result++;
|
|
8
|
-
charCode = s.charCodeAt(index++);
|
|
9
|
-
if (charCode >= 0xd800 && charCode <= 0xdbff && index < length) {
|
|
10
|
-
charCode = s.charCodeAt(index);
|
|
11
|
-
if ((charCode & 0xfc00) == 0xdc00) {
|
|
12
|
-
index++;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|