z-schema 6.0.2 → 7.0.0-beta.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.
Files changed (47) hide show
  1. package/README.md +154 -134
  2. package/bin/z-schema +128 -124
  3. package/dist/Errors.js +50 -0
  4. package/dist/FormatValidators.js +136 -0
  5. package/{src → dist}/JsonValidation.js +184 -213
  6. package/dist/Report.js +220 -0
  7. package/{src → dist}/SchemaCache.js +67 -82
  8. package/{src → dist}/SchemaCompilation.js +89 -129
  9. package/dist/SchemaValidation.js +631 -0
  10. package/{src → dist}/Utils.js +96 -104
  11. package/dist/ZSchema-umd-min.js +1 -0
  12. package/dist/ZSchema-umd.js +13791 -0
  13. package/dist/ZSchema.cjs +13785 -0
  14. package/dist/ZSchema.js +366 -0
  15. package/dist/schemas/hyper-schema.json +156 -0
  16. package/dist/schemas/schema.json +151 -0
  17. package/dist/types/Errors.d.ts +44 -0
  18. package/dist/types/FormatValidators.d.ts +12 -0
  19. package/dist/types/JsonValidation.d.ts +37 -0
  20. package/dist/types/Report.d.ts +87 -0
  21. package/dist/types/SchemaCache.d.ts +26 -0
  22. package/dist/types/SchemaCompilation.d.ts +1 -0
  23. package/dist/types/SchemaValidation.d.ts +6 -0
  24. package/dist/types/Utils.d.ts +64 -0
  25. package/dist/types/ZSchema.d.ts +97 -0
  26. package/package.json +54 -43
  27. package/src/Errors.ts +56 -0
  28. package/src/FormatValidators.ts +136 -0
  29. package/src/JsonValidation.ts +624 -0
  30. package/src/Report.ts +337 -0
  31. package/src/SchemaCache.ts +189 -0
  32. package/src/SchemaCompilation.ts +293 -0
  33. package/src/SchemaValidation.ts +629 -0
  34. package/src/Utils.ts +286 -0
  35. package/src/ZSchema.ts +469 -0
  36. package/src/schemas/_ +0 -0
  37. package/dist/ZSchema-browser-min.js +0 -2
  38. package/dist/ZSchema-browser-min.js.map +0 -1
  39. package/dist/ZSchema-browser-test.js +0 -32247
  40. package/dist/ZSchema-browser.js +0 -12745
  41. package/index.d.ts +0 -175
  42. package/src/Errors.js +0 -60
  43. package/src/FormatValidators.js +0 -129
  44. package/src/Polyfills.js +0 -16
  45. package/src/Report.js +0 -299
  46. package/src/SchemaValidation.js +0 -619
  47. package/src/ZSchema.js +0 -409
@@ -1,71 +1,59 @@
1
- "use strict";
2
-
3
- exports.jsonSymbol = Symbol.for("z-schema/json");
4
-
5
- exports.schemaSymbol = Symbol.for("z-schema/schema");
6
-
1
+ export const jsonSymbol = Symbol.for('z-schema/json');
2
+ export const schemaSymbol = Symbol.for('z-schema/schema');
7
3
  /**
8
4
  * @param {object} obj
9
5
  *
10
6
  * @returns {string[]}
11
7
  */
12
- var sortedKeys = exports.sortedKeys = function (obj) {
8
+ export function sortedKeys(obj) {
13
9
  return Object.keys(obj).sort();
14
- };
15
-
10
+ }
16
11
  /**
17
12
  *
18
13
  * @param {string} uri
19
14
  *
20
15
  * @returns {boolean}
21
16
  */
22
- exports.isAbsoluteUri = function (uri) {
17
+ export function isAbsoluteUri(uri) {
23
18
  return /^https?:\/\//.test(uri);
24
- };
25
-
19
+ }
26
20
  /**
27
21
  *
28
22
  * @param {string} uri
29
23
  *
30
24
  * @returns {boolean}
31
25
  */
32
- exports.isRelativeUri = function (uri) {
26
+ export function isRelativeUri(uri) {
33
27
  // relative URIs that end with a hash sign, issue #56
34
28
  return /.+#/.test(uri);
35
- };
36
-
37
- exports.whatIs = function (what) {
38
-
39
- var to = typeof what;
40
-
41
- if (to === "object") {
29
+ }
30
+ export function whatIs(what) {
31
+ const to = typeof what;
32
+ if (to === 'object') {
42
33
  if (what === null) {
43
- return "null";
34
+ return 'null';
44
35
  }
45
36
  if (Array.isArray(what)) {
46
- return "array";
37
+ return 'array';
47
38
  }
48
- return "object"; // typeof what === 'object' && what === Object(what) && !Array.isArray(what);
39
+ return 'object'; // typeof what === 'object' && what === Object(what) && !Array.isArray(what);
49
40
  }
50
-
51
- if (to === "number") {
41
+ if (to === 'number') {
52
42
  if (Number.isFinite(what)) {
53
43
  if (what % 1 === 0) {
54
- return "integer";
55
- } else {
56
- return "number";
44
+ return 'integer';
45
+ }
46
+ else {
47
+ return 'number';
57
48
  }
58
49
  }
59
50
  if (Number.isNaN(what)) {
60
- return "not-a-number";
51
+ return 'not-a-number';
61
52
  }
62
- return "unknown-number";
53
+ return 'unknown-number';
63
54
  }
64
-
65
55
  return to; // undefined, boolean, string, function
66
-
67
- };
68
-
56
+ }
69
57
  /**
70
58
  *
71
59
  * @param {*} json1
@@ -74,13 +62,10 @@ exports.whatIs = function (what) {
74
62
  *
75
63
  * @returns {boolean}
76
64
  */
77
- exports.areEqual = function areEqual(json1, json2, options) {
78
-
65
+ export function areEqual(json1, json2, options) {
79
66
  options = options || {};
80
- var caseInsensitiveComparison = options.caseInsensitiveComparison || false;
81
-
67
+ const caseInsensitiveComparison = options.caseInsensitiveComparison || false;
82
68
  // http://json-schema.org/latest/json-schema-core.html#rfc.section.3.6
83
-
84
69
  // Two JSON values are said to be equal if and only if:
85
70
  // both are nulls; or
86
71
  // both are booleans, and have the same value; or
@@ -89,15 +74,13 @@ exports.areEqual = function areEqual(json1, json2, options) {
89
74
  if (json1 === json2) {
90
75
  return true;
91
76
  }
92
- if (
93
- caseInsensitiveComparison === true &&
94
- typeof json1 === "string" && typeof json2 === "string" &&
95
- json1.toUpperCase() === json2.toUpperCase()) {
77
+ if (caseInsensitiveComparison === true &&
78
+ typeof json1 === 'string' &&
79
+ typeof json2 === 'string' &&
80
+ json1.toUpperCase() === json2.toUpperCase()) {
96
81
  return true;
97
82
  }
98
-
99
- var i, len;
100
-
83
+ let i, len;
101
84
  // both are arrays, and:
102
85
  if (Array.isArray(json1) && Array.isArray(json2)) {
103
86
  // have the same number of items; and
@@ -113,12 +96,11 @@ exports.areEqual = function areEqual(json1, json2, options) {
113
96
  }
114
97
  return true;
115
98
  }
116
-
117
99
  // both are objects, and:
118
- if (exports.whatIs(json1) === "object" && exports.whatIs(json2) === "object") {
100
+ if (whatIs(json1) === 'object' && whatIs(json2) === 'object') {
119
101
  // have the same set of property names; and
120
- var keys1 = sortedKeys(json1);
121
- var keys2 = sortedKeys(json2);
102
+ const keys1 = sortedKeys(json1);
103
+ const keys2 = sortedKeys(json2);
122
104
  if (!areEqual(keys1, keys2, { caseInsensitiveComparison: caseInsensitiveComparison })) {
123
105
  return false;
124
106
  }
@@ -131,10 +113,8 @@ exports.areEqual = function areEqual(json1, json2, options) {
131
113
  }
132
114
  return true;
133
115
  }
134
-
135
116
  return false;
136
- };
137
-
117
+ }
138
118
  /**
139
119
  *
140
120
  * @param {*[]} arr
@@ -142,19 +122,22 @@ exports.areEqual = function areEqual(json1, json2, options) {
142
122
  *
143
123
  * @returns {boolean}
144
124
  */
145
- exports.isUniqueArray = function (arr, indexes) {
146
- var i, j, l = arr.length;
125
+ export function isUniqueArray(arr, indexes) {
126
+ let i;
127
+ let j;
128
+ const l = arr.length;
147
129
  for (i = 0; i < l; i++) {
148
130
  for (j = i + 1; j < l; j++) {
149
- if (exports.areEqual(arr[i], arr[j])) {
150
- if (indexes) { indexes.push(i, j); }
131
+ if (areEqual(arr[i], arr[j])) {
132
+ if (indexes) {
133
+ indexes.push(i, j);
134
+ }
151
135
  return false;
152
136
  }
153
137
  }
154
138
  }
155
139
  return true;
156
- };
157
-
140
+ }
158
141
  /**
159
142
  *
160
143
  * @param {*} bigSet
@@ -162,77 +145,84 @@ exports.isUniqueArray = function (arr, indexes) {
162
145
  *
163
146
  * @returns {*[]}
164
147
  */
165
- exports.difference = function (bigSet, subSet) {
166
- var arr = [],
167
- idx = bigSet.length;
148
+ export function difference(bigSet, subSet) {
149
+ const arr = [];
150
+ let idx = bigSet.length;
168
151
  while (idx--) {
169
152
  if (subSet.indexOf(bigSet[idx]) === -1) {
170
153
  arr.push(bigSet[idx]);
171
154
  }
172
155
  }
173
156
  return arr;
174
- };
175
-
157
+ }
176
158
  // NOT a deep version of clone
177
- exports.clone = function (src) {
178
- if (typeof src === "undefined") { return void 0; }
179
- if (typeof src !== "object" || src === null) { return src; }
180
- var res, idx;
159
+ export function clone(src) {
160
+ if (typeof src === 'undefined') {
161
+ return void 0;
162
+ }
163
+ if (typeof src !== 'object' || src === null) {
164
+ return src;
165
+ }
166
+ let res, idx;
181
167
  if (Array.isArray(src)) {
182
168
  res = [];
183
169
  idx = src.length;
184
170
  while (idx--) {
185
171
  res[idx] = src[idx];
186
172
  }
187
- } else {
173
+ }
174
+ else {
188
175
  res = {};
189
- var keys = Object.keys(src);
176
+ const keys = Object.keys(src);
190
177
  idx = keys.length;
191
178
  while (idx--) {
192
- var key = keys[idx];
179
+ const key = keys[idx];
193
180
  res[key] = src[key];
194
181
  }
195
182
  }
196
183
  return res;
197
- };
198
-
199
- exports.cloneDeep = function (src) {
200
- var vidx = 0, visited = new Map(), cloned = [];
201
- function cloneDeep(src) {
202
- if (typeof src !== "object" || src === null) { return src; }
203
- var res, idx, cidx;
204
-
205
- cidx = visited.get(src);
206
- if (cidx !== undefined) { return cloned[cidx]; }
207
-
184
+ }
185
+ export function cloneDeep(src) {
186
+ let vidx = 0;
187
+ const visited = new Map();
188
+ const cloned = [];
189
+ function cloneDeepInner(src) {
190
+ if (typeof src !== 'object' || src === null) {
191
+ return src;
192
+ }
193
+ let res;
194
+ let idx;
195
+ const cidx = visited.get(src);
196
+ if (cidx !== undefined) {
197
+ return cloned[cidx];
198
+ }
208
199
  visited.set(src, vidx++);
209
200
  if (Array.isArray(src)) {
210
201
  res = [];
211
202
  cloned.push(res);
212
203
  idx = src.length;
213
204
  while (idx--) {
214
- res[idx] = cloneDeep(src[idx]);
205
+ res[idx] = cloneDeepInner(src[idx]);
215
206
  }
216
- } else {
207
+ }
208
+ else {
217
209
  res = {};
218
210
  cloned.push(res);
219
- var keys = Object.keys(src);
211
+ const keys = Object.keys(src);
220
212
  idx = keys.length;
221
213
  while (idx--) {
222
- var key = keys[idx];
223
- res[key] = cloneDeep(src[key]);
214
+ const key = keys[idx];
215
+ res[key] = cloneDeepInner(src[key]);
224
216
  }
225
217
  }
226
218
  return res;
227
219
  }
228
- return cloneDeep(src);
229
- };
230
-
220
+ return cloneDeepInner(src);
221
+ }
231
222
  /*
232
223
  following function comes from punycode.js library
233
224
  see: https://github.com/bestiejs/punycode.js
234
225
  */
235
- /*jshint -W016*/
236
226
  /**
237
227
  * Creates an array containing the numeric code points of each Unicode
238
228
  * character in the string. While JavaScript uses UCS-2 internally,
@@ -246,29 +236,31 @@ exports.cloneDeep = function (src) {
246
236
  * @param {String} string The Unicode input string (UCS-2).
247
237
  * @returns {Array} The new array of code points.
248
238
  */
249
- exports.ucs2decode = function (string) {
250
- var output = [],
251
- counter = 0,
252
- length = string.length,
253
- value,
254
- extra;
239
+ export function ucs2decode(string) {
240
+ const output = [];
241
+ let counter = 0;
242
+ const length = string.length;
243
+ let value;
244
+ let extra;
255
245
  while (counter < length) {
256
246
  value = string.charCodeAt(counter++);
257
- if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
247
+ if (value >= 0xd800 && value <= 0xdbff && counter < length) {
258
248
  // high surrogate, and there is a next character
259
249
  extra = string.charCodeAt(counter++);
260
- if ((extra & 0xFC00) == 0xDC00) { // low surrogate
261
- output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
262
- } else {
250
+ if ((extra & 0xfc00) == 0xdc00) {
251
+ // low surrogate
252
+ output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
253
+ }
254
+ else {
263
255
  // unmatched surrogate; only append this code unit, in case the next
264
256
  // code unit is the high surrogate of a surrogate pair
265
257
  output.push(value);
266
258
  counter--;
267
259
  }
268
- } else {
260
+ }
261
+ else {
269
262
  output.push(value);
270
263
  }
271
264
  }
272
265
  return output;
273
- };
274
- /*jshint +W016*/
266
+ }