@cfworker/json-schema 4.1.0 → 4.1.3
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/deep-compare-strict.d.ts +1 -0
- package/dist/commonjs/deep-compare-strict.d.ts.map +1 -0
- package/dist/commonjs/deep-compare-strict.js +10 -4
- package/dist/commonjs/deep-compare-strict.js.map +1 -0
- package/dist/commonjs/dereference.d.ts +1 -0
- package/dist/commonjs/dereference.d.ts.map +1 -0
- package/dist/commonjs/dereference.js +4 -2
- package/dist/commonjs/dereference.js.map +1 -0
- package/dist/commonjs/format.d.ts +1 -0
- package/dist/commonjs/format.d.ts.map +1 -0
- package/dist/commonjs/format.js +26 -9
- package/dist/commonjs/format.js.map +1 -0
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +2 -1
- package/dist/commonjs/pointer.d.ts +1 -0
- package/dist/commonjs/pointer.d.ts.map +1 -0
- package/dist/commonjs/pointer.js +1 -0
- package/dist/commonjs/pointer.js.map +1 -0
- package/dist/commonjs/types.d.ts +1 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +1 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/ucs2-length.d.ts +1 -0
- package/dist/commonjs/ucs2-length.d.ts.map +1 -0
- package/dist/commonjs/ucs2-length.js +1 -0
- package/dist/commonjs/ucs2-length.js.map +1 -0
- package/dist/commonjs/validate.d.ts +1 -0
- package/dist/commonjs/validate.d.ts.map +1 -0
- package/dist/commonjs/validate.js +51 -25
- package/dist/commonjs/validate.js.map +1 -0
- package/dist/commonjs/validator.d.ts +1 -0
- package/dist/commonjs/validator.d.ts.map +1 -0
- package/dist/commonjs/validator.js +1 -0
- package/dist/commonjs/validator.js.map +1 -0
- package/dist/esm/deep-compare-strict.d.ts +1 -0
- package/dist/esm/deep-compare-strict.d.ts.map +1 -0
- package/dist/esm/deep-compare-strict.js +10 -4
- package/dist/esm/deep-compare-strict.js.map +1 -0
- package/dist/esm/dereference.d.ts +1 -0
- package/dist/esm/dereference.d.ts.map +1 -0
- package/dist/esm/dereference.js +4 -2
- package/dist/esm/dereference.js.map +1 -0
- package/dist/esm/format.d.ts +1 -0
- package/dist/esm/format.d.ts.map +1 -0
- package/dist/esm/format.js +26 -9
- package/dist/esm/format.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +2 -1
- package/dist/esm/pointer.d.ts +1 -0
- package/dist/esm/pointer.d.ts.map +1 -0
- package/dist/esm/pointer.js +1 -0
- package/dist/esm/pointer.js.map +1 -0
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/ucs2-length.d.ts +1 -0
- package/dist/esm/ucs2-length.d.ts.map +1 -0
- package/dist/esm/ucs2-length.js +1 -0
- package/dist/esm/ucs2-length.js.map +1 -0
- package/dist/esm/validate.d.ts +1 -0
- package/dist/esm/validate.d.ts.map +1 -0
- package/dist/esm/validate.js +51 -25
- package/dist/esm/validate.js.map +1 -0
- package/dist/esm/validator.d.ts +1 -0
- package/dist/esm/validator.d.ts.map +1 -0
- package/dist/esm/validator.js +1 -0
- package/dist/esm/validator.js.map +1 -0
- package/package.json +13 -10
- package/src/deep-compare-strict.ts +9 -4
- package/src/dereference.ts +3 -2
- package/src/format.ts +27 -9
- package/src/types.d.ts +1 -7
- package/src/types.ts +1 -7
- package/src/validate.ts +67 -31
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-compare-strict.d.ts","sourceRoot":"","sources":["../../src/deep-compare-strict.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,OAAO,CA2CzD"}
|
|
@@ -6,10 +6,12 @@ function deepCompareStrict(a, b) {
|
|
|
6
6
|
if (typeofa !== typeof b) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const aIsArray = Array.isArray(a);
|
|
10
|
+
const bIsArray = Array.isArray(b);
|
|
11
|
+
if (aIsArray !== bIsArray) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (aIsArray) {
|
|
13
15
|
const length = a.length;
|
|
14
16
|
if (length !== b.length) {
|
|
15
17
|
return false;
|
|
@@ -32,6 +34,9 @@ function deepCompareStrict(a, b) {
|
|
|
32
34
|
return false;
|
|
33
35
|
}
|
|
34
36
|
for (const k of aKeys) {
|
|
37
|
+
if (!Object.prototype.hasOwnProperty.call(b, k)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
35
40
|
if (!deepCompareStrict(a[k], b[k])) {
|
|
36
41
|
return false;
|
|
37
42
|
}
|
|
@@ -40,3 +45,4 @@ function deepCompareStrict(a, b) {
|
|
|
40
45
|
}
|
|
41
46
|
return a === b;
|
|
42
47
|
}
|
|
48
|
+
//# sourceMappingURL=deep-compare-strict.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-compare-strict.js","sourceRoot":"","sources":["../../src/deep-compare-strict.ts"],"names":[],"mappings":";;;AAAA,2BAAkC,CAAM,EAAE,CAAM;IAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC;IACzB,IAAI,OAAO,KAAK,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,C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BACnC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC","sourcesContent":["export function deepCompareStrict(a: any, b: any): boolean {\n const typeofa = typeof a;\n if (typeofa !== typeof b) {\n return false;\n }\n const aIsArray = Array.isArray(a);\n const bIsArray = Array.isArray(b);\n if (aIsArray !== bIsArray) {\n return false;\n }\n if (aIsArray) {\n const length = a.length;\n if (length !== b.length) {\n return false;\n }\n for (let i = 0; i < length; i++) {\n if (!deepCompareStrict(a[i], b[i])) {\n return false;\n }\n }\n return true;\n }\n if (typeofa === 'object') {\n if (!a || !b) {\n return a === b;\n }\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n const length = aKeys.length;\n if (length !== bKeys.length) {\n return false;\n }\n for (const k of aKeys) {\n if (!Object.prototype.hasOwnProperty.call(b, k)) {\n return false;\n }\n if (!deepCompareStrict(a[k], b[k])) {\n return false;\n }\n }\n return true;\n }\n return a === b;\n}\n"]}
|
|
@@ -5,3 +5,4 @@ export declare const schemaMapKeyword: Record<string, boolean>;
|
|
|
5
5
|
export declare const ignoredKeyword: Record<string, boolean>;
|
|
6
6
|
export declare let initialBaseURI: URL;
|
|
7
7
|
export declare function dereference(schema: Schema | boolean, lookup?: Record<string, Schema | boolean>, baseURI?: URL, basePointer?: string): Record<string, Schema | boolean>;
|
|
8
|
+
//# sourceMappingURL=dereference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/dereference.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAYjD,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAMtD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAMpD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA4BlD,CAAC;AAOF,eAAO,IAAI,cAAc,EAAE,GAOiB,CAAC;AAE7C,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAuB,EAC9D,OAAO,GAAE,GAAoB,EAC7B,WAAW,SAAK,GACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CA+FlC"}
|
|
@@ -42,6 +42,7 @@ exports.ignoredKeyword = {
|
|
|
42
42
|
enum: true,
|
|
43
43
|
const: true,
|
|
44
44
|
required: true,
|
|
45
|
+
dependentRequired: true,
|
|
45
46
|
type: true,
|
|
46
47
|
maximum: true,
|
|
47
48
|
minimum: true,
|
|
@@ -66,7 +67,7 @@ exports.initialBaseURI = typeof self !== 'undefined' &&
|
|
|
66
67
|
: new URL('https://github.com/cfworker');
|
|
67
68
|
function dereference(schema, lookup = Object.create(null), baseURI = exports.initialBaseURI, basePointer = '') {
|
|
68
69
|
if (schema && typeof schema === 'object' && !Array.isArray(schema)) {
|
|
69
|
-
const id = schema.$id || schema
|
|
70
|
+
const id = schema.$id || schema['id'];
|
|
70
71
|
if (id) {
|
|
71
72
|
const url = new URL(id, baseURI.href);
|
|
72
73
|
if (url.hash.length > 1) {
|
|
@@ -87,7 +88,7 @@ function dereference(schema, lookup = Object.create(null), baseURI = exports.ini
|
|
|
87
88
|
return lookup;
|
|
88
89
|
}
|
|
89
90
|
const schemaURI = baseURI.href + (basePointer ? '#' + basePointer : '');
|
|
90
|
-
if (lookup[schemaURI] !== undefined) {
|
|
91
|
+
if (lookup[schemaURI] !== undefined && lookup[schemaURI] !== schema) {
|
|
91
92
|
throw new Error(`Duplicate schema URI "${schemaURI}".`);
|
|
92
93
|
}
|
|
93
94
|
lookup[schemaURI] = schema;
|
|
@@ -145,3 +146,4 @@ function dereference(schema, lookup = Object.create(null), baseURI = exports.ini
|
|
|
145
146
|
}
|
|
146
147
|
return lookup;
|
|
147
148
|
}
|
|
149
|
+
//# sourceMappingURL=dereference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dereference.js","sourceRoot":"","sources":["../../src/dereference.ts"],"names":[],"mappings":";;;;AAAA,6CAA6C;AAGhC,QAAA,aAAa,GAA4B;IACpD,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,oBAAoB,EAAE,IAAI;IAC1B,qBAAqB,EAAE,IAAI;IAC3B,aAAa,EAAE,IAAI;IACnB,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACX,CAAC;AAEW,QAAA,kBAAkB,GAA4B;IACzD,WAAW,EAAE,IAAI;IACjB,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;CACZ,CAAC;AAEW,QAAA,gBAAgB,GAA4B;IACvD,KAAK,EAAE,IAAI;IACX,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEW,QAAA,cAAc,GAA4B;IACrD,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,iBAAiB,EAAE,IAAI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C;gBAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAChC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC;aAAM,IAAI,QAAA,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;YACjC,KAAK,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;gBAC7B,WAAW,CACT,SAAS,CAAC,MAAM,CAAC,EACjB,MAAM,EACN,OAAO,EACP,GAAG,OAAO,IAAI,IAAA,0BAAa,EAAC,MAAM,CAAC,EAAE,CACtC,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { encodePointer } from './pointer.js';\nimport { Schema } from './types.js';\n\nexport const schemaKeyword: Record<string, boolean> = {\n additionalItems: true,\n unevaluatedItems: true,\n items: true,\n contains: true,\n additionalProperties: true,\n unevaluatedProperties: true,\n propertyNames: true,\n not: true,\n if: true,\n then: true,\n else: true\n};\n\nexport const schemaArrayKeyword: Record<string, boolean> = {\n prefixItems: true,\n items: true,\n allOf: true,\n anyOf: true,\n oneOf: true\n};\n\nexport const schemaMapKeyword: Record<string, boolean> = {\n $defs: true,\n definitions: true,\n properties: true,\n patternProperties: true,\n dependentSchemas: true\n};\n\nexport const ignoredKeyword: Record<string, boolean> = {\n id: true,\n $id: true,\n $ref: true,\n $schema: true,\n $anchor: true,\n $vocabulary: true,\n $comment: true,\n default: true,\n enum: true,\n const: true,\n required: true,\n dependentRequired: true,\n type: true,\n maximum: true,\n minimum: true,\n exclusiveMaximum: true,\n exclusiveMinimum: true,\n multipleOf: true,\n maxLength: true,\n minLength: true,\n pattern: true,\n format: true,\n maxItems: true,\n minItems: true,\n uniqueItems: true,\n maxProperties: true,\n minProperties: true\n};\n\n/**\n * Default base URI for schemas without an $id.\n * https://json-schema.org/draft/2019-09/json-schema-core.html#initial-base\n * https://tools.ietf.org/html/rfc3986#section-5.1\n */\nexport let initialBaseURI: URL =\n // @ts-ignore\n typeof self !== 'undefined' &&\n self.location &&\n self.location.origin !== 'null'\n ? //@ts-ignore\n new URL(self.location.origin + self.location.pathname + location.search)\n : new URL('https://github.com/cfworker');\n\nexport function dereference(\n schema: Schema | boolean,\n lookup: Record<string, Schema | boolean> = Object.create(null),\n baseURI: URL = initialBaseURI,\n basePointer = ''\n): Record<string, Schema | boolean> {\n if (schema && typeof schema === 'object' && !Array.isArray(schema)) {\n const id: string = schema.$id || schema['id'];\n if (id) {\n const url = new URL(id, baseURI.href);\n if (url.hash.length > 1) {\n lookup[url.href] = schema;\n } else {\n url.hash = ''; // normalize hash https://url.spec.whatwg.org/#dom-url-hash\n if (basePointer === '') {\n baseURI = url;\n } else {\n dereference(schema, lookup, baseURI);\n }\n }\n }\n } else if (schema !== true && schema !== false) {\n return lookup;\n }\n\n // compute the schema's URI and add it to the mapping.\n const schemaURI = baseURI.href + (basePointer ? '#' + basePointer : '');\n if (lookup[schemaURI] !== undefined && lookup[schemaURI] !== schema) {\n throw new Error(`Duplicate schema URI \"${schemaURI}\".`);\n }\n lookup[schemaURI] = schema;\n\n // exit early if this is a boolean schema.\n if (schema === true || schema === false) {\n return lookup;\n }\n\n // set the schema's absolute URI.\n if (schema.__absolute_uri__ === undefined) {\n Object.defineProperty(schema, '__absolute_uri__', {\n enumerable: false,\n value: schemaURI\n });\n }\n\n // if a $ref is found, resolve it's absolute URI.\n if (schema.$ref && schema.__absolute_ref__ === undefined) {\n const url = new URL(schema.$ref, baseURI.href);\n url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash\n Object.defineProperty(schema, '__absolute_ref__', {\n enumerable: false,\n value: url.href\n });\n }\n\n // if a $recursiveRef is found, resolve it's absolute URI.\n if (schema.$recursiveRef && schema.__absolute_recursive_ref__ === undefined) {\n const url = new URL(schema.$recursiveRef, baseURI.href);\n url.hash = url.hash; // normalize hash https://url.spec.whatwg.org/#dom-url-hash\n Object.defineProperty(schema, '__absolute_recursive_ref__', {\n enumerable: false,\n value: url.href\n });\n }\n\n // if an $anchor is found, compute it's URI and add it to the mapping.\n if (schema.$anchor) {\n const url = new URL('#' + schema.$anchor, baseURI.href);\n lookup[url.href] = schema;\n }\n\n // process subschemas.\n for (let key in schema) {\n if (ignoredKeyword[key]) {\n continue;\n }\n const keyBase = `${basePointer}/${encodePointer(key)}`;\n const subSchema = schema[key];\n if (Array.isArray(subSchema)) {\n if (schemaArrayKeyword[key]) {\n const length = subSchema.length;\n for (let i = 0; i < length; i++) {\n dereference(subSchema[i], lookup, baseURI, `${keyBase}/${i}`);\n }\n }\n } else if (schemaMapKeyword[key]) {\n for (let subKey in subSchema) {\n dereference(\n subSchema[subKey],\n lookup,\n baseURI,\n `${keyBase}/${encodePointer(subKey)}`\n );\n }\n } else {\n dereference(subSchema, lookup, baseURI, keyBase);\n }\n }\n\n return lookup;\n}\n\n// schema identification examples\n// https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.appendix.A\n// $ref delegation\n// https://github.com/json-schema-org/json-schema-spec/issues/514\n// output format\n// https://json-schema.org/draft/2019-09/json-schema-core.html#output\n// JSON pointer\n// https://tools.ietf.org/html/rfc6901\n// JSON relative pointer\n// https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAiFA,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAkBzD,CAAC"}
|
package/dist/commonjs/format.js
CHANGED
|
@@ -67,21 +67,33 @@ function date(str) {
|
|
|
67
67
|
const matches = str.match(DATE);
|
|
68
68
|
if (!matches)
|
|
69
69
|
return false;
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
70
|
+
const yearPart = matches[1];
|
|
71
|
+
const monthPart = matches[2];
|
|
72
|
+
const dayPart = matches[3];
|
|
73
|
+
if (!yearPart || !monthPart || !dayPart)
|
|
74
|
+
return false;
|
|
75
|
+
const year = +yearPart;
|
|
76
|
+
const month = +monthPart;
|
|
77
|
+
const day = +dayPart;
|
|
78
|
+
const maxDay = month == 2 && isLeapYear(year) ? 29 : DAYS[month];
|
|
73
79
|
return (month >= 1 &&
|
|
74
80
|
month <= 12 &&
|
|
75
81
|
day >= 1 &&
|
|
76
|
-
|
|
82
|
+
maxDay !== undefined &&
|
|
83
|
+
day <= maxDay);
|
|
77
84
|
}
|
|
78
85
|
function time(full, str) {
|
|
79
86
|
const matches = str.match(TIME);
|
|
80
87
|
if (!matches)
|
|
81
88
|
return false;
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
89
|
+
const hourPart = matches[1];
|
|
90
|
+
const minutePart = matches[2];
|
|
91
|
+
const secondPart = matches[3];
|
|
92
|
+
if (!hourPart || !minutePart || !secondPart)
|
|
93
|
+
return false;
|
|
94
|
+
const hour = +hourPart;
|
|
95
|
+
const minute = +minutePart;
|
|
96
|
+
const second = +secondPart;
|
|
85
97
|
const timeZone = !!matches[5];
|
|
86
98
|
return (((hour <= 23 && minute <= 59 && second <= 59) ||
|
|
87
99
|
(hour == 23 && minute == 59 && second == 60)) &&
|
|
@@ -89,8 +101,12 @@ function time(full, str) {
|
|
|
89
101
|
}
|
|
90
102
|
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
91
103
|
function date_time(str) {
|
|
92
|
-
const
|
|
93
|
-
return
|
|
104
|
+
const [datePart, timePart, extra] = str.split(DATE_TIME_SEPARATOR);
|
|
105
|
+
return (datePart !== undefined &&
|
|
106
|
+
timePart !== undefined &&
|
|
107
|
+
extra === undefined &&
|
|
108
|
+
date(datePart) &&
|
|
109
|
+
time(true, timePart));
|
|
94
110
|
}
|
|
95
111
|
const NOT_URI_FRAGMENT = /\/|:/;
|
|
96
112
|
const URI_PATTERN = /^(?:[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;
|
|
@@ -109,3 +125,4 @@ function regex(str) {
|
|
|
109
125
|
return false;
|
|
110
126
|
}
|
|
111
127
|
}
|
|
128
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":";;;AAEA,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAC1C,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACjE,MAAM,IAAI,GAAG,yDAAyD,CAAC;AACvE,MAAM,QAAQ,GACZ,uGAAuG,CAAC;AAE1G,MAAM,MAAM,GACV,woCAAwoC,CAAC;AAE3oC,MAAM,WAAW,GACf,mLAAmL,CAAC;AAGtL,MAAM,IAAI,GACR,wfAAwf,CAAC;AAC3f,MAAM,IAAI,GAAG,8DAA8D,CAAC;AAC5E,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,MAAM,yBAAyB,GAC7B,8DAA8D,CAAC;AACjE,MAAM,qBAAqB,GACzB,kDAAkD,CAAC;AAerD,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE;IAC9B,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACnC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,G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OAAO,CAAC;AACpC,SAAS,SAAS,CAAC,GAAW;IAE5B,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACnE,OAAO,CACL,QAAQ,KAAK,SAAS;QACtB,QAAQ,KAAK,SAAS;QACtB,KAAK,KAAK,SAAS;QACnB,IAAI,CAAC,QAAQ,CAAC;QACd,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CACrB,CAAC;AACJ,CAAC;AAED,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,WAAW,GACf,8nCAA8nC,CAAC;AAEjoC,SAAS,GAAG,CAAC,GAAW;IAEtB,OAAO,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,SAAS,KAAK,CAAC,GAAW;IACxB,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,IAAI,CAAC;QACH,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["// based on https://github.com/epoberezkin/ajv/blob/master/lib/compile/formats.js\n\nconst DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/;\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst TIME = /^(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?(z|[+-]\\d\\d(?::?\\d\\d)?)?$/i;\nconst HOSTNAME =\n /^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-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(?:[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;\n// uri-template: https://tools.ietf.org/html/rfc6570\nconst URITEMPLATE =\n /^(?:(?:[^\\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;\n// For the source: https://gist.github.com/dperini/729294\n// For test cases: https://mathiasbynens.be/demo/url-regex\nconst URL_ =\n /^(?:(?: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;\nconst UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;\nconst JSON_POINTER = /^(?:\\/(?:[^~/]|~0|~1)*)*$/;\nconst JSON_POINTER_URI_FRAGMENT =\n /^#(?:\\/(?:[a-z0-9_\\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;\nconst RELATIVE_JSON_POINTER =\n /^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/;\n\n// // date: http://tools.ietf.org/html/rfc3339#section-5.6\n// const FASTDATE = /^\\d\\d\\d\\d-[0-1]\\d-[0-3]\\d$/;\n// // date-time: http://tools.ietf.org/html/rfc3339#section-5.6\n// const FASTTIME =\n// /^(?:[0-2]\\d:[0-5]\\d:[0-5]\\d|23:59:60)(?:\\.\\d+)?(?:z|[+-]\\d\\d(?::?\\d\\d)?)?$/i;\n// const FASTDATETIME =\n// /^\\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;\n// // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js\n// // const FASTURI = /^(?:[a-z][a-z0-9+-.]*:)(?:\\/?\\/)?[^\\s]*$/i;\n// const FASTURIREFERENCE =\n// /^(?:(?:[a-z][a-z0-9+-.]*:)?\\/?\\/)?(?:[^\\\\\\s#][^\\s#]*)?(?:#[^\\\\\\s]*)?$/i;\n\n// https://github.com/ExodusMovement/schemasafe/blob/master/src/formats.js\nconst EMAIL = (input: string) => {\n if (input[0] === '\"') return false;\n const [name, host, ...rest] = input.split('@');\n if (\n !name ||\n !host ||\n rest.length !== 0 ||\n name.length > 64 ||\n host.length > 253\n )\n return false;\n if (name[0] === '.' || name.endsWith('.') || name.includes('..'))\n return false;\n if (\n !/^[a-z0-9.-]+$/i.test(host) ||\n !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(name)\n )\n return false;\n return host\n .split('.')\n .every(part => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(part));\n};\n\n// optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\nconst IPV4 =\n /^(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$/;\n// optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses\nconst IPV6 =\n /^((([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;\n\n// https://github.com/ExodusMovement/schemasafe/blob/master/src/formats.js\nconst DURATION = (input: string) =>\n input.length > 1 &&\n input.length < 80 &&\n (/^P\\d+([.,]\\d+)?W$/.test(input) ||\n (/^P[\\dYMDTHS]*(\\d[.,]\\d+)?[YMDHS]$/.test(input) &&\n /^P([.,\\d]+Y)?([.,\\d]+M)?([.,\\d]+D)?(T([.,\\d]+H)?([.,\\d]+M)?([.,\\d]+S)?)?$/.test(\n input\n )));\n\nfunction bind(r: RegExp) {\n return r.test.bind(r);\n}\n\nexport const format: Record<string, (s: string) => boolean> = {\n date,\n time: time.bind(undefined, false),\n 'date-time': date_time,\n duration: DURATION,\n uri,\n 'uri-reference': bind(URIREF),\n 'uri-template': bind(URITEMPLATE),\n url: bind(URL_),\n email: EMAIL,\n hostname: bind(HOSTNAME),\n ipv4: bind(IPV4),\n ipv6: bind(IPV6),\n regex: regex,\n uuid: bind(UUID),\n 'json-pointer': bind(JSON_POINTER),\n 'json-pointer-uri-fragment': bind(JSON_POINTER_URI_FRAGMENT),\n 'relative-json-pointer': bind(RELATIVE_JSON_POINTER)\n};\n\nfunction isLeapYear(year: number) {\n // https://tools.ietf.org/html/rfc3339#appendix-C\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);\n}\n\nfunction date(str: string) {\n // full-date from http://tools.ietf.org/html/rfc3339#section-5.6\n const matches = str.match(DATE);\n if (!matches) return false;\n\n const yearPart = matches[1];\n const monthPart = matches[2];\n const dayPart = matches[3];\n if (!yearPart || !monthPart || !dayPart) return false;\n\n const year = +yearPart;\n const month = +monthPart;\n const day = +dayPart;\n const maxDay = month == 2 && isLeapYear(year) ? 29 : DAYS[month];\n\n return (\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n maxDay !== undefined &&\n day <= maxDay\n );\n}\n\nfunction time(full: boolean, str: string) {\n const matches = str.match(TIME);\n if (!matches) return false;\n\n const hourPart = matches[1];\n const minutePart = matches[2];\n const secondPart = matches[3];\n if (!hourPart || !minutePart || !secondPart) return false;\n\n const hour = +hourPart;\n const minute = +minutePart;\n const second = +secondPart;\n const timeZone = !!matches[5];\n return (\n ((hour <= 23 && minute <= 59 && second <= 59) ||\n (hour == 23 && minute == 59 && second == 60)) &&\n (!full || timeZone)\n );\n}\n\nconst DATE_TIME_SEPARATOR = /t|\\s/i;\nfunction date_time(str: string) {\n // http://tools.ietf.org/html/rfc3339#section-5.6\n const [datePart, timePart, extra] = str.split(DATE_TIME_SEPARATOR);\n return (\n datePart !== undefined &&\n timePart !== undefined &&\n extra === undefined &&\n date(datePart) &&\n time(true, timePart)\n );\n}\n\nconst NOT_URI_FRAGMENT = /\\/|:/;\nconst URI_PATTERN =\n /^(?:[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;\n\nfunction uri(str: string): boolean {\n // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required \".\"\n return NOT_URI_FRAGMENT.test(str) && URI_PATTERN.test(str);\n}\n\nconst Z_ANCHOR = /[^\\\\]\\\\Z/;\nfunction regex(str: string) {\n if (Z_ANCHOR.test(str)) return false;\n try {\n new RegExp(str, 'u');\n return true;\n } catch (e) {\n return false;\n }\n}\n"]}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,mDAAiC;AACjC,8CAA4B;AAC5B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,gDAA8B;AAC9B,iDAA+B","sourcesContent":["export * from './deep-compare-strict.js';\nexport * from './dereference.js';\nexport * from './format.js';\nexport * from './pointer.js';\nexport * from './types.js';\nexport * from './ucs2-length.js';\nexport * from './validate.js';\nexport * from './validator.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer.d.ts","sourceRoot":"","sources":["../../src/pointer.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/commonjs/pointer.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointer.js","sourceRoot":"","sources":["../../src/pointer.ts"],"names":[],"mappings":";;;;AAAA,uBAA8B,CAAS;IACrC,OAAO,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,uBAA8B,CAAS;IACrC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC","sourcesContent":["export function encodePointer(p: string): string {\n return encodeURI(escapePointer(p));\n}\n\nexport function escapePointer(p: string): string {\n return p.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n"]}
|
package/dist/commonjs/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5D,0BAAkB,YAAY;IAC5B,IAAI,IAAS;IACb,KAAK,IAAS;IACd,QAAQ,IAAS;CAClB;AAED,MAAM,MAAM,YAAY,GACtB,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5E,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEtC,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAC;IACrC,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;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OAAO,CAAC;IAEtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB"}
|
package/dist/commonjs/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAEA,IAAkB,YAIjB;AAJD,WAAkB,YAAY;IAC5B,+CAAa,CAAA;IACb,iDAAc,CAAA;IACd,uDAAiB,CAAA;AACnB,CAAC,EAJiB,YAAY,aAAZ,YAAY,GAAZ,YAAY,QAI7B","sourcesContent":["export type SchemaDraft = '4' | '7' | '2019-09' | '2020-12';\n\nexport const enum OutputFormat {\n Flag = 1 << 0,\n Basic = 1 << 1,\n Detailed = 1 << 2\n}\n\nexport type InstanceType =\n 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';\n\nexport interface Schema {\n $id?: string;\n $anchor?: string;\n $recursiveAnchor?: boolean;\n $ref?: string;\n $recursiveRef?: '#';\n $schema?: string;\n $comment?: string;\n $defs?: any;\n $vocabulary?: Record<string, boolean>;\n\n type?: InstanceType | InstanceType[];\n const?: any;\n enum?: any[];\n required?: string[];\n not?: Schema;\n anyOf?: Schema[];\n allOf?: Schema[];\n oneOf?: Schema[];\n if?: Schema;\n then?: Schema;\n else?: Schema;\n\n format?: string;\n\n properties?: Record<string | number, Schema | boolean>;\n patternProperties?: Record<string, Schema | boolean>;\n additionalProperties?: Schema | boolean;\n unevaluatedProperties?: Schema | boolean;\n minProperties?: number;\n maxProperties?: number;\n propertyNames?: Schema;\n dependentRequired?: Record<string, string[]>;\n dependentSchemas?: Record<string, Schema>;\n dependencies?: Record<string, Schema | string[]>;\n\n prefixItems?: Array<Schema | boolean>;\n items?: Schema | boolean | Array<Schema | boolean>;\n additionalItems?: Schema | boolean;\n unevaluatedItems?: Schema | boolean;\n contains?: Schema | boolean;\n minContains?: number;\n maxContains?: number;\n minItems?: number;\n maxItems?: number;\n uniqueItems?: boolean;\n\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number | boolean;\n exclusiveMaximum?: number | boolean;\n multipleOf?: number;\n\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n\n __absolute_ref__?: string;\n __absolute_recursive_ref__?: string;\n __absolute_uri__?: string;\n\n [key: string]: any;\n}\n\nexport interface OutputUnit {\n keyword: string;\n keywordLocation: string;\n instanceLocation: string;\n error: string;\n}\n\nexport interface ValidationResult {\n valid: boolean;\n errors: OutputUnit[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ucs2-length.d.ts","sourceRoot":"","sources":["../../src/ucs2-length.ts"],"names":[],"mappings":"AAKA,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ucs2-length.js","sourceRoot":"","sources":["../../src/ucs2-length.ts"],"names":[],"mappings":";;;AAKA,oBAA2B,CAAS;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,QAAgB,CAAC;IACrB,OAAO,KAAK,GAAG,MAAM,EAAE,CAAC;QACtB,MAAM,EAAE,CAAC;QACT,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QACjC,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAK,GAAG,MAAM,EAAE,CAAC;YAE/D,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;gBAElC,KAAK,EAAE,CAAC;YACV,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Get UCS-2 length of a string\n * https://mathiasbynens.be/notes/javascript-encoding\n * https://github.com/bestiejs/punycode.js - punycode.ucs2.decode\n */\nexport function ucs2length(s: string): number {\n let result = 0;\n let length = s.length;\n let index = 0;\n let charCode: number;\n while (index < length) {\n result++;\n charCode = s.charCodeAt(index++);\n if (charCode >= 0xd800 && charCode <= 0xdbff && index < length) {\n // high surrogate, and there is a next character\n charCode = s.charCodeAt(index);\n if ((charCode & 0xfc00) == 0xdc00) {\n // low surrogate\n index++;\n }\n }\n }\n return result;\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Schema, SchemaDraft, ValidationResult } from './types.js';
|
|
2
2
|
export type Evaluated = Record<string | number, boolean>;
|
|
3
3
|
export declare function validate(instance: any, schema: Schema | boolean, draft?: SchemaDraft, lookup?: Record<string, Schema | boolean>, shortCircuit?: boolean, recursiveAnchor?: Schema | null, instanceLocation?: string, schemaLocation?: string, evaluated?: Evaluated): ValidationResult;
|
|
4
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,MAAM,EACN,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;AA4CzD,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,MAAM,GAAG,OAAO,EACxB,KAAK,GAAE,WAAuB,EAC9B,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAuB,EAC9D,YAAY,UAAO,EACnB,eAAe,GAAE,MAAM,GAAG,IAAW,EACrC,gBAAgB,SAAM,EACtB,cAAc,SAAM,EACpB,SAAS,GAAE,SAA+B,GACzC,gBAAgB,CAgnClB"}
|
|
@@ -6,6 +6,36 @@ const dereference_js_1 = require("./dereference.js");
|
|
|
6
6
|
const format_js_1 = require("./format.js");
|
|
7
7
|
const pointer_js_1 = require("./pointer.js");
|
|
8
8
|
const ucs2_length_js_1 = require("./ucs2-length.js");
|
|
9
|
+
function hasOwnProperty(instance, key) {
|
|
10
|
+
return Object.prototype.hasOwnProperty.call(instance, key);
|
|
11
|
+
}
|
|
12
|
+
function decimalInteger(value) {
|
|
13
|
+
const coefficientAndExponent = Math.abs(value).toString().split('e');
|
|
14
|
+
const coefficient = coefficientAndExponent[0];
|
|
15
|
+
const exponent = coefficientAndExponent[1] ?? '0';
|
|
16
|
+
const point = coefficient.indexOf('.');
|
|
17
|
+
const fractionLength = point === -1 ? 0 : coefficient.length - point - 1;
|
|
18
|
+
return [
|
|
19
|
+
BigInt(coefficient.replace('.', '')),
|
|
20
|
+
Number(exponent) - fractionLength
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
function isMultipleOf(instance, divisor) {
|
|
24
|
+
if (!Number.isFinite(instance) || !Number.isFinite(divisor) || divisor <= 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const [instanceCoefficient, instanceExponent] = decimalInteger(instance);
|
|
28
|
+
const [divisorCoefficient, divisorExponent] = decimalInteger(divisor);
|
|
29
|
+
const exponentDifference = instanceExponent - divisorExponent;
|
|
30
|
+
if (exponentDifference >= 0) {
|
|
31
|
+
return ((instanceCoefficient * 10n ** BigInt(exponentDifference)) %
|
|
32
|
+
divisorCoefficient ===
|
|
33
|
+
0n);
|
|
34
|
+
}
|
|
35
|
+
return (instanceCoefficient %
|
|
36
|
+
(divisorCoefficient * 10n ** BigInt(-exponentDifference)) ===
|
|
37
|
+
0n);
|
|
38
|
+
}
|
|
9
39
|
function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_js_1.dereference)(schema), shortCircuit = true, recursiveAnchor = null, instanceLocation = '#', schemaLocation = '#', evaluated = Object.create(null)) {
|
|
10
40
|
if (schema === true) {
|
|
11
41
|
return { valid: true, errors: [] };
|
|
@@ -187,8 +217,7 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
187
217
|
const keywordLocation = `${schemaLocation}/anyOf`;
|
|
188
218
|
const errorsLength = errors.length;
|
|
189
219
|
let anyValid = false;
|
|
190
|
-
for (
|
|
191
|
-
const subSchema = $anyOf[i];
|
|
220
|
+
for (const [i, subSchema] of $anyOf.entries()) {
|
|
192
221
|
const subEvaluated = Object.create(evaluated);
|
|
193
222
|
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
194
223
|
errors.push(...result.errors);
|
|
@@ -213,8 +242,7 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
213
242
|
const keywordLocation = `${schemaLocation}/allOf`;
|
|
214
243
|
const errorsLength = errors.length;
|
|
215
244
|
let allValid = true;
|
|
216
|
-
for (
|
|
217
|
-
const subSchema = $allOf[i];
|
|
245
|
+
for (const [i, subSchema] of $allOf.entries()) {
|
|
218
246
|
const subEvaluated = Object.create(evaluated);
|
|
219
247
|
const result = validate(instance, subSchema, draft, lookup, shortCircuit, $recursiveAnchor === true ? recursiveAnchor : null, instanceLocation, `${keywordLocation}/${i}`, subEvaluated);
|
|
220
248
|
errors.push(...result.errors);
|
|
@@ -293,7 +321,7 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
293
321
|
if (instanceType === 'object') {
|
|
294
322
|
if ($required !== undefined) {
|
|
295
323
|
for (const key of $required) {
|
|
296
|
-
if (!(key
|
|
324
|
+
if (!hasOwnProperty(instance, key)) {
|
|
297
325
|
errors.push({
|
|
298
326
|
instanceLocation,
|
|
299
327
|
keyword: 'required',
|
|
@@ -338,10 +366,10 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
338
366
|
if ($dependentRequired !== undefined) {
|
|
339
367
|
const keywordLocation = `${schemaLocation}/dependantRequired`;
|
|
340
368
|
for (const key in $dependentRequired) {
|
|
341
|
-
if (key
|
|
369
|
+
if (hasOwnProperty(instance, key)) {
|
|
342
370
|
const required = $dependentRequired[key];
|
|
343
371
|
for (const dependantKey of required) {
|
|
344
|
-
if (!(dependantKey
|
|
372
|
+
if (!hasOwnProperty(instance, dependantKey)) {
|
|
345
373
|
errors.push({
|
|
346
374
|
instanceLocation,
|
|
347
375
|
keyword: 'dependentRequired',
|
|
@@ -354,10 +382,10 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
354
382
|
}
|
|
355
383
|
}
|
|
356
384
|
if ($dependentSchemas !== undefined) {
|
|
357
|
-
for (const key
|
|
385
|
+
for (const [key, dependentSchema] of Object.entries($dependentSchemas)) {
|
|
358
386
|
const keywordLocation = `${schemaLocation}/dependentSchemas`;
|
|
359
|
-
if (key
|
|
360
|
-
const result = validate(instance,
|
|
387
|
+
if (hasOwnProperty(instance, key)) {
|
|
388
|
+
const result = validate(instance, dependentSchema, draft, lookup, shortCircuit, recursiveAnchor, instanceLocation, `${keywordLocation}/${(0, pointer_js_1.encodePointer)(key)}`, evaluated);
|
|
361
389
|
if (!result.valid) {
|
|
362
390
|
errors.push({
|
|
363
391
|
instanceLocation,
|
|
@@ -372,11 +400,11 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
372
400
|
if ($dependencies !== undefined) {
|
|
373
401
|
const keywordLocation = `${schemaLocation}/dependencies`;
|
|
374
402
|
for (const key in $dependencies) {
|
|
375
|
-
if (key
|
|
403
|
+
if (hasOwnProperty(instance, key)) {
|
|
376
404
|
const propsOrSchema = $dependencies[key];
|
|
377
405
|
if (Array.isArray(propsOrSchema)) {
|
|
378
406
|
for (const dependantKey of propsOrSchema) {
|
|
379
|
-
if (!(dependantKey
|
|
407
|
+
if (!hasOwnProperty(instance, dependantKey)) {
|
|
380
408
|
errors.push({
|
|
381
409
|
instanceLocation,
|
|
382
410
|
keyword: 'dependencies',
|
|
@@ -404,14 +432,15 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
404
432
|
let stop = false;
|
|
405
433
|
if ($properties !== undefined) {
|
|
406
434
|
const keywordLocation = `${schemaLocation}/properties`;
|
|
407
|
-
for (const key
|
|
408
|
-
if (!(key
|
|
435
|
+
for (const [key, propertySchema] of Object.entries($properties)) {
|
|
436
|
+
if (!hasOwnProperty(instance, key)) {
|
|
409
437
|
continue;
|
|
410
438
|
}
|
|
411
439
|
const subInstancePointer = `${instanceLocation}/${(0, pointer_js_1.encodePointer)(key)}`;
|
|
412
|
-
const result = validate(instance[key],
|
|
440
|
+
const result = validate(instance[key], propertySchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${(0, pointer_js_1.encodePointer)(key)}`);
|
|
441
|
+
thisEvaluated[key] = true;
|
|
413
442
|
if (result.valid) {
|
|
414
|
-
evaluated[key] =
|
|
443
|
+
evaluated[key] = true;
|
|
415
444
|
}
|
|
416
445
|
else {
|
|
417
446
|
stop = shortCircuit;
|
|
@@ -428,17 +457,17 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
428
457
|
}
|
|
429
458
|
if (!stop && $patternProperties !== undefined) {
|
|
430
459
|
const keywordLocation = `${schemaLocation}/patternProperties`;
|
|
431
|
-
for (const pattern
|
|
460
|
+
for (const [pattern, subSchema] of Object.entries($patternProperties)) {
|
|
432
461
|
const regex = new RegExp(pattern, 'u');
|
|
433
|
-
const subSchema = $patternProperties[pattern];
|
|
434
462
|
for (const key in instance) {
|
|
435
463
|
if (!regex.test(key)) {
|
|
436
464
|
continue;
|
|
437
465
|
}
|
|
438
466
|
const subInstancePointer = `${instanceLocation}/${(0, pointer_js_1.encodePointer)(key)}`;
|
|
439
467
|
const result = validate(instance[key], subSchema, draft, lookup, shortCircuit, recursiveAnchor, subInstancePointer, `${keywordLocation}/${(0, pointer_js_1.encodePointer)(pattern)}`);
|
|
468
|
+
thisEvaluated[key] = true;
|
|
440
469
|
if (result.valid) {
|
|
441
|
-
evaluated[key] =
|
|
470
|
+
evaluated[key] = true;
|
|
442
471
|
}
|
|
443
472
|
else {
|
|
444
473
|
stop = shortCircuit;
|
|
@@ -622,9 +651,7 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
622
651
|
if (contained >= ($minContains || 0)) {
|
|
623
652
|
errors.length = errorsLength;
|
|
624
653
|
}
|
|
625
|
-
if ($minContains === undefined &&
|
|
626
|
-
$maxContains === undefined &&
|
|
627
|
-
contained === 0) {
|
|
654
|
+
if ($minContains === undefined && contained === 0) {
|
|
628
655
|
errors.splice(errorsLength, 0, {
|
|
629
656
|
instanceLocation,
|
|
630
657
|
keyword: 'contains',
|
|
@@ -750,9 +777,7 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
750
777
|
}
|
|
751
778
|
}
|
|
752
779
|
if ($multipleOf !== undefined) {
|
|
753
|
-
|
|
754
|
-
if (Math.abs(0 - remainder) >= 1.1920929e-7 &&
|
|
755
|
-
Math.abs($multipleOf - remainder) >= 1.1920929e-7) {
|
|
780
|
+
if (!isMultipleOf(instance, $multipleOf)) {
|
|
756
781
|
errors.push({
|
|
757
782
|
instanceLocation,
|
|
758
783
|
keyword: 'multipleOf',
|
|
@@ -803,3 +828,4 @@ function validate(instance, schema, draft = '2019-09', lookup = (0, dereference_
|
|
|
803
828
|
}
|
|
804
829
|
return { valid: errors.length === 0, errors };
|
|
805
830
|
}
|
|
831
|
+
//# sourceMappingURL=validate.js.map
|