z-schema 3.22.0 → 3.24.2

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/src/Utils.js CHANGED
@@ -1,9 +1,36 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/es6/symbol");
4
+
5
+ exports.jsonSymbol = Symbol.for("z-schema/json");
6
+
7
+ exports.schemaSymbol = Symbol.for("z-schema/schema");
8
+
9
+ /**
10
+ * @param {object} obj
11
+ *
12
+ * @returns {string[]}
13
+ */
14
+ var sortedKeys = exports.sortedKeys = function (obj) {
15
+ return Object.keys(obj).sort();
16
+ };
17
+
18
+ /**
19
+ *
20
+ * @param {string} uri
21
+ *
22
+ * @returns {boolean}
23
+ */
3
24
  exports.isAbsoluteUri = function (uri) {
4
25
  return /^https?:\/\//.test(uri);
5
26
  };
6
27
 
28
+ /**
29
+ *
30
+ * @param {string} uri
31
+ *
32
+ * @returns {boolean}
33
+ */
7
34
  exports.isRelativeUri = function (uri) {
8
35
  // relative URIs that end with a hash sign, issue #56
9
36
  return /.+#/.test(uri);
@@ -41,6 +68,14 @@ exports.whatIs = function (what) {
41
68
 
42
69
  };
43
70
 
71
+ /**
72
+ *
73
+ * @param {*} json1
74
+ * @param {*} json2
75
+ * @param {*} [options]
76
+ *
77
+ * @returns {boolean}
78
+ */
44
79
  exports.areEqual = function areEqual(json1, json2, options) {
45
80
 
46
81
  options = options || {};
@@ -84,8 +119,8 @@ exports.areEqual = function areEqual(json1, json2, options) {
84
119
  // both are objects, and:
85
120
  if (exports.whatIs(json1) === "object" && exports.whatIs(json2) === "object") {
86
121
  // have the same set of property names; and
87
- var keys1 = Object.keys(json1);
88
- var keys2 = Object.keys(json2);
122
+ var keys1 = sortedKeys(json1);
123
+ var keys2 = sortedKeys(json2);
89
124
  if (!areEqual(keys1, keys2, { caseInsensitiveComparison: caseInsensitiveComparison })) {
90
125
  return false;
91
126
  }
@@ -102,6 +137,13 @@ exports.areEqual = function areEqual(json1, json2, options) {
102
137
  return false;
103
138
  };
104
139
 
140
+ /**
141
+ *
142
+ * @param {*[]} arr
143
+ * @param {number[]} [indexes]
144
+ *
145
+ * @returns {boolean}
146
+ */
105
147
  exports.isUniqueArray = function (arr, indexes) {
106
148
  var i, j, l = arr.length;
107
149
  for (i = 0; i < l; i++) {
@@ -115,6 +157,13 @@ exports.isUniqueArray = function (arr, indexes) {
115
157
  return true;
116
158
  };
117
159
 
160
+ /**
161
+ *
162
+ * @param {*} bigSet
163
+ * @param {*} subSet
164
+ *
165
+ * @returns {*[]}
166
+ */
118
167
  exports.difference = function (bigSet, subSet) {
119
168
  var arr = [],
120
169
  idx = bigSet.length;
package/src/ZSchema.js CHANGED
@@ -12,9 +12,9 @@ var Utils = require("./Utils");
12
12
  var Draft4Schema = require("./schemas/schema.json");
13
13
  var Draft4HyperSchema = require("./schemas/hyper-schema.json");
14
14
 
15
- /*
16
- default options
17
- */
15
+ /**
16
+ * default options
17
+ */
18
18
  var defaultOptions = {
19
19
  // default timeout for all async tasks
20
20
  asyncTimeout: 2000,
@@ -108,9 +108,11 @@ function normalizeOptions(options) {
108
108
  return normalized;
109
109
  }
110
110
 
111
- /*
112
- constructor
113
- */
111
+ /**
112
+ * @class
113
+ *
114
+ * @param {*} [options]
115
+ */
114
116
  function ZSchema(options) {
115
117
  this.cache = {};
116
118
  this.referenceCache = [];
@@ -125,9 +127,13 @@ function ZSchema(options) {
125
127
  this.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", Draft4HyperSchema, metaschemaOptions);
126
128
  }
127
129
 
128
- /*
129
- instance methods
130
- */
130
+ /**
131
+ * instance methods
132
+ *
133
+ * @param {*} schema
134
+ *
135
+ * @returns {boolean}
136
+ */
131
137
  ZSchema.prototype.compileSchema = function (schema) {
132
138
  var report = new Report(this.options);
133
139
 
@@ -138,6 +144,13 @@ ZSchema.prototype.compileSchema = function (schema) {
138
144
  this.lastReport = report;
139
145
  return report.isValid();
140
146
  };
147
+
148
+ /**
149
+ *
150
+ * @param {*} schema
151
+ *
152
+ * @returns {boolean}
153
+ */
141
154
  ZSchema.prototype.validateSchema = function (schema) {
142
155
  if (Array.isArray(schema) && schema.length === 0) {
143
156
  throw new Error(".validateSchema was called with an empty array");
@@ -153,6 +166,16 @@ ZSchema.prototype.validateSchema = function (schema) {
153
166
  this.lastReport = report;
154
167
  return report.isValid();
155
168
  };
169
+
170
+ /**
171
+ *
172
+ * @param {*} json
173
+ * @param {*} schema
174
+ * @param {*} [options]
175
+ * @param {function(*, *)} [callback]
176
+ *
177
+ * @returns {boolean}
178
+ */
156
179
  ZSchema.prototype.validate = function (json, schema, options, callback) {
157
180
 
158
181
  if (Utils.whatIs(options) === "function") {
@@ -177,6 +200,7 @@ ZSchema.prototype.validate = function (json, schema, options, callback) {
177
200
 
178
201
  var foundError = false;
179
202
  var report = new Report(this.options);
203
+ report.json = json;
180
204
 
181
205
  if (typeof schema === "string") {
182
206
  var schemaName = schema;
@@ -343,13 +367,22 @@ ZSchema.prototype.getResolvedSchema = function (schema) {
343
367
  throw this.getLastError();
344
368
  }
345
369
  };
370
+
371
+ /**
372
+ *
373
+ * @param {*} schemaReader
374
+ *
375
+ * @returns {void}
376
+ */
346
377
  ZSchema.prototype.setSchemaReader = function (schemaReader) {
347
378
  return ZSchema.setSchemaReader(schemaReader);
348
379
  };
380
+
349
381
  ZSchema.prototype.getSchemaReader = function () {
350
382
  return ZSchema.schemaReader;
351
383
  };
352
384
 
385
+ ZSchema.schemaReader = undefined;
353
386
  /*
354
387
  static methods
355
388
  */
@@ -369,4 +402,8 @@ ZSchema.getDefaultOptions = function () {
369
402
  return Utils.cloneDeep(defaultOptions);
370
403
  };
371
404
 
405
+ ZSchema.schemaSymbol = Utils.schemaSymbol;
406
+
407
+ ZSchema.jsonSymbol = Utils.jsonSymbol;
408
+
372
409
  module.exports = ZSchema;