4 var EXPORTED_SYMBOLS = ["Ajv"];
7 * ajv 4.1.1: Another JSON Schema Validator
9 * https://github.com/epoberezkin/ajv
11 * The MIT License (MIT)
13 * Copyright (c) 2015 Evgeny Poberezkin
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this software and associated documentation files (the "Software"), to deal
17 * in the Software without restriction, including without limitation the rights
18 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 * copies of the Software, and to permit persons to whom the Software is
20 * furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice shall be included in all
23 * copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 // Everything below this comment was taken from the `dist/ajv.bundle.js` in the
35 // ajv node module. (You can get this by running `npm install ajv` in an empty
36 // directory and copying `node_modules/ajv/dist/ajv.bundle.js`).
38 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
47 var util = require('./compile/util');
51 'co*': checkGenerators,
52 'es7': checkAsyncFunction
57 'regenerator': getRegenerator
62 { async: 'es7', transpile: 'nodent' },
63 { async: 'co*', transpile: 'regenerator' }
67 var regenerator, nodent;
70 function setupAsync(opts, required) {
71 if (required !== false) required = true;
72 var async = opts.async
73 , transpile = opts.transpile
76 switch (typeof transpile) {
78 var get = TRANSPILE[transpile];
79 if (!get) throw new Error('bad transpiler: ' + transpile);
80 return (opts._transpileFunc = get(opts, required));
83 if (typeof async == 'string') {
85 if (!check) throw new Error('bad async mode: ' + async);
86 return (opts.transpile = check(opts, required));
89 for (var i=0; i<MODES.length; i++) {
91 if (setupAsync(_opts, false)) {
92 util.copy(_opts, opts);
93 return opts.transpile;
96 /* istanbul ignore next */
97 throw new Error('generators, nodent and regenerator are not available');
99 return (opts._transpileFunc = opts.transpile);
101 throw new Error('bad transpiler: ' + transpile);
106 function checkGenerators(opts, required) {
107 /* jshint evil: true */
109 eval('(function*(){})()');
112 /* istanbul ignore next */
113 if (required) throw new Error('generators not supported');
118 function checkAsyncFunction(opts, required) {
119 /* jshint evil: true */
121 eval('(async function(){})()');
122 /* istanbul ignore next */
125 if (required) throw new Error('es7 async functions not supported');
130 function getRegenerator(opts, required) {
133 regenerator = require('' + 'regenerator');
134 regenerator.runtime();
136 if (!opts.async || opts.async === true)
138 return regeneratorTranspile;
140 /* istanbul ignore next */
141 if (required) throw new Error('regenerator not available');
146 function regeneratorTranspile(code) {
147 return regenerator.compile(code).code;
151 function getNodent(opts, required) {
152 /* jshint evil: true */
154 if (!nodent) nodent = require('' + 'nodent')({ log: false, dontInstallRequireHook: true });
155 if (opts.async != 'es7') {
156 if (opts.async && opts.async !== true) console.warn('nodent transpiles only es7 async functions');
159 return nodentTranspile;
161 /* istanbul ignore next */
162 if (required) throw new Error('nodent not available');
167 function nodentTranspile(code) {
168 return nodent.compile(code, '', { promises: true, sourcemap: false }).code;
173 * Creates validating function for passed schema with asynchronous loading of missing schemas.
174 * `loadSchema` option should be a function that accepts schema uri and node-style callback.
176 * @param {Object} schema schema object
177 * @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function.
179 function compileAsync(schema, callback) {
180 /* eslint no-shadow: 0 */
181 /* jshint validthis: true */
185 schemaObj = this._addSchema(schema);
187 setTimeout(function() { callback(e); });
190 if (schemaObj.validate) {
191 setTimeout(function() { callback(null, schemaObj.validate); });
193 if (typeof this._opts.loadSchema != 'function')
194 throw new Error('options.loadSchema should be a function');
195 _compileAsync(schema, callback, true);
199 function _compileAsync(schema, callback, firstCall) {
201 try { validate = self.compile(schema); }
203 if (e.missingSchema) loadMissingSchema(e);
204 else deferCallback(e);
207 deferCallback(null, validate);
209 function loadMissingSchema(e) {
210 var ref = e.missingSchema;
211 if (self._refs[ref] || self._schemas[ref])
212 return callback(new Error('Schema ' + ref + ' is loaded but' + e.missingRef + 'cannot be resolved'));
213 var _callbacks = self._loadingSchemas[ref];
215 if (typeof _callbacks == 'function')
216 self._loadingSchemas[ref] = [_callbacks, schemaLoaded];
218 _callbacks[_callbacks.length] = schemaLoaded;
220 self._loadingSchemas[ref] = schemaLoaded;
221 self._opts.loadSchema(ref, function (err, sch) {
222 var _callbacks = self._loadingSchemas[ref];
223 delete self._loadingSchemas[ref];
224 if (typeof _callbacks == 'function') {
225 _callbacks(err, sch);
227 for (var i=0; i<_callbacks.length; i++)
228 _callbacks[i](err, sch);
233 function schemaLoaded(err, sch) {
234 if (err) return callback(err);
235 if (!(self._refs[ref] || self._schemas[ref])) {
237 self.addSchema(sch, ref);
243 _compileAsync(schema, callback);
247 function deferCallback(err, validate) {
248 if (firstCall) setTimeout(function() { callback(err, validate); });
249 else return callback(err, validate);
254 },{"./compile/util":10}],2:[function(require,module,exports){
258 var Cache = module.exports = function Cache() {
263 Cache.prototype.put = function Cache_put(key, value) {
264 this._cache[key] = value;
268 Cache.prototype.get = function Cache_get(key) {
269 return this._cache[key];
273 Cache.prototype.del = function Cache_del(key) {
274 delete this._cache[key];
278 Cache.prototype.clear = function Cache_clear() {
282 },{}],3:[function(require,module,exports){
285 //all requires must be explicit because browserify won't work with dynamic requires
287 '$ref': require('../dotjs/ref'),
288 allOf: require('../dotjs/allOf'),
289 anyOf: require('../dotjs/anyOf'),
290 dependencies: require('../dotjs/dependencies'),
291 'enum': require('../dotjs/enum'),
292 format: require('../dotjs/format'),
293 items: require('../dotjs/items'),
294 maximum: require('../dotjs/_limit'),
295 minimum: require('../dotjs/_limit'),
296 maxItems: require('../dotjs/_limitItems'),
297 minItems: require('../dotjs/_limitItems'),
298 maxLength: require('../dotjs/_limitLength'),
299 minLength: require('../dotjs/_limitLength'),
300 maxProperties: require('../dotjs/_limitProperties'),
301 minProperties: require('../dotjs/_limitProperties'),
302 multipleOf: require('../dotjs/multipleOf'),
303 not: require('../dotjs/not'),
304 oneOf: require('../dotjs/oneOf'),
305 pattern: require('../dotjs/pattern'),
306 properties: require('../dotjs/properties'),
307 required: require('../dotjs/required'),
308 uniqueItems: require('../dotjs/uniqueItems'),
309 validate: require('../dotjs/validate')
312 },{"../dotjs/_limit":13,"../dotjs/_limitItems":14,"../dotjs/_limitLength":15,"../dotjs/_limitProperties":16,"../dotjs/allOf":17,"../dotjs/anyOf":18,"../dotjs/dependencies":20,"../dotjs/enum":21,"../dotjs/format":22,"../dotjs/items":23,"../dotjs/multipleOf":24,"../dotjs/not":25,"../dotjs/oneOf":26,"../dotjs/pattern":27,"../dotjs/properties":29,"../dotjs/ref":30,"../dotjs/required":31,"../dotjs/uniqueItems":33,"../dotjs/validate":34}],4:[function(require,module,exports){
315 module.exports = function equal(a, b) {
316 if (a === b) return true;
318 var arrA = Array.isArray(a)
319 , arrB = Array.isArray(b)
323 if (a.length != b.length) return false;
324 for (i = 0; i < a.length; i++)
325 if (!equal(a[i], b[i])) return false;
329 if (arrA != arrB) return false;
331 if (a && b && typeof a === 'object' && typeof b === 'object') {
332 var keys = Object.keys(a);
334 if (keys.length !== Object.keys(b).length) return false;
336 for (i = 0; i < keys.length; i++)
337 if (b[keys[i]] === undefined) return false;
339 for (i = 0; i < keys.length; i++)
340 if(!equal(a[keys[i]], b[keys[i]])) return false;
348 },{}],5:[function(require,module,exports){
351 var util = require('./util');
353 var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/;
354 var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31];
355 var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i;
356 var HOSTNAME = /^[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?(\.[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?)*$/i;
357 var URI = /^(?:[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;
358 var UUID = /^(?:urn\:uuid\:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
359 var JSON_POINTER = /^(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?$|^\#(?:\/(?:[a-z0-9_\-\.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)+)*(?:\/)?$/i;
360 var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:\#|(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?)$/;
363 module.exports = formats;
365 function formats(mode) {
366 mode = mode == 'full' ? 'full' : 'fast';
367 var formatDefs = util.copy(formats[mode]);
368 for (var fName in formats.compare) {
369 formatDefs[fName] = {
370 validate: formatDefs[fName],
371 compare: formats.compare[fName]
379 // date: http://tools.ietf.org/html/rfc3339#section-5.6
380 date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
381 // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
382 time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i,
383 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i,
384 // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
385 uri: /^(?:[a-z][a-z0-9+-.]*)?(?:\:|\/)\/?[^\s]*$/i,
386 // email (sources from jsen validator):
387 // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
388 // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
389 email: /^[a-z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
391 // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
392 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
393 // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
394 ipv6: /^\s*(?:(?:(?:[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}))|:)))(?:%.+)?\s*$/i,
396 // uuid: http://tools.ietf.org/html/rfc4122
398 // JSON-pointer: https://tools.ietf.org/html/rfc6901
399 // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
400 'json-pointer': JSON_POINTER,
401 // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
402 'relative-json-pointer': RELATIVE_JSON_POINTER
409 'date-time': date_time,
411 email: /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
413 ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
414 ipv6: /^\s*(?:(?:(?:[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}))|:)))(?:%.+)?\s*$/i,
417 'json-pointer': JSON_POINTER,
418 'relative-json-pointer': RELATIVE_JSON_POINTER
425 'date-time': compareDateTime
430 // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
431 var matches = str.match(DATE);
432 if (!matches) return false;
434 var month = +matches[1];
435 var day = +matches[2];
436 return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month];
440 function time(str, full) {
441 var matches = str.match(TIME);
442 if (!matches) return false;
444 var hour = matches[1];
445 var minute = matches[2];
446 var second = matches[3];
447 var timeZone = matches[5];
448 return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone);
452 var DATE_TIME_SEPARATOR = /t|\s/i;
453 function date_time(str) {
454 // http://tools.ietf.org/html/rfc3339#section-5.6
455 var dateTime = str.split(DATE_TIME_SEPARATOR);
456 return date(dateTime[0]) && time(dateTime[1], true);
460 function hostname(str) {
461 // http://tools.ietf.org/html/rfc1034#section-3.5
462 return str.length <= 255 && HOSTNAME.test(str);
466 var NOT_URI_FRAGMENT = /\/|\:/;
468 // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
469 return NOT_URI_FRAGMENT.test(str) && URI.test(str);
473 function regex(str) {
483 function compareDate(d1, d2) {
484 if (!(d1 && d2)) return;
485 if (d1 > d2) return 1;
486 if (d1 < d2) return -1;
487 if (d1 === d2) return 0;
491 function compareTime(t1, t2) {
492 if (!(t1 && t2)) return;
495 if (!(t1 && t2)) return;
496 t1 = t1[1] + t1[2] + t1[3] + (t1[4]||'');
497 t2 = t2[1] + t2[2] + t2[3] + (t2[4]||'');
498 if (t1 > t2) return 1;
499 if (t1 < t2) return -1;
500 if (t1 === t2) return 0;
504 function compareDateTime(dt1, dt2) {
505 if (!(dt1 && dt2)) return;
506 dt1 = dt1.split(DATE_TIME_SEPARATOR);
507 dt2 = dt2.split(DATE_TIME_SEPARATOR);
508 var res = compareDate(dt1[0], dt2[0]);
509 if (res === undefined) return;
510 return res || compareTime(dt1[1], dt2[1]);
513 },{"./util":10}],6:[function(require,module,exports){
516 var resolve = require('./resolve')
517 , util = require('./util')
518 , stableStringify = require('json-stable-stringify')
519 , async = require('../async');
521 var beautify = (function() { try { return require('' + 'js-beautify').js_beautify; } catch(e) {/*empty*/} })();
523 var validateGenerator = require('../dotjs/validate');
525 module.exports = compile;
529 * Compiles schema to validation function
531 * @param {Object} schema schema object
532 * @param {Object} root object with information about the root schema for this schema
533 * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
534 * @param {String} baseId base ID for IDs in the schema
535 * @return {Function} validation function
537 function compile(schema, root, localRefs, baseId) {
538 /* jshint validthis: true, evil: true */
539 /* eslint no-shadow: 0 */
542 , refVal = [ undefined ]
550 root = root || { schema: schema, refVal: refVal, refs: refs };
552 var formats = this._formats;
553 var RULES = this.RULES;
555 return localCompile(schema, root, localRefs, baseId);
558 function localCompile(_schema, _root, localRefs, baseId) {
559 var isRoot = !_root || (_root && _root.schema == _schema);
560 if (_root.schema != root.schema)
561 return compile.call(self, _schema, _root, localRefs, baseId);
563 var $async = _schema.$async === true;
564 if ($async && !opts.transpile) async.setup(opts);
566 var sourceCode = validateGenerator({
576 validate: validateGenerator,
579 resolveRef: resolveRef,
580 usePattern: usePattern,
581 useDefault: useDefault,
582 useCustomRule: useCustomRule,
588 sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
589 + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
593 /* istanbul ignore else */
594 if (beautify) sourceCode = beautify(sourceCode, opts.beautify);
595 else console.error('"npm install js-beautify" to use beautify option');
597 // console.log('\n\n\n *** \n', sourceCode);
598 var validate, validateCode
599 , transpile = opts._transpileFunc;
601 validateCode = $async && transpile
602 ? transpile(sourceCode)
605 refVal[0] = validate;
607 console.error('Error compiling schema, function code:', validateCode);
611 validate.schema = _schema;
612 validate.errors = null;
613 validate.refs = refs;
614 validate.refVal = refVal;
615 validate.root = isRoot ? validate : _root;
616 if ($async) validate.$async = true;
617 validate.sourceCode = sourceCode;
622 function resolveRef(baseId, ref, isRoot) {
623 ref = resolve.url(baseId, ref);
624 var refIndex = refs[ref];
625 var _refVal, refCode;
626 if (refIndex !== undefined) {
627 _refVal = refVal[refIndex];
628 refCode = 'refVal[' + refIndex + ']';
629 return resolvedRef(_refVal, refCode);
632 var rootRefId = root.refs[ref];
633 if (rootRefId !== undefined) {
634 _refVal = root.refVal[rootRefId];
635 refCode = addLocalRef(ref, _refVal);
636 return resolvedRef(_refVal, refCode);
640 refCode = addLocalRef(ref);
641 var v = resolve.call(self, localCompile, root, ref);
643 var localSchema = localRefs && localRefs[ref];
645 v = resolve.inlineRef(localSchema, opts.inlineRefs)
647 : compile.call(self, localSchema, root, localRefs, baseId);
652 replaceLocalRef(ref, v);
653 return resolvedRef(v, refCode);
657 function addLocalRef(ref, v) {
658 var refId = refVal.length;
661 return 'refVal' + refId;
664 function replaceLocalRef(ref, v) {
665 var refId = refs[ref];
669 function resolvedRef(refVal, code) {
670 return typeof refVal == 'object'
671 ? { code: code, schema: refVal, inline: true }
672 : { code: code, $async: refVal && refVal.$async };
675 function usePattern(regexStr) {
676 var index = patternsHash[regexStr];
677 if (index === undefined) {
678 index = patternsHash[regexStr] = patterns.length;
679 patterns[index] = regexStr;
681 return 'pattern' + index;
684 function useDefault(value) {
685 switch (typeof value) {
690 return util.toQuotedString(value);
692 if (value === null) return 'null';
693 var valueStr = stableStringify(value);
694 var index = defaultsHash[valueStr];
695 if (index === undefined) {
696 index = defaultsHash[valueStr] = defaults.length;
697 defaults[index] = value;
699 return 'default' + index;
703 function useCustomRule(rule, schema, parentSchema, it) {
704 var compile = rule.definition.compile
705 , inline = rule.definition.inline
706 , macro = rule.definition.macro;
710 validate = compile.call(self, schema, parentSchema);
712 validate = macro.call(self, schema, parentSchema);
713 if (opts.validateSchema !== false) self.validateSchema(validate, true);
715 validate = inline.call(self, it, rule.keyword, schema, parentSchema);
717 validate = rule.definition.validate;
720 var index = customRules.length;
721 customRules[index] = validate;
724 code: 'customRule' + index,
731 function patternCode(i, patterns) {
732 return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
736 function defaultCode(i) {
737 return 'var default' + i + ' = defaults[' + i + '];';
741 function refValCode(i, refVal) {
742 return refVal[i] ? 'var refVal' + i + ' = refVal[' + i + '];' : '';
746 function customRuleCode(i) {
747 return 'var customRule' + i + ' = customRules[' + i + '];';
751 function vars(arr, statement) {
752 if (!arr.length) return '';
754 for (var i=0; i<arr.length; i++)
755 code += statement(i, arr);
760 /*eslint-disable no-unused-vars */
763 * Functions below are used inside compiled validations function
766 var co = require('co');
768 var ucs2length = util.ucs2length;
770 var equal = require('./equal');
772 // this error is thrown by async schemas to return validation errors via exception
773 var ValidationError = require('./validation_error');
775 /*eslint-enable no-unused-vars */
777 },{"../async":1,"../dotjs/validate":34,"./equal":4,"./resolve":7,"./util":10,"./validation_error":11,"co":45,"json-stable-stringify":46}],7:[function(require,module,exports){
780 var url = require('url')
781 , equal = require('./equal')
782 , util = require('./util')
783 , SchemaObject = require('./schema_obj');
785 module.exports = resolve;
787 resolve.normalizeId = normalizeId;
788 resolve.fullPath = getFullPath;
789 resolve.url = resolveUrl;
790 resolve.ids = resolveIds;
791 resolve.inlineRef = inlineRef;
794 * [resolve and compile the references ($ref)]
796 * @param {Function} compile reference to schema compilation funciton (localCompile)
797 * @param {Object} root object with information about the root schema for the current schema
798 * @param {String} ref reference to resolve
799 * @return {Object|Function} schema object (if the schema can be inlined) or validation function
801 function resolve(compile, root, ref) {
802 /* jshint validthis: true */
803 var refVal = this._refs[ref];
804 if (typeof refVal == 'string') {
805 if (this._refs[refVal]) refVal = this._refs[refVal];
806 else return resolve.call(this, compile, root, refVal);
809 refVal = refVal || this._schemas[ref];
810 if (refVal instanceof SchemaObject) {
811 return inlineRef(refVal.schema, this._opts.inlineRefs)
813 : refVal.validate || this._compile(refVal);
816 var res = _resolve.call(this, root, ref);
817 var schema, v, baseId;
824 if (schema instanceof SchemaObject) {
825 v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
827 v = inlineRef(schema, this._opts.inlineRefs)
829 : compile.call(this, schema, root, undefined, baseId);
837 function _resolve(root, ref) {
838 /* jshint validthis: true */
839 var p = url.parse(ref, false, true)
840 , refPath = _getFullPath(p)
841 , baseId = getFullPath(root.schema.id);
842 if (refPath !== baseId) {
843 var id = normalizeId(refPath);
844 var refVal = this._refs[id];
845 if (typeof refVal == 'string') {
846 return resolveRecursive.call(this, root, refVal, p);
847 } else if (refVal instanceof SchemaObject) {
848 if (!refVal.validate) this._compile(refVal);
851 refVal = this._schemas[id];
852 if (refVal instanceof SchemaObject) {
853 if (!refVal.validate) this._compile(refVal);
854 if (id == normalizeId(ref))
855 return { schema: refVal, root: root, baseId: baseId };
859 if (!root.schema) return;
860 baseId = getFullPath(root.schema.id);
862 return getJsonPointer.call(this, p, baseId, root.schema, root);
867 function resolveRecursive(root, ref, parsedRef) {
868 /* jshint validthis: true */
869 var res = _resolve.call(this, root, ref);
871 var schema = res.schema;
872 var baseId = res.baseId;
874 if (schema.id) baseId = resolveUrl(baseId, schema.id);
875 return getJsonPointer.call(this, parsedRef, baseId, schema, root);
880 var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
882 function getJsonPointer(parsedRef, baseId, schema, root) {
883 /* jshint validthis: true */
884 parsedRef.hash = parsedRef.hash || '';
885 if (parsedRef.hash.slice(0,2) != '#/') return;
886 var parts = parsedRef.hash.split('/');
888 for (var i = 1; i < parts.length; i++) {
891 part = util.unescapeFragment(part);
892 schema = schema[part];
894 if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id);
896 var $ref = resolveUrl(baseId, schema.$ref);
897 var res = _resolve.call(this, root, $ref);
906 if (schema && schema != root.schema)
907 return { schema: schema, root: root, baseId: baseId };
911 var SIMPLE_INLINED = util.toHash([
912 'type', 'format', 'pattern',
913 'maxLength', 'minLength',
914 'maxProperties', 'minProperties',
915 'maxItems', 'minItems',
916 'maximum', 'minimum',
917 'uniqueItems', 'multipleOf',
920 function inlineRef(schema, limit) {
921 if (limit === false) return false;
922 if (limit === undefined || limit === true) return checkNoRef(schema);
923 else if (limit) return countKeys(schema) <= limit;
927 function checkNoRef(schema) {
929 if (Array.isArray(schema)) {
930 for (var i=0; i<schema.length; i++) {
932 if (typeof item == 'object' && !checkNoRef(item)) return false;
935 for (var key in schema) {
936 if (key == '$ref') return false;
938 if (typeof item == 'object' && !checkNoRef(item)) return false;
945 function countKeys(schema) {
947 if (Array.isArray(schema)) {
948 for (var i=0; i<schema.length; i++) {
950 if (typeof item == 'object') count += countKeys(item);
951 if (count == Infinity) return Infinity;
954 for (var key in schema) {
955 if (key == '$ref') return Infinity;
956 if (SIMPLE_INLINED[key]) {
960 if (typeof item == 'object') count += countKeys(item) + 1;
961 if (count == Infinity) return Infinity;
969 function getFullPath(id, normalize) {
970 if (normalize !== false) id = normalizeId(id);
971 var p = url.parse(id, false, true);
972 return _getFullPath(p);
976 function _getFullPath(p) {
977 return (p.protocol||'') + (p.protocol?'//':'') + (p.host||'') + (p.path||'') + '#';
981 var TRAILING_SLASH_HASH = /#\/?$/;
982 function normalizeId(id) {
983 return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
987 function resolveUrl(baseId, id) {
988 id = normalizeId(id);
989 return url.resolve(baseId, id);
994 function resolveIds(schema) {
995 /* eslint no-shadow: 0 */
996 /* jshint validthis: true */
997 var id = normalizeId(schema.id);
999 _resolveIds.call(this, schema, getFullPath(id, false), id);
1003 function _resolveIds(schema, fullPath, baseId) {
1004 /* jshint validthis: true */
1005 if (Array.isArray(schema)) {
1006 for (var i=0; i<schema.length; i++)
1007 _resolveIds.call(this, schema[i], fullPath+'/'+i, baseId);
1008 } else if (schema && typeof schema == 'object') {
1009 if (typeof schema.id == 'string') {
1010 var id = baseId = baseId
1011 ? url.resolve(baseId, schema.id)
1013 id = normalizeId(id);
1015 var refVal = this._refs[id];
1016 if (typeof refVal == 'string') refVal = this._refs[refVal];
1017 if (refVal && refVal.schema) {
1018 if (!equal(schema, refVal.schema))
1019 throw new Error('id "' + id + '" resolves to more than one schema');
1020 } else if (id != normalizeId(fullPath)) {
1022 if (localRefs[id] && !equal(schema, localRefs[id]))
1023 throw new Error('id "' + id + '" resolves to more than one schema');
1024 localRefs[id] = schema;
1026 this._refs[id] = fullPath;
1030 for (var key in schema)
1031 _resolveIds.call(this, schema[key], fullPath+'/'+util.escapeFragment(key), baseId);
1036 },{"./equal":4,"./schema_obj":9,"./util":10,"url":43}],8:[function(require,module,exports){
1039 var ruleModules = require('./_rules')
1040 , util = require('./util');
1042 module.exports = function rules() {
1045 rules: [ 'maximum', 'minimum', 'multipleOf'] },
1047 rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
1049 rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
1051 rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
1052 { rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
1055 RULES.all = [ 'type', 'additionalProperties', 'patternProperties' ];
1056 RULES.keywords = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ];
1057 RULES.types = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
1059 RULES.forEach(function (group) {
1060 group.rules = group.rules.map(function (keyword) {
1061 RULES.all.push(keyword);
1064 code: ruleModules[keyword]
1069 RULES.keywords = util.toHash(RULES.all.concat(RULES.keywords));
1070 RULES.all = util.toHash(RULES.all);
1071 RULES.types = util.toHash(RULES.types);
1076 },{"./_rules":3,"./util":10}],9:[function(require,module,exports){
1079 var util = require('./util');
1081 module.exports = SchemaObject;
1083 function SchemaObject(obj) {
1084 util.copy(obj, this);
1087 },{"./util":10}],10:[function(require,module,exports){
1093 checkDataType: checkDataType,
1094 checkDataTypes: checkDataTypes,
1095 coerceToTypes: coerceToTypes,
1097 getProperty: getProperty,
1098 escapeQuotes: escapeQuotes,
1099 ucs2length: ucs2length,
1100 varOccurences: varOccurences,
1101 varReplace: varReplace,
1102 cleanUpCode: cleanUpCode,
1103 cleanUpVarErrors: cleanUpVarErrors,
1104 schemaHasRules: schemaHasRules,
1105 stableStringify: require('json-stable-stringify'),
1106 toQuotedString: toQuotedString,
1107 getPathExpr: getPathExpr,
1110 unescapeFragment: unescapeFragment,
1111 escapeFragment: escapeFragment,
1112 escapeJsonPointer: escapeJsonPointer
1116 function copy(o, to) {
1118 for (var key in o) to[key] = o[key];
1123 function checkDataType(dataType, data, negate) {
1124 var EQUAL = negate ? ' !== ' : ' === '
1125 , AND = negate ? ' || ' : ' && '
1126 , OK = negate ? '!' : ''
1127 , NOT = negate ? '' : '!';
1129 case 'null': return data + EQUAL + 'null';
1130 case 'array': return OK + 'Array.isArray(' + data + ')';
1131 case 'object': return '(' + OK + data + AND +
1132 'typeof ' + data + EQUAL + '"object"' + AND +
1133 NOT + 'Array.isArray(' + data + '))';
1134 case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
1135 NOT + '(' + data + ' % 1)' +
1136 AND + data + EQUAL + data + ')';
1137 default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
1142 function checkDataTypes(dataTypes, data) {
1143 switch (dataTypes.length) {
1144 case 1: return checkDataType(dataTypes[0], data, true);
1147 var types = toHash(dataTypes);
1148 if (types.array && types.object) {
1149 code = types.null ? '(': '(!' + data + ' || ';
1150 code += 'typeof ' + data + ' !== "object")';
1153 delete types.object;
1155 if (types.number) delete types.integer;
1156 for (var t in types)
1157 code += (code ? ' && ' : '' ) + checkDataType(t, data, true);
1164 var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
1165 function coerceToTypes(dataTypes) {
1166 if (Array.isArray(dataTypes)) {
1168 for (var i=0; i<dataTypes.length; i++) {
1169 var t = dataTypes[i];
1170 if (COERCE_TO_TYPES[t]) types[types.length] = t;
1172 if (types.length) return types;
1173 } else if (COERCE_TO_TYPES[dataTypes]) {
1179 function toHash(arr) {
1181 for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
1186 var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
1187 var SINGLE_QUOTE = /'|\\/g;
1188 function getProperty(key) {
1189 return typeof key == 'number'
1191 : IDENTIFIER.test(key)
1193 : "['" + key.replace(SINGLE_QUOTE, '\\$&') + "']";
1197 function escapeQuotes(str) {
1198 return str.replace(SINGLE_QUOTE, '\\$&');
1202 // https://mathiasbynens.be/notes/javascript-encoding
1203 // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
1204 function ucs2length(str) {
1211 value = str.charCodeAt(pos++);
1212 if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
1213 // high surrogate, and there is a next character
1214 value = str.charCodeAt(pos);
1215 if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
1222 function varOccurences(str, dataVar) {
1223 dataVar += '[^0-9]';
1224 var matches = str.match(new RegExp(dataVar, 'g'));
1225 return matches ? matches.length : 0;
1229 function varReplace(str, dataVar, expr) {
1230 dataVar += '([^0-9])';
1231 expr = expr.replace(/\$/g, '$$$$');
1232 return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
1236 var EMPTY_ELSE = /else\s*{\s*}/g
1237 , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g
1238 , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g;
1239 function cleanUpCode(out) {
1240 return out.replace(EMPTY_ELSE, '')
1241 .replace(EMPTY_IF_NO_ELSE, '')
1242 .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))');
1246 var ERRORS_REGEXP = /[^v\.]errors/g
1247 , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g
1248 , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g
1249 , RETURN_VALID = 'return errors === 0;'
1250 , RETURN_TRUE = 'validate.errors = null; return true;'
1251 , RETURN_ASYNC = /if \(errors === 0\) return true;\s*else throw new ValidationError\(vErrors\);/
1252 , RETURN_TRUE_ASYNC = 'return true;';
1254 function cleanUpVarErrors(out, async) {
1255 var matches = out.match(ERRORS_REGEXP);
1256 if (!matches || matches.length !== 2) return out;
1258 ? out.replace(REMOVE_ERRORS_ASYNC, '')
1259 .replace(RETURN_ASYNC, RETURN_TRUE_ASYNC)
1260 : out.replace(REMOVE_ERRORS, '')
1261 .replace(RETURN_VALID, RETURN_TRUE);
1265 function schemaHasRules(schema, rules) {
1266 for (var key in schema) if (rules[key]) return true;
1270 function toQuotedString(str) {
1271 return '\'' + escapeQuotes(str) + '\'';
1275 function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
1276 var path = jsonPointers // false by default
1277 ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
1278 : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
1279 return joinPaths(currentPath, path);
1283 function getPath(currentPath, prop, jsonPointers) {
1284 var path = jsonPointers // false by default
1285 ? toQuotedString('/' + escapeJsonPointer(prop))
1286 : toQuotedString(getProperty(prop));
1287 return joinPaths(currentPath, path);
1291 var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
1292 function getData($data, lvl, paths) {
1293 var matches = $data.match(RELATIVE_JSON_POINTER);
1294 if (!matches) throw new Error('Invalid relative JSON-pointer: ' + $data);
1295 var up = +matches[1];
1296 var jsonPointer = matches[2];
1297 if (jsonPointer == '#') {
1298 if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
1299 return paths[lvl - up];
1302 if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
1303 var data = 'data' + ((lvl - up) || '');
1304 if (!jsonPointer) return data;
1307 var segments = jsonPointer.split('/');
1308 for (var i=0; i<segments.length; i++) {
1309 var segment = segments[i];
1311 data += getProperty(unescapeJsonPointer(segment));
1312 expr += ' && ' + data;
1319 function joinPaths (a, b) {
1320 if (a == '""') return b;
1321 return (a + ' + ' + b).replace(/' \+ '/g, '');
1325 function unescapeFragment(str) {
1326 return unescapeJsonPointer(decodeURIComponent(str));
1330 function escapeFragment(str) {
1331 return encodeURIComponent(escapeJsonPointer(str));
1335 function escapeJsonPointer(str) {
1336 return str.replace(/~/g, '~0').replace(/\//g, '~1');
1340 function unescapeJsonPointer(str) {
1341 return str.replace(/~1/g, '/').replace(/~0/g, '~');
1344 },{"json-stable-stringify":46}],11:[function(require,module,exports){
1347 module.exports = ValidationError;
1350 function ValidationError(errors) {
1351 this.message = 'validation failed';
1352 this.errors = errors;
1353 this.ajv = this.validation = true;
1357 ValidationError.prototype = Object.create(Error.prototype);
1358 ValidationError.prototype.constructor = ValidationError;
1360 },{}],12:[function(require,module,exports){
1362 module.exports = function generate__formatLimit(it, $keyword) {
1364 var $lvl = it.level;
1365 var $dataLvl = it.dataLevel;
1366 var $schema = it.schema[$keyword];
1367 var $schemaPath = it.schemaPath + '.' + $keyword;
1368 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1369 var $breakOnError = !it.opts.allErrors;
1371 var $data = 'data' + ($dataLvl || '');
1372 var $valid = 'valid' + $lvl;
1373 out += 'var ' + ($valid) + ' = undefined;';
1374 if (it.opts.format === false) {
1375 out += ' ' + ($valid) + ' = true; ';
1378 var $schemaFormat = it.schema.format,
1379 $isDataFormat = it.opts.v5 && $schemaFormat.$data,
1380 $closingBraces = '';
1381 if ($isDataFormat) {
1382 var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr),
1383 $format = 'format' + $lvl,
1384 $compare = 'compare' + $lvl;
1385 out += ' var ' + ($format) + ' = formats[' + ($schemaValueFormat) + '] , ' + ($compare) + ' = ' + ($format) + ' && ' + ($format) + '.compare;';
1387 var $format = it.formats[$schemaFormat];
1388 if (!($format && $format.compare)) {
1389 out += ' ' + ($valid) + ' = true; ';
1392 var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare';
1394 var $isMax = $keyword == 'formatMaximum',
1395 $exclusiveKeyword = 'formatExclusive' + ($isMax ? 'Maximum' : 'Minimum'),
1396 $schemaExcl = it.schema[$exclusiveKeyword],
1397 $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
1398 $op = $isMax ? '<' : '>',
1399 $result = 'result' + $lvl;
1400 var $isData = it.opts.v5 && $schema.$data;
1401 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
1403 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1404 $schemaValue = 'schema' + $lvl;
1407 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
1408 $exclusive = 'exclusive' + $lvl,
1409 $opExpr = 'op' + $lvl,
1410 $opStr = '\' + ' + $opExpr + ' + \'';
1411 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
1412 $schemaValueExcl = 'schemaExcl' + $lvl;
1413 out += ' if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && ' + ($schemaValueExcl) + ' !== undefined) { ' + ($valid) + ' = false; ';
1414 var $errorKeyword = $exclusiveKeyword;
1415 var $$outStack = $$outStack || [];
1416 $$outStack.push(out);
1417 out = ''; /* istanbul ignore else */
1418 if (it.createErrors !== false) {
1419 out += ' { keyword: \'' + ($errorKeyword || '_formatExclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
1420 if (it.opts.messages !== false) {
1421 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
1423 if (it.opts.verbose) {
1424 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1431 out = $$outStack.pop();
1432 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1434 out += ' throw new ValidationError([' + (__err) + ']); ';
1436 out += ' validate.errors = [' + (__err) + ']; return false; ';
1439 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1442 if ($breakOnError) {
1443 $closingBraces += '}';
1447 out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
1448 $closingBraces += '}';
1450 if ($isDataFormat) {
1451 out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
1452 $closingBraces += '}';
1454 out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
1456 out += '' + ($schemaValue);
1458 out += '' + (it.util.toQuotedString($schema));
1460 out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; var ' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true; if (' + ($valid) + ' === undefined) { ' + ($valid) + ' = ' + ($exclusive) + ' ? ' + ($result) + ' ' + ($op) + ' 0 : ' + ($result) + ' ' + ($op) + '= 0; } if (!' + ($valid) + ') var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
1462 var $exclusive = $schemaExcl === true,
1464 if (!$exclusive) $opStr += '=';
1465 var $opExpr = '\'' + $opStr + '\'';
1467 out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
1468 $closingBraces += '}';
1470 if ($isDataFormat) {
1471 out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
1472 $closingBraces += '}';
1474 out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
1476 out += '' + ($schemaValue);
1478 out += '' + (it.util.toQuotedString($schema));
1480 out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; if (' + ($valid) + ' === undefined) ' + ($valid) + ' = ' + ($result) + ' ' + ($op);
1486 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
1487 var $errorKeyword = $keyword;
1488 var $$outStack = $$outStack || [];
1489 $$outStack.push(out);
1490 out = ''; /* istanbul ignore else */
1491 if (it.createErrors !== false) {
1492 out += ' { keyword: \'' + ($errorKeyword || '_formatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { comparison: ' + ($opExpr) + ', limit: ';
1494 out += '' + ($schemaValue);
1496 out += '' + (it.util.toQuotedString($schema));
1498 out += ' , exclusive: ' + ($exclusive) + ' } ';
1499 if (it.opts.messages !== false) {
1500 out += ' , message: \'should be ' + ($opStr) + ' "';
1502 out += '\' + ' + ($schemaValue) + ' + \'';
1504 out += '' + (it.util.escapeQuotes($schema));
1508 if (it.opts.verbose) {
1509 out += ' , schema: ';
1511 out += 'validate.schema' + ($schemaPath);
1513 out += '' + (it.util.toQuotedString($schema));
1515 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1522 out = $$outStack.pop();
1523 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1525 out += ' throw new ValidationError([' + (__err) + ']); ';
1527 out += ' validate.errors = [' + (__err) + ']; return false; ';
1530 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1536 },{}],13:[function(require,module,exports){
1538 module.exports = function generate__limit(it, $keyword) {
1540 var $lvl = it.level;
1541 var $dataLvl = it.dataLevel;
1542 var $schema = it.schema[$keyword];
1543 var $schemaPath = it.schemaPath + '.' + $keyword;
1544 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1545 var $breakOnError = !it.opts.allErrors;
1547 var $data = 'data' + ($dataLvl || '');
1548 var $isData = it.opts.v5 && $schema.$data;
1549 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
1551 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1552 $schemaValue = 'schema' + $lvl;
1554 var $isMax = $keyword == 'maximum',
1555 $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
1556 $schemaExcl = it.schema[$exclusiveKeyword],
1557 $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
1558 $op = $isMax ? '<' : '>',
1559 $notOp = $isMax ? '>' : '<';
1561 var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
1562 $exclusive = 'exclusive' + $lvl,
1563 $opExpr = 'op' + $lvl,
1564 $opStr = '\' + ' + $opExpr + ' + \'';
1565 out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
1566 $schemaValueExcl = 'schemaExcl' + $lvl;
1567 out += ' var exclusive' + ($lvl) + '; if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && typeof ' + ($schemaValueExcl) + ' != \'undefined\') { ';
1568 var $errorKeyword = $exclusiveKeyword;
1569 var $$outStack = $$outStack || [];
1570 $$outStack.push(out);
1571 out = ''; /* istanbul ignore else */
1572 if (it.createErrors !== false) {
1573 out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
1574 if (it.opts.messages !== false) {
1575 out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
1577 if (it.opts.verbose) {
1578 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1585 out = $$outStack.pop();
1586 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1588 out += ' throw new ValidationError([' + (__err) + ']); ';
1590 out += ' validate.errors = [' + (__err) + ']; return false; ';
1593 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1595 out += ' } else if( ';
1597 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1599 out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ') || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
1601 var $exclusive = $schemaExcl === true,
1603 if (!$exclusive) $opStr += '=';
1604 var $opExpr = '\'' + $opStr + '\'';
1607 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1609 out += ' ' + ($data) + ' ' + ($notOp);
1613 out += ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') {';
1615 var $errorKeyword = $keyword;
1616 var $$outStack = $$outStack || [];
1617 $$outStack.push(out);
1618 out = ''; /* istanbul ignore else */
1619 if (it.createErrors !== false) {
1620 out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
1621 if (it.opts.messages !== false) {
1622 out += ' , message: \'should be ' + ($opStr) + ' ';
1624 out += '\' + ' + ($schemaValue);
1626 out += '' + ($schema) + '\'';
1629 if (it.opts.verbose) {
1630 out += ' , schema: ';
1632 out += 'validate.schema' + ($schemaPath);
1634 out += '' + ($schema);
1636 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1643 out = $$outStack.pop();
1644 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1646 out += ' throw new ValidationError([' + (__err) + ']); ';
1648 out += ' validate.errors = [' + (__err) + ']; return false; ';
1651 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1654 if ($breakOnError) {
1660 },{}],14:[function(require,module,exports){
1662 module.exports = function generate__limitItems(it, $keyword) {
1664 var $lvl = it.level;
1665 var $dataLvl = it.dataLevel;
1666 var $schema = it.schema[$keyword];
1667 var $schemaPath = it.schemaPath + '.' + $keyword;
1668 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1669 var $breakOnError = !it.opts.allErrors;
1671 var $data = 'data' + ($dataLvl || '');
1672 var $isData = it.opts.v5 && $schema.$data;
1673 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
1675 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1676 $schemaValue = 'schema' + $lvl;
1678 var $op = $keyword == 'maxItems' ? '>' : '<';
1681 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1683 out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1684 var $errorKeyword = $keyword;
1685 var $$outStack = $$outStack || [];
1686 $$outStack.push(out);
1687 out = ''; /* istanbul ignore else */
1688 if (it.createErrors !== false) {
1689 out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
1690 if (it.opts.messages !== false) {
1691 out += ' , message: \'should NOT have ';
1692 if ($keyword == 'maxItems') {
1699 out += '\' + ' + ($schemaValue) + ' + \'';
1701 out += '' + ($schema);
1705 if (it.opts.verbose) {
1706 out += ' , schema: ';
1708 out += 'validate.schema' + ($schemaPath);
1710 out += '' + ($schema);
1712 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1719 out = $$outStack.pop();
1720 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1722 out += ' throw new ValidationError([' + (__err) + ']); ';
1724 out += ' validate.errors = [' + (__err) + ']; return false; ';
1727 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1730 if ($breakOnError) {
1736 },{}],15:[function(require,module,exports){
1738 module.exports = function generate__limitLength(it, $keyword) {
1740 var $lvl = it.level;
1741 var $dataLvl = it.dataLevel;
1742 var $schema = it.schema[$keyword];
1743 var $schemaPath = it.schemaPath + '.' + $keyword;
1744 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1745 var $breakOnError = !it.opts.allErrors;
1747 var $data = 'data' + ($dataLvl || '');
1748 var $isData = it.opts.v5 && $schema.$data;
1749 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
1751 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1752 $schemaValue = 'schema' + $lvl;
1754 var $op = $keyword == 'maxLength' ? '>' : '<';
1757 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1759 if (it.opts.unicode === false) {
1760 out += ' ' + ($data) + '.length ';
1762 out += ' ucs2length(' + ($data) + ') ';
1764 out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
1765 var $errorKeyword = $keyword;
1766 var $$outStack = $$outStack || [];
1767 $$outStack.push(out);
1768 out = ''; /* istanbul ignore else */
1769 if (it.createErrors !== false) {
1770 out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
1771 if (it.opts.messages !== false) {
1772 out += ' , message: \'should NOT be ';
1773 if ($keyword == 'maxLength') {
1780 out += '\' + ' + ($schemaValue) + ' + \'';
1782 out += '' + ($schema);
1784 out += ' characters\' ';
1786 if (it.opts.verbose) {
1787 out += ' , schema: ';
1789 out += 'validate.schema' + ($schemaPath);
1791 out += '' + ($schema);
1793 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1800 out = $$outStack.pop();
1801 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1803 out += ' throw new ValidationError([' + (__err) + ']); ';
1805 out += ' validate.errors = [' + (__err) + ']; return false; ';
1808 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1811 if ($breakOnError) {
1817 },{}],16:[function(require,module,exports){
1819 module.exports = function generate__limitProperties(it, $keyword) {
1821 var $lvl = it.level;
1822 var $dataLvl = it.dataLevel;
1823 var $schema = it.schema[$keyword];
1824 var $schemaPath = it.schemaPath + '.' + $keyword;
1825 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1826 var $breakOnError = !it.opts.allErrors;
1828 var $data = 'data' + ($dataLvl || '');
1829 var $isData = it.opts.v5 && $schema.$data;
1830 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
1832 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1833 $schemaValue = 'schema' + $lvl;
1835 var $op = $keyword == 'maxProperties' ? '>' : '<';
1838 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1840 out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
1841 var $errorKeyword = $keyword;
1842 var $$outStack = $$outStack || [];
1843 $$outStack.push(out);
1844 out = ''; /* istanbul ignore else */
1845 if (it.createErrors !== false) {
1846 out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } ';
1847 if (it.opts.messages !== false) {
1848 out += ' , message: \'should NOT have ';
1849 if ($keyword == 'maxProperties') {
1856 out += '\' + ' + ($schemaValue) + ' + \'';
1858 out += '' + ($schema);
1860 out += ' properties\' ';
1862 if (it.opts.verbose) {
1863 out += ' , schema: ';
1865 out += 'validate.schema' + ($schemaPath);
1867 out += '' + ($schema);
1869 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1876 out = $$outStack.pop();
1877 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1879 out += ' throw new ValidationError([' + (__err) + ']); ';
1881 out += ' validate.errors = [' + (__err) + ']; return false; ';
1884 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1887 if ($breakOnError) {
1893 },{}],17:[function(require,module,exports){
1895 module.exports = function generate_allOf(it, $keyword) {
1897 var $schema = it.schema[$keyword];
1898 var $schemaPath = it.schemaPath + '.' + $keyword;
1899 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1900 var $breakOnError = !it.opts.allErrors;
1901 var $it = it.util.copy(it);
1902 var $closingBraces = '';
1904 var $currentBaseId = $it.baseId;
1908 l1 = arr1.length - 1;
1910 $sch = arr1[$i += 1];
1911 if (it.util.schemaHasRules($sch, it.RULES.all)) {
1913 $it.schemaPath = $schemaPath + '[' + $i + ']';
1914 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1915 out += ' ' + (it.validate($it)) + ' ';
1916 $it.baseId = $currentBaseId;
1917 if ($breakOnError) {
1918 out += ' if (valid' + ($it.level) + ') { ';
1919 $closingBraces += '}';
1924 if ($breakOnError) {
1925 out += ' ' + ($closingBraces.slice(0, -1));
1927 out = it.util.cleanUpCode(out);
1931 },{}],18:[function(require,module,exports){
1933 module.exports = function generate_anyOf(it, $keyword) {
1935 var $lvl = it.level;
1936 var $dataLvl = it.dataLevel;
1937 var $schema = it.schema[$keyword];
1938 var $schemaPath = it.schemaPath + '.' + $keyword;
1939 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
1940 var $breakOnError = !it.opts.allErrors;
1942 var $data = 'data' + ($dataLvl || '');
1943 var $valid = 'valid' + $lvl;
1944 var $errs = 'errs__' + $lvl;
1945 var $it = it.util.copy(it);
1946 var $closingBraces = '';
1948 var $noEmptySchema = $schema.every(function($sch) {
1949 return it.util.schemaHasRules($sch, it.RULES.all);
1951 if ($noEmptySchema) {
1952 var $currentBaseId = $it.baseId;
1953 out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
1954 var $wasComposite = it.compositeRule;
1955 it.compositeRule = $it.compositeRule = true;
1959 l1 = arr1.length - 1;
1961 $sch = arr1[$i += 1];
1963 $it.schemaPath = $schemaPath + '[' + $i + ']';
1964 $it.errSchemaPath = $errSchemaPath + '/' + $i;
1965 out += ' ' + (it.validate($it)) + ' ';
1966 $it.baseId = $currentBaseId;
1967 out += ' ' + ($valid) + ' = ' + ($valid) + ' || valid' + ($it.level) + '; if (!' + ($valid) + ') { ';
1968 $closingBraces += '}';
1971 it.compositeRule = $it.compositeRule = $wasComposite;
1972 out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
1973 if (it.createErrors !== false) {
1974 out += ' { keyword: \'' + ($errorKeyword || 'anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
1975 if (it.opts.messages !== false) {
1976 out += ' , message: \'should match some schema in anyOf\' ';
1978 if (it.opts.verbose) {
1979 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1985 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
1986 if (it.opts.allErrors) {
1989 out = it.util.cleanUpCode(out);
1991 if ($breakOnError) {
1992 out += ' if (true) { ';
1998 },{}],19:[function(require,module,exports){
2000 module.exports = function generate_constant(it, $keyword) {
2002 var $lvl = it.level;
2003 var $dataLvl = it.dataLevel;
2004 var $schema = it.schema[$keyword];
2005 var $schemaPath = it.schemaPath + '.' + $keyword;
2006 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2007 var $breakOnError = !it.opts.allErrors;
2009 var $data = 'data' + ($dataLvl || '');
2010 var $valid = 'valid' + $lvl;
2011 var $isData = it.opts.v5 && $schema.$data;
2012 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2014 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2015 $schemaValue = 'schema' + $lvl;
2018 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
2020 out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
2021 var $$outStack = $$outStack || [];
2022 $$outStack.push(out);
2023 out = ''; /* istanbul ignore else */
2024 if (it.createErrors !== false) {
2025 out += ' { keyword: \'' + ($errorKeyword || 'constant') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
2026 if (it.opts.messages !== false) {
2027 out += ' , message: \'should be equal to constant\' ';
2029 if (it.opts.verbose) {
2030 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2037 out = $$outStack.pop();
2038 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2040 out += ' throw new ValidationError([' + (__err) + ']); ';
2042 out += ' validate.errors = [' + (__err) + ']; return false; ';
2045 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2051 },{}],20:[function(require,module,exports){
2053 module.exports = function generate_dependencies(it, $keyword) {
2055 var $lvl = it.level;
2056 var $dataLvl = it.dataLevel;
2057 var $schema = it.schema[$keyword];
2058 var $schemaPath = it.schemaPath + '.' + $keyword;
2059 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2060 var $breakOnError = !it.opts.allErrors;
2062 var $data = 'data' + ($dataLvl || '');
2063 var $errs = 'errs__' + $lvl;
2064 var $it = it.util.copy(it);
2065 var $closingBraces = '';
2067 var $schemaDeps = {},
2069 for ($property in $schema) {
2070 var $sch = $schema[$property];
2071 var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
2072 $deps[$property] = $sch;
2074 out += 'var ' + ($errs) + ' = errors;';
2075 var $currentErrorPath = it.errorPath;
2076 out += 'var missing' + ($lvl) + ';';
2077 for (var $property in $propertyDeps) {
2078 $deps = $propertyDeps[$property];
2079 out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
2080 if ($breakOnError) {
2084 var _$property, $i = -1,
2085 l1 = arr1.length - 1;
2087 _$property = arr1[$i += 1];
2091 var $prop = it.util.getProperty(_$property);
2092 out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
2096 var $propertyPath = 'missing' + $lvl,
2097 $missingProperty = '\' + ' + $propertyPath + ' + \'';
2098 if (it.opts._errorDataPathProperty) {
2099 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
2101 var $$outStack = $$outStack || [];
2102 $$outStack.push(out);
2103 out = ''; /* istanbul ignore else */
2104 if (it.createErrors !== false) {
2105 out += ' { keyword: \'' + ($errorKeyword || 'dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
2106 if (it.opts.messages !== false) {
2107 out += ' , message: \'should have ';
2108 if ($deps.length == 1) {
2109 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2111 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2113 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2115 if (it.opts.verbose) {
2116 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2123 out = $$outStack.pop();
2124 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2126 out += ' throw new ValidationError([' + (__err) + ']); ';
2128 out += ' validate.errors = [' + (__err) + ']; return false; ';
2131 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2137 var $reqProperty, i2 = -1,
2138 l2 = arr2.length - 1;
2140 $reqProperty = arr2[i2 += 1];
2141 var $prop = it.util.getProperty($reqProperty),
2142 $missingProperty = it.util.escapeQuotes($reqProperty);
2143 if (it.opts._errorDataPathProperty) {
2144 it.errorPath = it.util.getPath($currentErrorPath, $reqProperty, it.opts.jsonPointers);
2146 out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */
2147 if (it.createErrors !== false) {
2148 out += ' { keyword: \'' + ($errorKeyword || 'dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
2149 if (it.opts.messages !== false) {
2150 out += ' , message: \'should have ';
2151 if ($deps.length == 1) {
2152 out += 'property ' + (it.util.escapeQuotes($deps[0]));
2154 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2156 out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2158 if (it.opts.verbose) {
2159 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2165 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2170 if ($breakOnError) {
2171 $closingBraces += '}';
2175 it.errorPath = $currentErrorPath;
2176 var $currentBaseId = $it.baseId;
2177 for (var $property in $schemaDeps) {
2178 var $sch = $schemaDeps[$property];
2179 if (it.util.schemaHasRules($sch, it.RULES.all)) {
2180 out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { ';
2182 $it.schemaPath = $schemaPath + it.util.getProperty($property);
2183 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
2184 out += ' ' + (it.validate($it)) + ' ';
2185 $it.baseId = $currentBaseId;
2187 if ($breakOnError) {
2188 out += ' if (valid' + ($it.level) + ') { ';
2189 $closingBraces += '}';
2193 if ($breakOnError) {
2194 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2196 out = it.util.cleanUpCode(out);
2200 },{}],21:[function(require,module,exports){
2202 module.exports = function generate_enum(it, $keyword) {
2204 var $lvl = it.level;
2205 var $dataLvl = it.dataLevel;
2206 var $schema = it.schema[$keyword];
2207 var $schemaPath = it.schemaPath + '.' + $keyword;
2208 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2209 var $breakOnError = !it.opts.allErrors;
2211 var $data = 'data' + ($dataLvl || '');
2212 var $valid = 'valid' + $lvl;
2213 var $isData = it.opts.v5 && $schema.$data;
2214 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2216 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2217 $schemaValue = 'schema' + $lvl;
2219 var $i = 'i' + $lvl;
2221 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
2223 out += 'var ' + ($valid) + ';';
2225 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
2227 out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<schema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', schema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
2231 out += ' if (!' + ($valid) + ') { ';
2232 var $$outStack = $$outStack || [];
2233 $$outStack.push(out);
2234 out = ''; /* istanbul ignore else */
2235 if (it.createErrors !== false) {
2236 out += ' { keyword: \'' + ($errorKeyword || 'enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
2237 if (it.opts.messages !== false) {
2238 out += ' , message: \'should be equal to one of the allowed values\' ';
2240 if (it.opts.verbose) {
2241 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2248 out = $$outStack.pop();
2249 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2251 out += ' throw new ValidationError([' + (__err) + ']); ';
2253 out += ' validate.errors = [' + (__err) + ']; return false; ';
2256 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2259 if ($breakOnError) {
2265 },{}],22:[function(require,module,exports){
2267 module.exports = function generate_format(it, $keyword) {
2269 var $lvl = it.level;
2270 var $dataLvl = it.dataLevel;
2271 var $schema = it.schema[$keyword];
2272 var $schemaPath = it.schemaPath + '.' + $keyword;
2273 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2274 var $breakOnError = !it.opts.allErrors;
2276 var $data = 'data' + ($dataLvl || '');
2277 if (it.opts.format === false) {
2278 if ($breakOnError) {
2279 out += ' if (true) { ';
2283 var $isData = it.opts.v5 && $schema.$data;
2284 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2286 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2287 $schemaValue = 'schema' + $lvl;
2290 var $format = 'format' + $lvl;
2291 out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var isObject' + ($lvl) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; if (isObject' + ($lvl) + ') { var async' + ($lvl) + ' = ' + ($format) + '.async; ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
2293 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2295 out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? ';
2297 out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
2299 out += ' ' + ($format) + '(' + ($data) + ') ';
2301 out += ' : ' + ($format) + '.test(' + ($data) + ')))) {';
2303 var $format = it.formats[$schema];
2305 if ($breakOnError) {
2306 out += ' if (true) { ';
2310 var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
2312 var $async = $format.async === true;
2313 $format = $format.validate;
2316 if (!it.async) throw new Error('async format in sync schema');
2317 var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
2318 out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { ';
2321 var $formatRef = 'formats' + it.util.getProperty($schema);
2322 if ($isObject) $formatRef += '.validate';
2323 if (typeof $format == 'function') {
2324 out += ' ' + ($formatRef) + '(' + ($data) + ') ';
2326 out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
2331 var $$outStack = $$outStack || [];
2332 $$outStack.push(out);
2333 out = ''; /* istanbul ignore else */
2334 if (it.createErrors !== false) {
2335 out += ' { keyword: \'' + ($errorKeyword || 'format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { format: ';
2337 out += '' + ($schemaValue);
2339 out += '' + (it.util.toQuotedString($schema));
2342 if (it.opts.messages !== false) {
2343 out += ' , message: \'should match format "';
2345 out += '\' + ' + ($schemaValue) + ' + \'';
2347 out += '' + (it.util.escapeQuotes($schema));
2351 if (it.opts.verbose) {
2352 out += ' , schema: ';
2354 out += 'validate.schema' + ($schemaPath);
2356 out += '' + (it.util.toQuotedString($schema));
2358 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2365 out = $$outStack.pop();
2366 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2368 out += ' throw new ValidationError([' + (__err) + ']); ';
2370 out += ' validate.errors = [' + (__err) + ']; return false; ';
2373 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2376 if ($breakOnError) {
2382 },{}],23:[function(require,module,exports){
2384 module.exports = function generate_items(it, $keyword) {
2386 var $lvl = it.level;
2387 var $dataLvl = it.dataLevel;
2388 var $schema = it.schema[$keyword];
2389 var $schemaPath = it.schemaPath + '.' + $keyword;
2390 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2391 var $breakOnError = !it.opts.allErrors;
2393 var $data = 'data' + ($dataLvl || '');
2394 var $valid = 'valid' + $lvl;
2395 var $errs = 'errs__' + $lvl;
2396 var $it = it.util.copy(it);
2397 var $closingBraces = '';
2399 var $dataNxt = $it.dataLevel = it.dataLevel + 1,
2400 $nextData = 'data' + $dataNxt,
2401 $currentBaseId = it.baseId;
2402 out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
2403 if (Array.isArray($schema)) {
2404 var $additionalItems = it.schema.additionalItems;
2405 if ($additionalItems === false) {
2406 out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
2407 var $currErrSchemaPath = $errSchemaPath;
2408 $errSchemaPath = it.errSchemaPath + '/additionalItems';
2409 out += ' if (!' + ($valid) + ') { ';
2410 var $$outStack = $$outStack || [];
2411 $$outStack.push(out);
2412 out = ''; /* istanbul ignore else */
2413 if (it.createErrors !== false) {
2414 out += ' { keyword: \'' + ($errorKeyword || 'additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schema.length) + ' } ';
2415 if (it.opts.messages !== false) {
2416 out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
2418 if (it.opts.verbose) {
2419 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2426 out = $$outStack.pop();
2427 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2429 out += ' throw new ValidationError([' + (__err) + ']); ';
2431 out += ' validate.errors = [' + (__err) + ']; return false; ';
2434 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2437 $errSchemaPath = $currErrSchemaPath;
2438 if ($breakOnError) {
2439 $closingBraces += '}';
2446 l1 = arr1.length - 1;
2448 $sch = arr1[$i += 1];
2449 if (it.util.schemaHasRules($sch, it.RULES.all)) {
2450 out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
2451 var $passData = $data + '[' + $i + ']';
2453 $it.schemaPath = $schemaPath + '[' + $i + ']';
2454 $it.errSchemaPath = $errSchemaPath + '/' + $i;
2455 $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
2456 $it.dataPathArr[$dataNxt] = $i;
2457 var $code = it.validate($it);
2458 $it.baseId = $currentBaseId;
2459 if (it.util.varOccurences($code, $nextData) < 2) {
2460 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2462 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2465 if ($breakOnError) {
2466 out += ' if (valid' + ($it.level) + ') { ';
2467 $closingBraces += '}';
2472 if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) {
2473 $it.schema = $additionalItems;
2474 $it.schemaPath = it.schemaPath + '.additionalItems';
2475 $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
2476 out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var i' + ($lvl) + ' = ' + ($schema.length) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
2477 $it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
2478 var $passData = $data + '[i' + $lvl + ']';
2479 $it.dataPathArr[$dataNxt] = 'i' + $lvl;
2480 var $code = it.validate($it);
2481 $it.baseId = $currentBaseId;
2482 if (it.util.varOccurences($code, $nextData) < 2) {
2483 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2485 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2487 if ($breakOnError) {
2488 out += ' if (!valid' + ($it.level) + ') break; ';
2491 if ($breakOnError) {
2492 out += ' if (valid' + ($it.level) + ') { ';
2493 $closingBraces += '}';
2496 } else if (it.util.schemaHasRules($schema, it.RULES.all)) {
2497 $it.schema = $schema;
2498 $it.schemaPath = $schemaPath;
2499 $it.errSchemaPath = $errSchemaPath;
2500 out += ' for (var i' + ($lvl) + ' = ' + (0) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { ';
2501 $it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true);
2502 var $passData = $data + '[i' + $lvl + ']';
2503 $it.dataPathArr[$dataNxt] = 'i' + $lvl;
2504 var $code = it.validate($it);
2505 $it.baseId = $currentBaseId;
2506 if (it.util.varOccurences($code, $nextData) < 2) {
2507 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
2509 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2511 if ($breakOnError) {
2512 out += ' if (!valid' + ($it.level) + ') break; ';
2515 if ($breakOnError) {
2516 out += ' if (valid' + ($it.level) + ') { ';
2517 $closingBraces += '}';
2520 if ($breakOnError) {
2521 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2523 out = it.util.cleanUpCode(out);
2527 },{}],24:[function(require,module,exports){
2529 module.exports = function generate_multipleOf(it, $keyword) {
2531 var $lvl = it.level;
2532 var $dataLvl = it.dataLevel;
2533 var $schema = it.schema[$keyword];
2534 var $schemaPath = it.schemaPath + '.' + $keyword;
2535 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2536 var $breakOnError = !it.opts.allErrors;
2538 var $data = 'data' + ($dataLvl || '');
2539 var $isData = it.opts.v5 && $schema.$data;
2540 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2542 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2543 $schemaValue = 'schema' + $lvl;
2545 out += 'var division' + ($lvl) + ';if (';
2547 out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
2549 out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
2550 if (it.opts.multipleOfPrecision) {
2551 out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
2553 out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
2560 var $$outStack = $$outStack || [];
2561 $$outStack.push(out);
2562 out = ''; /* istanbul ignore else */
2563 if (it.createErrors !== false) {
2564 out += ' { keyword: \'' + ($errorKeyword || 'multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { multipleOf: ' + ($schemaValue) + ' } ';
2565 if (it.opts.messages !== false) {
2566 out += ' , message: \'should be multiple of ';
2568 out += '\' + ' + ($schemaValue);
2570 out += '' + ($schema) + '\'';
2573 if (it.opts.verbose) {
2574 out += ' , schema: ';
2576 out += 'validate.schema' + ($schemaPath);
2578 out += '' + ($schema);
2580 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2587 out = $$outStack.pop();
2588 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2590 out += ' throw new ValidationError([' + (__err) + ']); ';
2592 out += ' validate.errors = [' + (__err) + ']; return false; ';
2595 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2598 if ($breakOnError) {
2604 },{}],25:[function(require,module,exports){
2606 module.exports = function generate_not(it, $keyword) {
2608 var $lvl = it.level;
2609 var $dataLvl = it.dataLevel;
2610 var $schema = it.schema[$keyword];
2611 var $schemaPath = it.schemaPath + '.' + $keyword;
2612 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2613 var $breakOnError = !it.opts.allErrors;
2615 var $data = 'data' + ($dataLvl || '');
2616 var $errs = 'errs__' + $lvl;
2617 var $it = it.util.copy(it);
2619 if (it.util.schemaHasRules($schema, it.RULES.all)) {
2620 $it.schema = $schema;
2621 $it.schemaPath = $schemaPath;
2622 $it.errSchemaPath = $errSchemaPath;
2623 out += ' var ' + ($errs) + ' = errors; ';
2624 var $wasComposite = it.compositeRule;
2625 it.compositeRule = $it.compositeRule = true;
2626 $it.createErrors = false;
2627 var $allErrorsOption;
2628 if ($it.opts.allErrors) {
2629 $allErrorsOption = $it.opts.allErrors;
2630 $it.opts.allErrors = false;
2632 out += ' ' + (it.validate($it)) + ' ';
2633 $it.createErrors = true;
2634 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
2635 it.compositeRule = $it.compositeRule = $wasComposite;
2636 out += ' if (valid' + ($it.level) + ') { ';
2637 var $$outStack = $$outStack || [];
2638 $$outStack.push(out);
2639 out = ''; /* istanbul ignore else */
2640 if (it.createErrors !== false) {
2641 out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
2642 if (it.opts.messages !== false) {
2643 out += ' , message: \'should NOT be valid\' ';
2645 if (it.opts.verbose) {
2646 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2653 out = $$outStack.pop();
2654 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2656 out += ' throw new ValidationError([' + (__err) + ']); ';
2658 out += ' validate.errors = [' + (__err) + ']; return false; ';
2661 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2663 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2664 if (it.opts.allErrors) {
2668 out += ' var err = '; /* istanbul ignore else */
2669 if (it.createErrors !== false) {
2670 out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
2671 if (it.opts.messages !== false) {
2672 out += ' , message: \'should NOT be valid\' ';
2674 if (it.opts.verbose) {
2675 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2681 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2682 if ($breakOnError) {
2683 out += ' if (false) { ';
2689 },{}],26:[function(require,module,exports){
2691 module.exports = function generate_oneOf(it, $keyword) {
2693 var $lvl = it.level;
2694 var $dataLvl = it.dataLevel;
2695 var $schema = it.schema[$keyword];
2696 var $schemaPath = it.schemaPath + '.' + $keyword;
2697 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2698 var $breakOnError = !it.opts.allErrors;
2700 var $data = 'data' + ($dataLvl || '');
2701 var $valid = 'valid' + $lvl;
2702 var $errs = 'errs__' + $lvl;
2703 var $it = it.util.copy(it);
2704 var $closingBraces = '';
2706 out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;';
2707 var $currentBaseId = $it.baseId;
2708 var $wasComposite = it.compositeRule;
2709 it.compositeRule = $it.compositeRule = true;
2713 l1 = arr1.length - 1;
2715 $sch = arr1[$i += 1];
2716 if (it.util.schemaHasRules($sch, it.RULES.all)) {
2718 $it.schemaPath = $schemaPath + '[' + $i + ']';
2719 $it.errSchemaPath = $errSchemaPath + '/' + $i;
2720 out += ' ' + (it.validate($it)) + ' ';
2721 $it.baseId = $currentBaseId;
2723 out += ' var valid' + ($it.level) + ' = true; ';
2726 out += ' if (valid' + ($it.level) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
2727 $closingBraces += '}';
2729 out += ' if (valid' + ($it.level) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
2732 it.compositeRule = $it.compositeRule = $wasComposite;
2733 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
2734 var $$outStack = $$outStack || [];
2735 $$outStack.push(out);
2736 out = ''; /* istanbul ignore else */
2737 if (it.createErrors !== false) {
2738 out += ' { keyword: \'' + ($errorKeyword || 'oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} ';
2739 if (it.opts.messages !== false) {
2740 out += ' , message: \'should match exactly one schema in oneOf\' ';
2742 if (it.opts.verbose) {
2743 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2750 out = $$outStack.pop();
2751 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2753 out += ' throw new ValidationError([' + (__err) + ']); ';
2755 out += ' validate.errors = [' + (__err) + ']; return false; ';
2758 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2760 out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
2761 if (it.opts.allErrors) {
2767 },{}],27:[function(require,module,exports){
2769 module.exports = function generate_pattern(it, $keyword) {
2771 var $lvl = it.level;
2772 var $dataLvl = it.dataLevel;
2773 var $schema = it.schema[$keyword];
2774 var $schemaPath = it.schemaPath + '.' + $keyword;
2775 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2776 var $breakOnError = !it.opts.allErrors;
2778 var $data = 'data' + ($dataLvl || '');
2779 var $isData = it.opts.v5 && $schema.$data;
2780 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2782 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2783 $schemaValue = 'schema' + $lvl;
2785 var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
2788 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2790 out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
2791 var $$outStack = $$outStack || [];
2792 $$outStack.push(out);
2793 out = ''; /* istanbul ignore else */
2794 if (it.createErrors !== false) {
2795 out += ' { keyword: \'' + ($errorKeyword || 'pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { pattern: ';
2797 out += '' + ($schemaValue);
2799 out += '' + (it.util.toQuotedString($schema));
2802 if (it.opts.messages !== false) {
2803 out += ' , message: \'should match pattern "';
2805 out += '\' + ' + ($schemaValue) + ' + \'';
2807 out += '' + (it.util.escapeQuotes($schema));
2811 if (it.opts.verbose) {
2812 out += ' , schema: ';
2814 out += 'validate.schema' + ($schemaPath);
2816 out += '' + (it.util.toQuotedString($schema));
2818 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2825 out = $$outStack.pop();
2826 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2828 out += ' throw new ValidationError([' + (__err) + ']); ';
2830 out += ' validate.errors = [' + (__err) + ']; return false; ';
2833 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2836 if ($breakOnError) {
2842 },{}],28:[function(require,module,exports){
2844 module.exports = function generate_patternRequired(it, $keyword) {
2846 var $lvl = it.level;
2847 var $dataLvl = it.dataLevel;
2848 var $schema = it.schema[$keyword];
2849 var $schemaPath = it.schemaPath + '.' + $keyword;
2850 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2851 var $breakOnError = !it.opts.allErrors;
2853 var $data = 'data' + ($dataLvl || '');
2854 var $valid = 'valid' + $lvl;
2855 var $key = 'key' + $lvl,
2856 $matched = 'patternMatched' + $lvl,
2857 $closingBraces = '',
2858 $ownProperties = it.opts.ownProperties;
2859 out += 'var ' + ($valid) + ' = true;';
2862 var $pProperty, i1 = -1,
2863 l1 = arr1.length - 1;
2865 $pProperty = arr1[i1 += 1];
2866 out += ' var ' + ($matched) + ' = false; for (var ' + ($key) + ' in ' + ($data) + ') { ';
2867 if ($ownProperties) {
2868 out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
2870 out += ' ' + ($matched) + ' = ' + (it.usePattern($pProperty)) + '.test(' + ($key) + '); if (' + ($matched) + ') break; } ';
2871 var $missingPattern = it.util.escapeQuotes($pProperty);
2872 out += ' if (!' + ($matched) + ') { ' + ($valid) + ' = false; var err = '; /* istanbul ignore else */
2873 if (it.createErrors !== false) {
2874 out += ' { keyword: \'' + ($errorKeyword || 'patternRequired') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingPattern: \'' + ($missingPattern) + '\' } ';
2875 if (it.opts.messages !== false) {
2876 out += ' , message: \'should have property matching pattern \\\'' + ($missingPattern) + '\\\'\' ';
2878 if (it.opts.verbose) {
2879 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2885 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2886 if ($breakOnError) {
2887 $closingBraces += '}';
2892 out += '' + ($closingBraces);
2896 },{}],29:[function(require,module,exports){
2898 module.exports = function generate_properties(it, $keyword) {
2900 var $lvl = it.level;
2901 var $dataLvl = it.dataLevel;
2902 var $schema = it.schema[$keyword];
2903 var $schemaPath = it.schemaPath + '.' + $keyword;
2904 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
2905 var $breakOnError = !it.opts.allErrors;
2907 var $data = 'data' + ($dataLvl || '');
2908 var $valid = 'valid' + $lvl;
2909 var $errs = 'errs__' + $lvl;
2910 var $it = it.util.copy(it);
2911 var $closingBraces = '';
2913 var $key = 'key' + $lvl,
2914 $dataNxt = $it.dataLevel = it.dataLevel + 1,
2915 $nextData = 'data' + $dataNxt;
2916 var $schemaKeys = Object.keys($schema || {}),
2917 $pProperties = it.schema.patternProperties || {},
2918 $pPropertyKeys = Object.keys($pProperties),
2919 $aProperties = it.schema.additionalProperties,
2920 $someProperties = $schemaKeys.length || $pPropertyKeys.length,
2921 $noAdditional = $aProperties === false,
2922 $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
2923 $removeAdditional = it.opts.removeAdditional,
2924 $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
2925 $ownProperties = it.opts.ownProperties,
2926 $currentBaseId = it.baseId;
2927 var $required = it.schema.required;
2928 if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required);
2930 var $pgProperties = it.schema.patternGroups || {},
2931 $pgPropertyKeys = Object.keys($pgProperties);
2933 out += 'var ' + ($errs) + ' = errors;var valid' + ($it.level) + ' = true;';
2934 if ($checkAdditional) {
2935 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
2936 if ($ownProperties) {
2937 out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
2939 if ($someProperties) {
2940 out += ' var isAdditional' + ($lvl) + ' = !(false ';
2941 if ($schemaKeys.length) {
2942 if ($schemaKeys.length > 5) {
2943 out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] ';
2945 var arr1 = $schemaKeys;
2947 var $propertyKey, i1 = -1,
2948 l1 = arr1.length - 1;
2950 $propertyKey = arr1[i1 += 1];
2951 out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
2956 if ($pPropertyKeys.length) {
2957 var arr2 = $pPropertyKeys;
2959 var $pProperty, $i = -1,
2960 l2 = arr2.length - 1;
2962 $pProperty = arr2[$i += 1];
2963 out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
2967 if (it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length) {
2968 var arr3 = $pgPropertyKeys;
2970 var $pgProperty, $i = -1,
2971 l3 = arr3.length - 1;
2973 $pgProperty = arr3[$i += 1];
2974 out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') ';
2978 out += ' ); if (isAdditional' + ($lvl) + ') { ';
2980 if ($removeAdditional == 'all') {
2981 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
2983 var $currentErrorPath = it.errorPath;
2984 var $additionalProperty = '\' + key' + $lvl + ' + \'';
2985 if (it.opts._errorDataPathProperty) {
2986 it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
2988 if ($noAdditional) {
2989 if ($removeAdditional) {
2990 out += ' delete ' + ($data) + '[' + ($key) + ']; ';
2992 out += ' valid' + ($it.level) + ' = false; ';
2993 var $currErrSchemaPath = $errSchemaPath;
2994 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
2995 var $$outStack = $$outStack || [];
2996 $$outStack.push(out);
2997 out = ''; /* istanbul ignore else */
2998 if (it.createErrors !== false) {
2999 out += ' { keyword: \'' + ($errorKeyword || 'additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
3000 if (it.opts.messages !== false) {
3001 out += ' , message: \'should NOT have additional properties\' ';
3003 if (it.opts.verbose) {
3004 out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3011 out = $$outStack.pop();
3012 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3014 out += ' throw new ValidationError([' + (__err) + ']); ';
3016 out += ' validate.errors = [' + (__err) + ']; return false; ';
3019 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3021 $errSchemaPath = $currErrSchemaPath;
3022 if ($breakOnError) {
3026 } else if ($additionalIsSchema) {
3027 if ($removeAdditional == 'failing') {
3028 out += ' var ' + ($errs) + ' = errors; ';
3029 var $wasComposite = it.compositeRule;
3030 it.compositeRule = $it.compositeRule = true;
3031 $it.schema = $aProperties;
3032 $it.schemaPath = it.schemaPath + '.additionalProperties';
3033 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3034 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
3035 var $passData = $data + '[key' + $lvl + ']';
3036 $it.dataPathArr[$dataNxt] = 'key' + $lvl;
3037 var $code = it.validate($it);
3038 $it.baseId = $currentBaseId;
3039 if (it.util.varOccurences($code, $nextData) < 2) {
3040 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3042 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3044 out += ' if (!valid' + ($it.level) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
3045 it.compositeRule = $it.compositeRule = $wasComposite;
3047 $it.schema = $aProperties;
3048 $it.schemaPath = it.schemaPath + '.additionalProperties';
3049 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
3050 $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
3051 var $passData = $data + '[key' + $lvl + ']';
3052 $it.dataPathArr[$dataNxt] = 'key' + $lvl;
3053 var $code = it.validate($it);
3054 $it.baseId = $currentBaseId;
3055 if (it.util.varOccurences($code, $nextData) < 2) {
3056 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3058 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3060 if ($breakOnError) {
3061 out += ' if (!valid' + ($it.level) + ') break; ';
3065 it.errorPath = $currentErrorPath;
3067 if ($someProperties) {
3071 if ($breakOnError) {
3072 out += ' if (valid' + ($it.level) + ') { ';
3073 $closingBraces += '}';
3076 var $useDefaults = it.opts.useDefaults && !it.compositeRule;
3077 if ($schemaKeys.length) {
3078 var arr4 = $schemaKeys;
3080 var $propertyKey, i4 = -1,
3081 l4 = arr4.length - 1;
3083 $propertyKey = arr4[i4 += 1];
3084 var $sch = $schema[$propertyKey];
3085 if (it.util.schemaHasRules($sch, it.RULES.all)) {
3086 var $prop = it.util.getProperty($propertyKey),
3087 $passData = $data + $prop,
3088 $hasDefault = $useDefaults && $sch.default !== undefined;
3090 $it.schemaPath = $schemaPath + $prop;
3091 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
3092 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
3093 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
3094 var $code = it.validate($it);
3095 $it.baseId = $currentBaseId;
3096 if (it.util.varOccurences($code, $nextData) < 2) {
3097 $code = it.util.varReplace($code, $nextData, $passData);
3098 var $useData = $passData;
3100 var $useData = $nextData;
3101 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
3104 out += ' ' + ($code) + ' ';
3106 if ($requiredHash && $requiredHash[$propertyKey]) {
3107 out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = false; ';
3108 var $currentErrorPath = it.errorPath,
3109 $currErrSchemaPath = $errSchemaPath,
3110 $missingProperty = it.util.escapeQuotes($propertyKey);
3111 if (it.opts._errorDataPathProperty) {
3112 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
3114 $errSchemaPath = it.errSchemaPath + '/required';
3115 var $$outStack = $$outStack || [];
3116 $$outStack.push(out);
3117 out = ''; /* istanbul ignore else */
3118 if (it.createErrors !== false) {
3119 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3120 if (it.opts.messages !== false) {
3121 out += ' , message: \'';
3122 if (it.opts._errorDataPathProperty) {
3123 out += 'is a required property';
3125 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3129 if (it.opts.verbose) {
3130 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3137 out = $$outStack.pop();
3138 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3140 out += ' throw new ValidationError([' + (__err) + ']); ';
3142 out += ' validate.errors = [' + (__err) + ']; return false; ';
3145 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3147 $errSchemaPath = $currErrSchemaPath;
3148 it.errorPath = $currentErrorPath;
3149 out += ' } else { ';
3151 if ($breakOnError) {
3152 out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = true; } else { ';
3154 out += ' if (' + ($useData) + ' !== undefined) { ';
3157 out += ' ' + ($code) + ' } ';
3160 if ($breakOnError) {
3161 out += ' if (valid' + ($it.level) + ') { ';
3162 $closingBraces += '}';
3167 var arr5 = $pPropertyKeys;
3169 var $pProperty, i5 = -1,
3170 l5 = arr5.length - 1;
3172 $pProperty = arr5[i5 += 1];
3173 var $sch = $pProperties[$pProperty];
3174 if (it.util.schemaHasRules($sch, it.RULES.all)) {
3176 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
3177 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
3178 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
3179 if ($ownProperties) {
3180 out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
3182 out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
3183 $it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
3184 var $passData = $data + '[key' + $lvl + ']';
3185 $it.dataPathArr[$dataNxt] = 'key' + $lvl;
3186 var $code = it.validate($it);
3187 $it.baseId = $currentBaseId;
3188 if (it.util.varOccurences($code, $nextData) < 2) {
3189 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3191 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3193 if ($breakOnError) {
3194 out += ' if (!valid' + ($it.level) + ') break; ';
3197 if ($breakOnError) {
3198 out += ' else valid' + ($it.level) + ' = true; ';
3201 if ($breakOnError) {
3202 out += ' if (valid' + ($it.level) + ') { ';
3203 $closingBraces += '}';
3209 var arr6 = $pgPropertyKeys;
3211 var $pgProperty, i6 = -1,
3212 l6 = arr6.length - 1;
3214 $pgProperty = arr6[i6 += 1];
3215 var $pgSchema = $pgProperties[$pgProperty],
3216 $sch = $pgSchema.schema;
3217 if (it.util.schemaHasRules($sch, it.RULES.all)) {
3219 $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
3220 $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema';
3221 out += ' var pgPropCount' + ($lvl) + ' = 0; for (var ' + ($key) + ' in ' + ($data) + ') { ';
3222 if ($ownProperties) {
3223 out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
3225 out += ' if (' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ')) { pgPropCount' + ($lvl) + '++; ';
3226 $it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
3227 var $passData = $data + '[key' + $lvl + ']';
3228 $it.dataPathArr[$dataNxt] = 'key' + $lvl;
3229 var $code = it.validate($it);
3230 $it.baseId = $currentBaseId;
3231 if (it.util.varOccurences($code, $nextData) < 2) {
3232 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
3234 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3236 if ($breakOnError) {
3237 out += ' if (!valid' + ($it.level) + ') break; ';
3240 if ($breakOnError) {
3241 out += ' else valid' + ($it.level) + ' = true; ';
3244 if ($breakOnError) {
3245 out += ' if (valid' + ($it.level) + ') { ';
3246 $closingBraces += '}';
3248 var $pgMin = $pgSchema.minimum,
3249 $pgMax = $pgSchema.maximum;
3250 if ($pgMin !== undefined || $pgMax !== undefined) {
3251 out += ' var ' + ($valid) + ' = true; ';
3252 var $currErrSchemaPath = $errSchemaPath;
3253 if ($pgMin !== undefined) {
3254 var $limit = $pgMin,
3255 $reason = 'minimum',
3256 $moreOrLess = 'less';
3257 out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; ';
3258 $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum';
3259 out += ' if (!' + ($valid) + ') { ';
3260 var $$outStack = $$outStack || [];
3261 $$outStack.push(out);
3262 out = ''; /* istanbul ignore else */
3263 if (it.createErrors !== false) {
3264 out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
3265 if (it.opts.messages !== false) {
3266 out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
3268 if (it.opts.verbose) {
3269 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3276 out = $$outStack.pop();
3277 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3279 out += ' throw new ValidationError([' + (__err) + ']); ';
3281 out += ' validate.errors = [' + (__err) + ']; return false; ';
3284 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3287 if ($pgMax !== undefined) {
3291 if ($pgMax !== undefined) {
3292 var $limit = $pgMax,
3293 $reason = 'maximum',
3294 $moreOrLess = 'more';
3295 out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; ';
3296 $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum';
3297 out += ' if (!' + ($valid) + ') { ';
3298 var $$outStack = $$outStack || [];
3299 $$outStack.push(out);
3300 out = ''; /* istanbul ignore else */
3301 if (it.createErrors !== false) {
3302 out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
3303 if (it.opts.messages !== false) {
3304 out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
3306 if (it.opts.verbose) {
3307 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3314 out = $$outStack.pop();
3315 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3317 out += ' throw new ValidationError([' + (__err) + ']); ';
3319 out += ' validate.errors = [' + (__err) + ']; return false; ';
3322 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3326 $errSchemaPath = $currErrSchemaPath;
3327 if ($breakOnError) {
3328 out += ' if (' + ($valid) + ') { ';
3329 $closingBraces += '}';
3336 if ($breakOnError) {
3337 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3339 out = it.util.cleanUpCode(out);
3343 },{}],30:[function(require,module,exports){
3345 module.exports = function generate_ref(it, $keyword) {
3347 var $lvl = it.level;
3348 var $dataLvl = it.dataLevel;
3349 var $schema = it.schema[$keyword];
3350 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3351 var $breakOnError = !it.opts.allErrors;
3353 var $data = 'data' + ($dataLvl || '');
3354 var $valid = 'valid' + $lvl;
3355 var $async, $refCode;
3356 if ($schema == '#' || $schema == '#/') {
3359 $refCode = 'validate';
3361 $async = it.root.schema.$async === true;
3362 $refCode = 'root.refVal[0]';
3365 var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
3366 if ($refVal === undefined) {
3367 var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId;
3368 if (it.opts.missingRefs == 'fail') {
3369 console.log($message);
3370 var $$outStack = $$outStack || [];
3371 $$outStack.push(out);
3372 out = ''; /* istanbul ignore else */
3373 if (it.createErrors !== false) {
3374 out += ' { keyword: \'' + ($errorKeyword || '$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
3375 if (it.opts.messages !== false) {
3376 out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
3378 if (it.opts.verbose) {
3379 out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3386 out = $$outStack.pop();
3387 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3389 out += ' throw new ValidationError([' + (__err) + ']); ';
3391 out += ' validate.errors = [' + (__err) + ']; return false; ';
3394 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3396 if ($breakOnError) {
3397 out += ' if (false) { ';
3399 } else if (it.opts.missingRefs == 'ignore') {
3400 console.log($message);
3401 if ($breakOnError) {
3402 out += ' if (true) { ';
3405 var $error = new Error($message);
3406 $error.missingRef = it.resolve.url(it.baseId, $schema);
3407 $error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
3410 } else if ($refVal.inline) {
3411 var $it = it.util.copy(it);
3413 $it.schema = $refVal.schema;
3414 $it.schemaPath = '';
3415 $it.errSchemaPath = $schema;
3416 var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
3417 out += ' ' + ($code) + ' ';
3418 if ($breakOnError) {
3419 out += ' if (valid' + ($it.level) + ') { ';
3422 $async = $refVal.$async === true;
3423 $refCode = $refVal.code;
3427 var $$outStack = $$outStack || [];
3428 $$outStack.push(out);
3430 if (it.opts.passContext) {
3431 out += ' ' + ($refCode) + '.call(this, ';
3433 out += ' ' + ($refCode) + '( ';
3435 out += ' ' + ($data) + ', (dataPath || \'\')';
3436 if (it.errorPath != '""') {
3437 out += ' + ' + (it.errorPath);
3440 out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
3442 out += ' , parentData , parentDataProperty ';
3445 var __callValidate = out;
3446 out = $$outStack.pop();
3448 if (!it.async) throw new Error('async schema referenced by sync schema');
3450 if ($breakOnError) {
3451 out += 'var ' + ($valid) + ' =';
3453 out += ' ' + (it.yieldAwait) + ' ' + (__callValidate) + '; } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; } ';
3454 if ($breakOnError) {
3455 out += ' if (' + ($valid) + ') { ';
3458 out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
3459 if ($breakOnError) {
3467 },{}],31:[function(require,module,exports){
3469 module.exports = function generate_required(it, $keyword) {
3471 var $lvl = it.level;
3472 var $dataLvl = it.dataLevel;
3473 var $schema = it.schema[$keyword];
3474 var $schemaPath = it.schemaPath + '.' + $keyword;
3475 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3476 var $breakOnError = !it.opts.allErrors;
3478 var $data = 'data' + ($dataLvl || '');
3479 var $valid = 'valid' + $lvl;
3480 var $isData = it.opts.v5 && $schema.$data;
3481 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
3483 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
3484 $schemaValue = 'schema' + $lvl;
3487 if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
3491 var $property, i1 = -1,
3492 l1 = arr1.length - 1;
3494 $property = arr1[i1 += 1];
3495 var $propertySch = it.schema.properties[$property];
3496 if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) {
3497 $required[$required.length] = $property;
3502 var $required = $schema;
3505 if ($isData || $required.length) {
3506 var $currentErrorPath = it.errorPath,
3507 $loopRequired = $isData || $required.length >= it.opts.loopRequired;
3508 if ($breakOnError) {
3509 out += ' var missing' + ($lvl) + '; ';
3510 if ($loopRequired) {
3512 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
3514 var $i = 'i' + $lvl,
3515 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
3516 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3517 if (it.opts._errorDataPathProperty) {
3518 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
3520 out += ' var ' + ($valid) + ' = true; ';
3522 out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
3524 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } ';
3528 out += ' if (!' + ($valid) + ') { ';
3529 var $$outStack = $$outStack || [];
3530 $$outStack.push(out);
3531 out = ''; /* istanbul ignore else */
3532 if (it.createErrors !== false) {
3533 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3534 if (it.opts.messages !== false) {
3535 out += ' , message: \'';
3536 if (it.opts._errorDataPathProperty) {
3537 out += 'is a required property';
3539 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3543 if (it.opts.verbose) {
3544 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3551 out = $$outStack.pop();
3552 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3554 out += ' throw new ValidationError([' + (__err) + ']); ';
3556 out += ' validate.errors = [' + (__err) + ']; return false; ';
3559 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3561 out += ' } else { ';
3564 var arr2 = $required;
3566 var _$property, $i = -1,
3567 l2 = arr2.length - 1;
3569 _$property = arr2[$i += 1];
3573 var $prop = it.util.getProperty(_$property);
3574 out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
3578 var $propertyPath = 'missing' + $lvl,
3579 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3580 if (it.opts._errorDataPathProperty) {
3581 it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
3583 var $$outStack = $$outStack || [];
3584 $$outStack.push(out);
3585 out = ''; /* istanbul ignore else */
3586 if (it.createErrors !== false) {
3587 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3588 if (it.opts.messages !== false) {
3589 out += ' , message: \'';
3590 if (it.opts._errorDataPathProperty) {
3591 out += 'is a required property';
3593 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3597 if (it.opts.verbose) {
3598 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3605 out = $$outStack.pop();
3606 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3608 out += ' throw new ValidationError([' + (__err) + ']); ';
3610 out += ' validate.errors = [' + (__err) + ']; return false; ';
3613 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3615 out += ' } else { ';
3618 if ($loopRequired) {
3620 out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
3622 var $i = 'i' + $lvl,
3623 $propertyPath = 'schema' + $lvl + '[' + $i + ']',
3624 $missingProperty = '\' + ' + $propertyPath + ' + \'';
3625 if (it.opts._errorDataPathProperty) {
3626 it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
3629 out += ' if (schema' + ($lvl) + ' && !Array.isArray(schema' + ($lvl) + ')) { var err = '; /* istanbul ignore else */
3630 if (it.createErrors !== false) {
3631 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3632 if (it.opts.messages !== false) {
3633 out += ' , message: \'';
3634 if (it.opts._errorDataPathProperty) {
3635 out += 'is a required property';
3637 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3641 if (it.opts.verbose) {
3642 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3648 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (schema' + ($lvl) + ' !== undefined) { ';
3650 out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { var err = '; /* istanbul ignore else */
3651 if (it.createErrors !== false) {
3652 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3653 if (it.opts.messages !== false) {
3654 out += ' , message: \'';
3655 if (it.opts._errorDataPathProperty) {
3656 out += 'is a required property';
3658 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3662 if (it.opts.verbose) {
3663 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3669 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
3674 var arr3 = $required;
3676 var $reqProperty, i3 = -1,
3677 l3 = arr3.length - 1;
3679 $reqProperty = arr3[i3 += 1];
3680 var $prop = it.util.getProperty($reqProperty),
3681 $missingProperty = it.util.escapeQuotes($reqProperty);
3682 if (it.opts._errorDataPathProperty) {
3683 it.errorPath = it.util.getPath($currentErrorPath, $reqProperty, it.opts.jsonPointers);
3685 out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */
3686 if (it.createErrors !== false) {
3687 out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
3688 if (it.opts.messages !== false) {
3689 out += ' , message: \'';
3690 if (it.opts._errorDataPathProperty) {
3691 out += 'is a required property';
3693 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3697 if (it.opts.verbose) {
3698 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3704 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
3709 it.errorPath = $currentErrorPath;
3710 } else if ($breakOnError) {
3711 out += ' if (true) {';
3716 },{}],32:[function(require,module,exports){
3718 module.exports = function generate_switch(it, $keyword) {
3720 var $lvl = it.level;
3721 var $dataLvl = it.dataLevel;
3722 var $schema = it.schema[$keyword];
3723 var $schemaPath = it.schemaPath + '.' + $keyword;
3724 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3725 var $breakOnError = !it.opts.allErrors;
3727 var $data = 'data' + ($dataLvl || '');
3728 var $valid = 'valid' + $lvl;
3729 var $errs = 'errs__' + $lvl;
3730 var $it = it.util.copy(it);
3731 var $closingBraces = '';
3733 var $ifPassed = 'ifPassed' + it.level,
3734 $currentBaseId = $it.baseId,
3736 out += 'var ' + ($ifPassed) + ';';
3739 var $sch, $caseIndex = -1,
3740 l1 = arr1.length - 1;
3741 while ($caseIndex < l1) {
3742 $sch = arr1[$caseIndex += 1];
3743 if ($caseIndex && !$shouldContinue) {
3744 out += ' if (!' + ($ifPassed) + ') { ';
3745 $closingBraces += '}';
3747 if ($sch.if && it.util.schemaHasRules($sch.if, it.RULES.all)) {
3748 out += ' var ' + ($errs) + ' = errors; ';
3749 var $wasComposite = it.compositeRule;
3750 it.compositeRule = $it.compositeRule = true;
3751 $it.createErrors = false;
3752 $it.schema = $sch.if;
3753 $it.schemaPath = $schemaPath + '[' + $caseIndex + '].if';
3754 $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/if';
3755 out += ' ' + (it.validate($it)) + ' ';
3756 $it.baseId = $currentBaseId;
3757 $it.createErrors = true;
3758 it.compositeRule = $it.compositeRule = $wasComposite;
3759 out += ' ' + ($ifPassed) + ' = valid' + ($it.level) + '; if (' + ($ifPassed) + ') { ';
3760 if (typeof $sch.then == 'boolean') {
3761 if ($sch.then === false) {
3762 var $$outStack = $$outStack || [];
3763 $$outStack.push(out);
3764 out = ''; /* istanbul ignore else */
3765 if (it.createErrors !== false) {
3766 out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } ';
3767 if (it.opts.messages !== false) {
3768 out += ' , message: \'should pass "switch" keyword validation\' ';
3770 if (it.opts.verbose) {
3771 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3778 out = $$outStack.pop();
3779 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3781 out += ' throw new ValidationError([' + (__err) + ']); ';
3783 out += ' validate.errors = [' + (__err) + ']; return false; ';
3786 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3789 out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
3791 $it.schema = $sch.then;
3792 $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
3793 $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
3794 out += ' ' + (it.validate($it)) + ' ';
3795 $it.baseId = $currentBaseId;
3797 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } } ';
3799 out += ' ' + ($ifPassed) + ' = true; ';
3800 if (typeof $sch.then == 'boolean') {
3801 if ($sch.then === false) {
3802 var $$outStack = $$outStack || [];
3803 $$outStack.push(out);
3804 out = ''; /* istanbul ignore else */
3805 if (it.createErrors !== false) {
3806 out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } ';
3807 if (it.opts.messages !== false) {
3808 out += ' , message: \'should pass "switch" keyword validation\' ';
3810 if (it.opts.verbose) {
3811 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3818 out = $$outStack.pop();
3819 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3821 out += ' throw new ValidationError([' + (__err) + ']); ';
3823 out += ' validate.errors = [' + (__err) + ']; return false; ';
3826 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3829 out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
3831 $it.schema = $sch.then;
3832 $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
3833 $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
3834 out += ' ' + (it.validate($it)) + ' ';
3835 $it.baseId = $currentBaseId;
3838 $shouldContinue = $sch.continue
3841 out += '' + ($closingBraces) + 'var ' + ($valid) + ' = valid' + ($it.level) + '; ';
3842 out = it.util.cleanUpCode(out);
3846 },{}],33:[function(require,module,exports){
3848 module.exports = function generate_uniqueItems(it, $keyword) {
3850 var $lvl = it.level;
3851 var $dataLvl = it.dataLevel;
3852 var $schema = it.schema[$keyword];
3853 var $schemaPath = it.schemaPath + '.' + $keyword;
3854 var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
3855 var $breakOnError = !it.opts.allErrors;
3857 var $data = 'data' + ($dataLvl || '');
3858 var $valid = 'valid' + $lvl;
3859 var $isData = it.opts.v5 && $schema.$data;
3860 var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
3862 out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
3863 $schemaValue = 'schema' + $lvl;
3865 if (($schema || $isData) && it.opts.uniqueItems !== false) {
3867 out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
3869 out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } ';
3873 out += ' if (!' + ($valid) + ') { ';
3874 var $$outStack = $$outStack || [];
3875 $$outStack.push(out);
3876 out = ''; /* istanbul ignore else */
3877 if (it.createErrors !== false) {
3878 out += ' { keyword: \'' + ($errorKeyword || 'uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { i: i, j: j } ';
3879 if (it.opts.messages !== false) {
3880 out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
3882 if (it.opts.verbose) {
3883 out += ' , schema: ';
3885 out += 'validate.schema' + ($schemaPath);
3887 out += '' + ($schema);
3889 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3896 out = $$outStack.pop();
3897 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3899 out += ' throw new ValidationError([' + (__err) + ']); ';
3901 out += ' validate.errors = [' + (__err) + ']; return false; ';
3904 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3907 if ($breakOnError) {
3911 if ($breakOnError) {
3912 out += ' if (true) { ';
3918 },{}],34:[function(require,module,exports){
3920 module.exports = function generate_validate(it, $keyword) {
3922 var $async = it.schema.$async === true;
3924 var $top = it.isTop,
3925 $lvl = it.level = 0,
3926 $dataLvl = it.dataLevel = 0,
3928 it.rootId = it.resolve.fullPath(it.root.schema.id);
3929 it.baseId = it.baseId || it.rootId;
3932 var $es7 = it.opts.async == 'es7';
3933 it.yieldAwait = $es7 ? 'await' : 'yield';
3936 it.dataPathArr = [undefined];
3937 out += ' validate = ';
3940 out += ' (async function ';
3942 if (it.opts.async == 'co*') {
3945 out += '(function* ';
3948 out += ' (function ';
3950 out += ' (data, dataPath, parentData, parentDataProperty) { \'use strict\'; var vErrors = null; ';
3951 out += ' var errors = 0; ';
3953 var $lvl = it.level,
3954 $dataLvl = it.dataLevel,
3955 $data = 'data' + ($dataLvl || '');
3956 if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
3957 if ($async && !it.async) throw new Error('async schema in sync schema');
3958 out += ' var errs_' + ($lvl) + ' = errors;';
3960 var $valid = 'valid' + $lvl,
3961 $breakOnError = !it.opts.allErrors,
3962 $closingBraces1 = '',
3963 $closingBraces2 = '',
3965 var $typeSchema = it.schema.type,
3966 $typeIsArray = Array.isArray($typeSchema);
3967 if ($typeSchema && it.opts.coerceTypes) {
3968 var $coerceToTypes = it.util.coerceToTypes($typeSchema);
3969 if ($coerceToTypes) {
3970 var $schemaPath = it.schemaPath + '.type',
3971 $errSchemaPath = it.errSchemaPath + '/type',
3972 $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
3973 out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
3974 var $dataType = 'dataType' + $lvl,
3975 $coerced = 'coerced' + $lvl;
3976 out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; ';
3977 var $bracesCoercion = '';
3978 var arr1 = $coerceToTypes;
3981 l1 = arr1.length - 1;
3983 $type = arr1[$i += 1];
3985 out += ' if (' + ($coerced) + ' === undefined) { ';
3986 $bracesCoercion += '}';
3988 if ($type == 'string') {
3989 out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
3990 } else if ($type == 'number' || $type == 'integer') {
3991 out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
3992 if ($type == 'integer') {
3993 out += ' && !(' + ($data) + ' % 1)';
3995 out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
3996 } else if ($type == 'boolean') {
3997 out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
3998 } else if ($type == 'null') {
3999 out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
4003 out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
4004 var $$outStack = $$outStack || [];
4005 $$outStack.push(out);
4006 out = ''; /* istanbul ignore else */
4007 if (it.createErrors !== false) {
4008 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
4010 out += '' + ($typeSchema.join(","));
4012 out += '' + ($typeSchema);
4015 if (it.opts.messages !== false) {
4016 out += ' , message: \'should be ';
4018 out += '' + ($typeSchema.join(","));
4020 out += '' + ($typeSchema);
4024 if (it.opts.verbose) {
4025 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4032 out = $$outStack.pop();
4033 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4035 out += ' throw new ValidationError([' + (__err) + ']); ';
4037 out += ' validate.errors = [' + (__err) + ']; return false; ';
4040 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4042 out += ' } else { ';
4044 var $parentData = 'data' + (($dataLvl - 1) || ''),
4045 $dataProperty = it.dataPathArr[$dataLvl];
4046 out += ' ' + ($data) + ' = ' + ($parentData) + '[' + ($dataProperty) + '] = ' + ($coerced) + '; ';
4048 out += ' data = ' + ($coerced) + '; if (parentData !== undefined) parentData[parentDataProperty] = ' + ($coerced) + '; ';
4053 var arr2 = it.RULES;
4055 var $rulesGroup, i2 = -1,
4056 l2 = arr2.length - 1;
4058 $rulesGroup = arr2[i2 += 1];
4059 if ($shouldUseGroup($rulesGroup)) {
4060 if ($rulesGroup.type) {
4061 out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
4063 if (it.opts.useDefaults && !it.compositeRule) {
4064 if ($rulesGroup.type == 'object' && it.schema.properties) {
4065 var $schema = it.schema.properties,
4066 $schemaKeys = Object.keys($schema);
4067 var arr3 = $schemaKeys;
4069 var $propertyKey, i3 = -1,
4070 l3 = arr3.length - 1;
4072 $propertyKey = arr3[i3 += 1];
4073 var $sch = $schema[$propertyKey];
4074 if ($sch.default !== undefined) {
4075 var $passData = $data + it.util.getProperty($propertyKey);
4076 out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
4077 if (it.opts.useDefaults == 'shared') {
4078 out += ' ' + (it.useDefault($sch.default)) + ' ';
4080 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4086 } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
4087 var arr4 = it.schema.items;
4090 l4 = arr4.length - 1;
4092 $sch = arr4[$i += 1];
4093 if ($sch.default !== undefined) {
4094 var $passData = $data + '[' + $i + ']';
4095 out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
4096 if (it.opts.useDefaults == 'shared') {
4097 out += ' ' + (it.useDefault($sch.default)) + ' ';
4099 out += ' ' + (JSON.stringify($sch.default)) + ' ';
4107 var arr5 = $rulesGroup.rules;
4110 l5 = arr5.length - 1;
4112 $rule = arr5[i5 += 1];
4113 if ($shouldUseRule($rule)) {
4115 var $schema = it.schema[$rule.keyword],
4116 $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it),
4117 $ruleErrs = $ruleValidate.code + '.errors',
4118 $schemaPath = it.schemaPath + '.' + $rule.keyword,
4119 $errSchemaPath = it.errSchemaPath + '/' + $rule.keyword,
4120 $errs = 'errs' + $lvl,
4122 $ruleErr = 'ruleErr' + $lvl,
4123 $rDef = $rule.definition,
4124 $asyncKeyword = $rDef.async,
4125 $inline = $rDef.inline,
4126 $macro = $rDef.macro;
4127 if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
4128 if (!($inline || $macro)) {
4129 out += '' + ($ruleErrs) + ' = null;';
4131 out += 'var ' + ($errs) + ' = errors;var valid' + ($lvl) + ';';
4132 if ($inline && $rDef.statements) {
4133 out += ' ' + ($ruleValidate.validate);
4134 } else if ($macro) {
4135 var $it = it.util.copy(it);
4137 $it.schema = $ruleValidate.validate;
4138 $it.schemaPath = '';
4139 var $wasComposite = it.compositeRule;
4140 it.compositeRule = $it.compositeRule = true;
4141 var $code = it.validate($it).replace(/validate\.schema/g, $ruleValidate.code);
4142 it.compositeRule = $it.compositeRule = $wasComposite;
4143 out += ' ' + ($code);
4144 } else if ($rDef.compile || $rDef.validate) {
4145 var $$outStack = $$outStack || [];
4146 $$outStack.push(out);
4148 out += ' ' + ($ruleValidate.code) + '.call( ';
4149 if (it.opts.passContext) {
4154 if ($rDef.compile || $rDef.schema === false) {
4155 out += ' , ' + ($data) + ' ';
4157 out += ' , validate.schema' + ($schemaPath) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
4159 out += ' , (dataPath || \'\')';
4160 if (it.errorPath != '""') {
4161 out += ' + ' + (it.errorPath);
4164 out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
4166 out += ' , parentData , parentDataProperty ';
4169 var def_callRuleValidate = out;
4170 out = $$outStack.pop();
4171 if ($rDef.errors !== false) {
4172 if ($asyncKeyword) {
4173 $ruleErrs = 'customErrors' + $lvl;
4174 out += ' var ' + ($ruleErrs) + ' = null; try { valid' + ($lvl) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { valid' + ($lvl) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
4176 out += ' ' + ($ruleValidate.code) + '.errors = null; ';
4182 if ($rDef.statements) {
4183 out += ' valid' + ($lvl) + ' ';
4185 out += ' (' + ($ruleValidate.validate) + ') ';
4187 } else if ($macro) {
4188 out += ' valid' + ($it.level) + ' ';
4190 if ($asyncKeyword) {
4191 if ($rDef.errors === false) {
4192 out += ' (' + (it.yieldAwait) + (def_callRuleValidate) + ') ';
4194 out += ' valid' + ($lvl) + ' ';
4197 out += ' ' + (def_callRuleValidate) + ' ';
4201 $errorKeyword = $rule.keyword;
4202 var $$outStack = $$outStack || [];
4203 $$outStack.push(out);
4205 var $$outStack = $$outStack || [];
4206 $$outStack.push(out);
4207 out = ''; /* istanbul ignore else */
4208 if (it.createErrors !== false) {
4209 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } ';
4210 if (it.opts.messages !== false) {
4211 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
4213 if (it.opts.verbose) {
4214 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4221 out = $$outStack.pop();
4222 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4224 out += ' throw new ValidationError([' + (__err) + ']); ';
4226 out += ' validate.errors = [' + (__err) + ']; return false; ';
4229 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4231 var def_customError = out;
4232 out = $$outStack.pop();
4235 if ($rDef.errors != 'full') {
4236 out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
4237 if (it.opts.verbose) {
4238 out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
4243 if ($rDef.errors === false) {
4244 out += ' ' + (def_customError) + ' ';
4246 out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
4247 if (it.opts.verbose) {
4248 out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
4253 } else if ($macro) {
4254 out += ' var err = '; /* istanbul ignore else */
4255 if (it.createErrors !== false) {
4256 out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } ';
4257 if (it.opts.messages !== false) {
4258 out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
4260 if (it.opts.verbose) {
4261 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4267 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4268 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4270 out += ' throw new ValidationError(vErrors); ';
4272 out += ' validate.errors = vErrors; return false ';
4276 if ($rDef.errors === false) {
4277 out += ' ' + (def_customError) + ' ';
4279 out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
4280 if (it.opts.verbose) {
4281 out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
4283 out += ' } } else { ' + (def_customError) + ' } ';
4286 $errorKeyword = undefined;
4288 if ($breakOnError) {
4292 out += ' ' + ($rule.code(it, $rule.keyword)) + ' ';
4294 if ($breakOnError) {
4295 $closingBraces1 += '}';
4300 if ($breakOnError) {
4301 out += ' ' + ($closingBraces1) + ' ';
4302 $closingBraces1 = '';
4304 if ($rulesGroup.type) {
4306 if ($typeSchema && $typeSchema === $rulesGroup.type) {
4307 var $typeChecked = true;
4309 var $schemaPath = it.schemaPath + '.type',
4310 $errSchemaPath = it.errSchemaPath + '/type';
4311 var $$outStack = $$outStack || [];
4312 $$outStack.push(out);
4313 out = ''; /* istanbul ignore else */
4314 if (it.createErrors !== false) {
4315 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
4317 out += '' + ($typeSchema.join(","));
4319 out += '' + ($typeSchema);
4322 if (it.opts.messages !== false) {
4323 out += ' , message: \'should be ';
4325 out += '' + ($typeSchema.join(","));
4327 out += '' + ($typeSchema);
4331 if (it.opts.verbose) {
4332 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4339 out = $$outStack.pop();
4340 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4342 out += ' throw new ValidationError([' + (__err) + ']); ';
4344 out += ' validate.errors = [' + (__err) + ']; return false; ';
4347 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4352 if ($breakOnError) {
4353 out += ' if (errors === ';
4357 out += 'errs_' + ($lvl);
4360 $closingBraces2 += '}';
4365 if ($typeSchema && !$typeChecked && !(it.opts.coerceTypes && $coerceToTypes)) {
4366 var $schemaPath = it.schemaPath + '.type',
4367 $errSchemaPath = it.errSchemaPath + '/type',
4368 $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
4369 out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
4370 var $$outStack = $$outStack || [];
4371 $$outStack.push(out);
4372 out = ''; /* istanbul ignore else */
4373 if (it.createErrors !== false) {
4374 out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \'';
4376 out += '' + ($typeSchema.join(","));
4378 out += '' + ($typeSchema);
4381 if (it.opts.messages !== false) {
4382 out += ' , message: \'should be ';
4384 out += '' + ($typeSchema.join(","));
4386 out += '' + ($typeSchema);
4390 if (it.opts.verbose) {
4391 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4398 out = $$outStack.pop();
4399 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4401 out += ' throw new ValidationError([' + (__err) + ']); ';
4403 out += ' validate.errors = [' + (__err) + ']; return false; ';
4406 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4410 if ($breakOnError) {
4411 out += ' ' + ($closingBraces2) + ' ';
4415 out += ' if (errors === 0) return true; ';
4416 out += ' else throw new ValidationError(vErrors); ';
4418 out += ' validate.errors = vErrors; ';
4419 out += ' return errors === 0; ';
4423 out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
4425 out = it.util.cleanUpCode(out);
4426 if ($top && $breakOnError) {
4427 out = it.util.cleanUpVarErrors(out, $async);
4430 function $shouldUseGroup($rulesGroup) {
4431 for (var i = 0; i < $rulesGroup.rules.length; i++)
4432 if ($shouldUseRule($rulesGroup.rules[i])) return true;
4435 function $shouldUseRule($rule) {
4436 return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties === false || typeof it.schema.additionalProperties == 'object' || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length) || (it.opts.v5 && it.schema.patternGroups && Object.keys(it.schema.patternGroups).length)));
4441 },{}],35:[function(require,module,exports){
4444 var IDENTIFIER = /^[a-z_$][a-z0-9_$]*$/i;
4447 * Define custom keyword
4449 * @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
4450 * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
4452 module.exports = function addKeyword(keyword, definition) {
4453 /* eslint no-shadow: 0 */
4455 if (this.RULES.keywords[keyword])
4456 throw new Error('Keyword ' + keyword + ' is already defined');
4458 if (!IDENTIFIER.test(keyword))
4459 throw new Error('Keyword ' + keyword + ' is not a valid identifier');
4462 var dataType = definition.type;
4463 if (Array.isArray(dataType)) {
4464 var i, len = dataType.length;
4465 for (i=0; i<len; i++) checkDataType(dataType[i]);
4466 for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition);
4468 if (dataType) checkDataType(dataType);
4469 _addRule(keyword, dataType, definition);
4473 this.RULES.keywords[keyword] = true;
4474 this.RULES.all[keyword] = true;
4477 function _addRule(keyword, dataType, definition) {
4479 for (var i=0; i<self.RULES.length; i++) {
4480 var rg = self.RULES[i];
4481 if (rg.type == dataType) {
4488 ruleGroup = { type: dataType, rules: [] };
4489 self.RULES.push(ruleGroup);
4492 var rule = { keyword: keyword, definition: definition, custom: true };
4493 ruleGroup.rules.push(rule);
4497 function checkDataType(dataType) {
4498 if (!self.RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
4502 },{}],36:[function(require,module,exports){
4504 "id": "http://json-schema.org/draft-04/schema#",
4505 "$schema": "http://json-schema.org/draft-04/schema#",
4506 "description": "Core schema meta-schema",
4511 "items": { "$ref": "#" }
4513 "positiveInteger": {
4517 "positiveIntegerDefault0": {
4518 "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
4521 "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
4525 "items": { "type": "string" },
4550 "exclusiveMinimum": true
4555 "exclusiveMaximum": {
4562 "exclusiveMinimum": {
4566 "maxLength": { "$ref": "#/definitions/positiveInteger" },
4567 "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
4572 "additionalItems": {
4574 { "type": "boolean" },
4582 { "$ref": "#/definitions/schemaArray" }
4586 "maxItems": { "$ref": "#/definitions/positiveInteger" },
4587 "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
4592 "maxProperties": { "$ref": "#/definitions/positiveInteger" },
4593 "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
4594 "required": { "$ref": "#/definitions/stringArray" },
4595 "additionalProperties": {
4597 { "type": "boolean" },
4604 "additionalProperties": { "$ref": "#" },
4609 "additionalProperties": { "$ref": "#" },
4612 "patternProperties": {
4614 "additionalProperties": { "$ref": "#" },
4619 "additionalProperties": {
4622 { "$ref": "#/definitions/stringArray" }
4633 { "$ref": "#/definitions/simpleTypes" },
4636 "items": { "$ref": "#/definitions/simpleTypes" },
4642 "allOf": { "$ref": "#/definitions/schemaArray" },
4643 "anyOf": { "$ref": "#/definitions/schemaArray" },
4644 "oneOf": { "$ref": "#/definitions/schemaArray" },
4645 "not": { "$ref": "#" }
4648 "exclusiveMaximum": [ "maximum" ],
4649 "exclusiveMinimum": [ "minimum" ]
4654 },{}],37:[function(require,module,exports){
4656 "id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#",
4657 "$schema": "http://json-schema.org/draft-04/schema#",
4658 "description": "Core schema meta-schema (v5 proposals)",
4663 "items": { "$ref": "#" }
4665 "positiveInteger": {
4669 "positiveIntegerDefault0": {
4670 "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
4673 "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
4677 "items": { "type": "string" },
4683 "required": [ "$data" ],
4687 "format": "relative-json-pointer"
4690 "additionalProperties": false
4715 "exclusiveMinimum": true
4717 { "$ref": "#/definitions/$data" }
4722 { "type": "number" },
4723 { "$ref": "#/definitions/$data" }
4726 "exclusiveMaximum": {
4732 { "$ref": "#/definitions/$data" }
4737 { "type": "number" },
4738 { "$ref": "#/definitions/$data" }
4741 "exclusiveMinimum": {
4747 { "$ref": "#/definitions/$data" }
4752 { "$ref": "#/definitions/positiveInteger" },
4753 { "$ref": "#/definitions/$data" }
4758 { "$ref": "#/definitions/positiveIntegerDefault0" },
4759 { "$ref": "#/definitions/$data" }
4768 { "$ref": "#/definitions/$data" }
4771 "additionalItems": {
4773 { "type": "boolean" },
4775 { "$ref": "#/definitions/$data" }
4782 { "$ref": "#/definitions/schemaArray" }
4788 { "$ref": "#/definitions/positiveInteger" },
4789 { "$ref": "#/definitions/$data" }
4794 { "$ref": "#/definitions/positiveIntegerDefault0" },
4795 { "$ref": "#/definitions/$data" }
4804 { "$ref": "#/definitions/$data" }
4809 { "$ref": "#/definitions/positiveInteger" },
4810 { "$ref": "#/definitions/$data" }
4815 { "$ref": "#/definitions/positiveIntegerDefault0" },
4816 { "$ref": "#/definitions/$data" }
4821 { "$ref": "#/definitions/stringArray" },
4822 { "$ref": "#/definitions/$data" }
4825 "additionalProperties": {
4827 { "type": "boolean" },
4829 { "$ref": "#/definitions/$data" }
4835 "additionalProperties": { "$ref": "#" },
4840 "additionalProperties": { "$ref": "#" },
4843 "patternProperties": {
4845 "additionalProperties": { "$ref": "#" },
4850 "additionalProperties": {
4853 { "$ref": "#/definitions/stringArray" }
4864 { "$ref": "#/definitions/$data" }
4869 { "$ref": "#/definitions/simpleTypes" },
4872 "items": { "$ref": "#/definitions/simpleTypes" },
4878 "allOf": { "$ref": "#/definitions/schemaArray" },
4879 "anyOf": { "$ref": "#/definitions/schemaArray" },
4880 "oneOf": { "$ref": "#/definitions/schemaArray" },
4881 "not": { "$ref": "#" },
4884 { "type": "string" },
4885 { "$ref": "#/definitions/$data" }
4890 { "type": "string" },
4891 { "$ref": "#/definitions/$data" }
4896 { "type": "string" },
4897 { "$ref": "#/definitions/$data" }
4900 "formatExclusiveMaximum": {
4906 { "$ref": "#/definitions/$data" }
4909 "formatExclusiveMinimum": {
4915 { "$ref": "#/definitions/$data" }
4921 { "$ref": "#/definitions/$data" }
4924 "contains": { "$ref": "#" },
4927 "additionalProperties": {
4929 "required": [ "schema" ],
4933 { "$ref": "#/definitions/positiveInteger" },
4934 { "$ref": "#/definitions/$data" }
4939 { "$ref": "#/definitions/positiveIntegerDefault0" },
4940 { "$ref": "#/definitions/$data" }
4943 "schema": { "$ref": "#" }
4945 "additionalProperties": false
4952 "required": [ "then" ],
4954 "if": { "$ref": "#" },
4957 { "type": "boolean" },
4961 "continue": { "type": "boolean" }
4963 "additionalProperties": false,
4965 "continue": [ "if" ]
4971 "exclusiveMaximum": [ "maximum" ],
4972 "exclusiveMinimum": [ "minimum" ],
4973 "formatMaximum": [ "format" ],
4974 "formatMinimum": [ "format" ],
4975 "formatExclusiveMaximum": [ "formatMaximum" ],
4976 "formatExclusiveMinimum": [ "formatMinimum" ]
4981 },{}],38:[function(require,module,exports){
4984 var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
4988 META_SCHEMA_ID: META_SCHEMA_ID
4992 function enableV5(ajv) {
4993 var inlineFunctions = {
4994 'switch': require('./dotjs/switch'),
4995 'constant': require('./dotjs/constant'),
4996 '_formatLimit': require('./dotjs/_formatLimit'),
4997 'patternRequired': require('./dotjs/patternRequired')
5000 if (ajv._opts.meta !== false) {
5001 var metaSchema = require('./refs/json-schema-v5.json');
5002 ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
5004 _addKeyword('constant');
5005 ajv.addKeyword('contains', { type: 'array', macro: containsMacro });
5007 _addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit);
5008 _addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit);
5009 ajv.addKeyword('formatExclusiveMaximum');
5010 ajv.addKeyword('formatExclusiveMinimum');
5012 ajv.addKeyword('patternGroups'); // implemented in properties.jst
5013 _addKeyword('patternRequired', 'object');
5014 _addKeyword('switch');
5017 function _addKeyword(keyword, types, inlineFunc) {
5019 inline: inlineFunc || inlineFunctions[keyword],
5023 if (types) definition.type = types;
5024 ajv.addKeyword(keyword, definition);
5029 function containsMacro(schema) {
5031 not: { items: { not: schema } }
5035 },{"./dotjs/_formatLimit":12,"./dotjs/constant":19,"./dotjs/patternRequired":28,"./dotjs/switch":32,"./refs/json-schema-v5.json":37}],39:[function(require,module,exports){
5037 /*! https://mths.be/punycode v1.4.1 by @mathias */
5040 /** Detect free variables */
5041 var freeExports = typeof exports == 'object' && exports &&
5042 !exports.nodeType && exports;
5043 var freeModule = typeof module == 'object' && module &&
5044 !module.nodeType && module;
5045 var freeGlobal = typeof global == 'object' && global;
5047 freeGlobal.global === freeGlobal ||
5048 freeGlobal.window === freeGlobal ||
5049 freeGlobal.self === freeGlobal
5055 * The `punycode` object.
5061 /** Highest positive signed 32-bit float value */
5062 maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
5064 /** Bootstring parameters */
5071 initialN = 128, // 0x80
5072 delimiter = '-', // '\x2D'
5074 /** Regular expressions */
5075 regexPunycode = /^xn--/,
5076 regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
5077 regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
5079 /** Error messages */
5081 'overflow': 'Overflow: input needs wider integers to process',
5082 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
5083 'invalid-input': 'Invalid input'
5086 /** Convenience shortcuts */
5087 baseMinusTMin = base - tMin,
5089 stringFromCharCode = String.fromCharCode,
5091 /** Temporary variable */
5094 /*--------------------------------------------------------------------------*/
5097 * A generic error utility function.
5099 * @param {String} type The error type.
5100 * @returns {Error} Throws a `RangeError` with the applicable error message.
5102 function error(type) {
5103 throw new RangeError(errors[type]);
5107 * A generic `Array#map` utility function.
5109 * @param {Array} array The array to iterate over.
5110 * @param {Function} callback The function that gets called for every array
5112 * @returns {Array} A new array of values returned by the callback function.
5114 function map(array, fn) {
5115 var length = array.length;
5118 result[length] = fn(array[length]);
5124 * A simple `Array#map`-like wrapper to work with domain name strings or email
5127 * @param {String} domain The domain name or email address.
5128 * @param {Function} callback The function that gets called for every
5130 * @returns {Array} A new string of characters returned by the callback
5133 function mapDomain(string, fn) {
5134 var parts = string.split('@');
5136 if (parts.length > 1) {
5137 // In email addresses, only the domain name should be punycoded. Leave
5138 // the local part (i.e. everything up to `@`) intact.
5139 result = parts[0] + '@';
5142 // Avoid `split(regex)` for IE8 compatibility. See #17.
5143 string = string.replace(regexSeparators, '\x2E');
5144 var labels = string.split('.');
5145 var encoded = map(labels, fn).join('.');
5146 return result + encoded;
5150 * Creates an array containing the numeric code points of each Unicode
5151 * character in the string. While JavaScript uses UCS-2 internally,
5152 * this function will convert a pair of surrogate halves (each of which
5153 * UCS-2 exposes as separate characters) into a single code point,
5155 * @see `punycode.ucs2.encode`
5156 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5157 * @memberOf punycode.ucs2
5159 * @param {String} string The Unicode input string (UCS-2).
5160 * @returns {Array} The new array of code points.
5162 function ucs2decode(string) {
5165 length = string.length,
5168 while (counter < length) {
5169 value = string.charCodeAt(counter++);
5170 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
5171 // high surrogate, and there is a next character
5172 extra = string.charCodeAt(counter++);
5173 if ((extra & 0xFC00) == 0xDC00) { // low surrogate
5174 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
5176 // unmatched surrogate; only append this code unit, in case the next
5177 // code unit is the high surrogate of a surrogate pair
5189 * Creates a string based on an array of numeric code points.
5190 * @see `punycode.ucs2.decode`
5191 * @memberOf punycode.ucs2
5193 * @param {Array} codePoints The array of numeric code points.
5194 * @returns {String} The new Unicode string (UCS-2).
5196 function ucs2encode(array) {
5197 return map(array, function(value) {
5199 if (value > 0xFFFF) {
5201 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
5202 value = 0xDC00 | value & 0x3FF;
5204 output += stringFromCharCode(value);
5210 * Converts a basic code point into a digit/integer.
5211 * @see `digitToBasic()`
5213 * @param {Number} codePoint The basic numeric code point value.
5214 * @returns {Number} The numeric value of a basic code point (for use in
5215 * representing integers) in the range `0` to `base - 1`, or `base` if
5216 * the code point does not represent a value.
5218 function basicToDigit(codePoint) {
5219 if (codePoint - 48 < 10) {
5220 return codePoint - 22;
5222 if (codePoint - 65 < 26) {
5223 return codePoint - 65;
5225 if (codePoint - 97 < 26) {
5226 return codePoint - 97;
5232 * Converts a digit/integer into a basic code point.
5233 * @see `basicToDigit()`
5235 * @param {Number} digit The numeric value of a basic code point.
5236 * @returns {Number} The basic code point whose value (when used for
5237 * representing integers) is `digit`, which needs to be in the range
5238 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
5239 * used; else, the lowercase form is used. The behavior is undefined
5240 * if `flag` is non-zero and `digit` has no uppercase form.
5242 function digitToBasic(digit, flag) {
5243 // 0..25 map to ASCII a..z or A..Z
5244 // 26..35 map to ASCII 0..9
5245 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
5249 * Bias adaptation function as per section 3.4 of RFC 3492.
5250 * https://tools.ietf.org/html/rfc3492#section-3.4
5253 function adapt(delta, numPoints, firstTime) {
5255 delta = firstTime ? floor(delta / damp) : delta >> 1;
5256 delta += floor(delta / numPoints);
5257 for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
5258 delta = floor(delta / baseMinusTMin);
5260 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
5264 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
5266 * @memberOf punycode
5267 * @param {String} input The Punycode string of ASCII-only symbols.
5268 * @returns {String} The resulting string of Unicode symbols.
5270 function decode(input) {
5273 inputLength = input.length,
5286 /** Cached calculation results */
5289 // Handle the basic code points: let `basic` be the number of input code
5290 // points before the last delimiter, or `0` if there is none, then copy
5291 // the first basic code points to the output.
5293 basic = input.lastIndexOf(delimiter);
5298 for (j = 0; j < basic; ++j) {
5299 // if it's not a basic code point
5300 if (input.charCodeAt(j) >= 0x80) {
5303 output.push(input.charCodeAt(j));
5306 // Main decoding loop: start just after the last delimiter if any basic code
5307 // points were copied; start at the beginning otherwise.
5309 for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
5311 // `index` is the index of the next character to be consumed.
5312 // Decode a generalized variable-length integer into `delta`,
5313 // which gets added to `i`. The overflow checking is easier
5314 // if we increase `i` as we go, then subtract off its starting
5315 // value at the end to obtain `delta`.
5316 for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
5318 if (index >= inputLength) {
5319 error('invalid-input');
5322 digit = basicToDigit(input.charCodeAt(index++));
5324 if (digit >= base || digit > floor((maxInt - i) / w)) {
5329 t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
5335 baseMinusT = base - t;
5336 if (w > floor(maxInt / baseMinusT)) {
5344 out = output.length + 1;
5345 bias = adapt(i - oldi, out, oldi == 0);
5347 // `i` was supposed to wrap around from `out` to `0`,
5348 // incrementing `n` each time, so we'll fix that now:
5349 if (floor(i / out) > maxInt - n) {
5353 n += floor(i / out);
5356 // Insert `n` at position `i` of the output
5357 output.splice(i++, 0, n);
5361 return ucs2encode(output);
5365 * Converts a string of Unicode symbols (e.g. a domain name label) to a
5366 * Punycode string of ASCII-only symbols.
5367 * @memberOf punycode
5368 * @param {String} input The string of Unicode symbols.
5369 * @returns {String} The resulting Punycode string of ASCII-only symbols.
5371 function encode(input) {
5384 /** `inputLength` will hold the number of code points in `input`. */
5386 /** Cached calculation results */
5387 handledCPCountPlusOne,
5391 // Convert the input in UCS-2 to Unicode
5392 input = ucs2decode(input);
5395 inputLength = input.length;
5397 // Initialize the state
5402 // Handle the basic code points
5403 for (j = 0; j < inputLength; ++j) {
5404 currentValue = input[j];
5405 if (currentValue < 0x80) {
5406 output.push(stringFromCharCode(currentValue));
5410 handledCPCount = basicLength = output.length;
5412 // `handledCPCount` is the number of code points that have been handled;
5413 // `basicLength` is the number of basic code points.
5415 // Finish the basic string - if it is not empty - with a delimiter
5417 output.push(delimiter);
5420 // Main encoding loop:
5421 while (handledCPCount < inputLength) {
5423 // All non-basic code points < n have been handled already. Find the next
5425 for (m = maxInt, j = 0; j < inputLength; ++j) {
5426 currentValue = input[j];
5427 if (currentValue >= n && currentValue < m) {
5432 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
5433 // but guard against overflow
5434 handledCPCountPlusOne = handledCPCount + 1;
5435 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
5439 delta += (m - n) * handledCPCountPlusOne;
5442 for (j = 0; j < inputLength; ++j) {
5443 currentValue = input[j];
5445 if (currentValue < n && ++delta > maxInt) {
5449 if (currentValue == n) {
5450 // Represent delta as a generalized variable-length integer
5451 for (q = delta, k = base; /* no condition */; k += base) {
5452 t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
5457 baseMinusT = base - t;
5459 stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
5461 q = floor(qMinusT / baseMinusT);
5464 output.push(stringFromCharCode(digitToBasic(q, 0)));
5465 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
5475 return output.join('');
5479 * Converts a Punycode string representing a domain name or an email address
5480 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
5481 * it doesn't matter if you call it on a string that has already been
5482 * converted to Unicode.
5483 * @memberOf punycode
5484 * @param {String} input The Punycoded domain name or email address to
5485 * convert to Unicode.
5486 * @returns {String} The Unicode representation of the given Punycode
5489 function toUnicode(input) {
5490 return mapDomain(input, function(string) {
5491 return regexPunycode.test(string)
5492 ? decode(string.slice(4).toLowerCase())
5498 * Converts a Unicode string representing a domain name or an email address to
5499 * Punycode. Only the non-ASCII parts of the domain name will be converted,
5500 * i.e. it doesn't matter if you call it with a domain that's already in
5502 * @memberOf punycode
5503 * @param {String} input The domain name or email address to convert, as a
5505 * @returns {String} The Punycode representation of the given domain name or
5508 function toASCII(input) {
5509 return mapDomain(input, function(string) {
5510 return regexNonASCII.test(string)
5511 ? 'xn--' + encode(string)
5516 /*--------------------------------------------------------------------------*/
5518 /** Define the public API */
5521 * A string representing the current Punycode.js version number.
5522 * @memberOf punycode
5527 * An object of methods to convert from JavaScript's internal character
5528 * representation (UCS-2) to Unicode code points, and back.
5529 * @see <https://mathiasbynens.be/notes/javascript-encoding>
5530 * @memberOf punycode
5534 'decode': ucs2decode,
5535 'encode': ucs2encode
5540 'toUnicode': toUnicode
5543 /** Expose `punycode` */
5544 // Some AMD build optimizers, like r.js, check for specific condition patterns
5545 // like the following:
5547 typeof define == 'function' &&
5548 typeof define.amd == 'object' &&
5551 define('punycode', function() {
5554 } else if (freeExports && freeModule) {
5555 if (module.exports == freeExports) {
5556 // in Node.js, io.js, or RingoJS v0.8.0+
5557 freeModule.exports = punycode;
5559 // in Narwhal or RingoJS v0.7.0-
5560 for (key in punycode) {
5561 punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
5565 // in Rhino or a web browser
5566 root.punycode = punycode;
5571 }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
5572 },{}],40:[function(require,module,exports){
5573 // Copyright Joyent, Inc. and other Node contributors.
5575 // Permission is hereby granted, free of charge, to any person obtaining a
5576 // copy of this software and associated documentation files (the
5577 // "Software"), to deal in the Software without restriction, including
5578 // without limitation the rights to use, copy, modify, merge, publish,
5579 // distribute, sublicense, and/or sell copies of the Software, and to permit
5580 // persons to whom the Software is furnished to do so, subject to the
5581 // following conditions:
5583 // The above copyright notice and this permission notice shall be included
5584 // in all copies or substantial portions of the Software.
5586 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5587 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5588 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5589 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5590 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5591 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5592 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5596 // If obj.hasOwnProperty has been overridden, then calling
5597 // obj.hasOwnProperty(prop) will break.
5598 // See: https://github.com/joyent/node/issues/1707
5599 function hasOwnProperty(obj, prop) {
5600 return Object.prototype.hasOwnProperty.call(obj, prop);
5603 module.exports = function(qs, sep, eq, options) {
5608 if (typeof qs !== 'string' || qs.length === 0) {
5616 if (options && typeof options.maxKeys === 'number') {
5617 maxKeys = options.maxKeys;
5620 var len = qs.length;
5621 // maxKeys <= 0 means that we should not limit keys count
5622 if (maxKeys > 0 && len > maxKeys) {
5626 for (var i = 0; i < len; ++i) {
5627 var x = qs[i].replace(regexp, '%20'),
5628 idx = x.indexOf(eq),
5632 kstr = x.substr(0, idx);
5633 vstr = x.substr(idx + 1);
5639 k = decodeURIComponent(kstr);
5640 v = decodeURIComponent(vstr);
5642 if (!hasOwnProperty(obj, k)) {
5644 } else if (isArray(obj[k])) {
5647 obj[k] = [obj[k], v];
5654 var isArray = Array.isArray || function (xs) {
5655 return Object.prototype.toString.call(xs) === '[object Array]';
5658 },{}],41:[function(require,module,exports){
5659 // Copyright Joyent, Inc. and other Node contributors.
5661 // Permission is hereby granted, free of charge, to any person obtaining a
5662 // copy of this software and associated documentation files (the
5663 // "Software"), to deal in the Software without restriction, including
5664 // without limitation the rights to use, copy, modify, merge, publish,
5665 // distribute, sublicense, and/or sell copies of the Software, and to permit
5666 // persons to whom the Software is furnished to do so, subject to the
5667 // following conditions:
5669 // The above copyright notice and this permission notice shall be included
5670 // in all copies or substantial portions of the Software.
5672 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5673 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5674 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5675 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5676 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5677 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5678 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5682 var stringifyPrimitive = function(v) {
5688 return v ? 'true' : 'false';
5691 return isFinite(v) ? v : '';
5698 module.exports = function(obj, sep, eq, name) {
5705 if (typeof obj === 'object') {
5706 return map(objectKeys(obj), function(k) {
5707 var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
5708 if (isArray(obj[k])) {
5709 return map(obj[k], function(v) {
5710 return ks + encodeURIComponent(stringifyPrimitive(v));
5713 return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
5719 if (!name) return '';
5720 return encodeURIComponent(stringifyPrimitive(name)) + eq +
5721 encodeURIComponent(stringifyPrimitive(obj));
5724 var isArray = Array.isArray || function (xs) {
5725 return Object.prototype.toString.call(xs) === '[object Array]';
5728 function map (xs, f) {
5729 if (xs.map) return xs.map(f);
5731 for (var i = 0; i < xs.length; i++) {
5732 res.push(f(xs[i], i));
5737 var objectKeys = Object.keys || function (obj) {
5739 for (var key in obj) {
5740 if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
5745 },{}],42:[function(require,module,exports){
5748 exports.decode = exports.parse = require('./decode');
5749 exports.encode = exports.stringify = require('./encode');
5751 },{"./decode":40,"./encode":41}],43:[function(require,module,exports){
5752 // Copyright Joyent, Inc. and other Node contributors.
5754 // Permission is hereby granted, free of charge, to any person obtaining a
5755 // copy of this software and associated documentation files (the
5756 // "Software"), to deal in the Software without restriction, including
5757 // without limitation the rights to use, copy, modify, merge, publish,
5758 // distribute, sublicense, and/or sell copies of the Software, and to permit
5759 // persons to whom the Software is furnished to do so, subject to the
5760 // following conditions:
5762 // The above copyright notice and this permission notice shall be included
5763 // in all copies or substantial portions of the Software.
5765 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
5766 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5767 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
5768 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
5769 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
5770 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
5771 // USE OR OTHER DEALINGS IN THE SOFTWARE.
5775 var punycode = require('punycode');
5776 var util = require('./util');
5778 exports.parse = urlParse;
5779 exports.resolve = urlResolve;
5780 exports.resolveObject = urlResolveObject;
5781 exports.format = urlFormat;
5786 this.protocol = null;
5787 this.slashes = null;
5791 this.hostname = null;
5795 this.pathname = null;
5800 // Reference: RFC 3986, RFC 1808, RFC 2396
5802 // define these here so at least they only have to be
5803 // compiled once on the first module load.
5804 var protocolPattern = /^([a-z0-9.+-]+:)/i,
5805 portPattern = /:[0-9]*$/,
5807 // Special case for a simple path URL
5808 simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
5810 // RFC 2396: characters reserved for delimiting URLs.
5811 // We actually just auto-escape these.
5812 delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
5814 // RFC 2396: characters not allowed for various reasons.
5815 unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
5817 // Allowed by RFCs, but cause of XSS attacks. Always escape these.
5818 autoEscape = ['\''].concat(unwise),
5819 // Characters that are never ever allowed in a hostname.
5820 // Note that any invalid chars are also handled, but these
5821 // are the ones that are *expected* to be seen, so we fast-path
5823 nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
5824 hostEndingChars = ['/', '?', '#'],
5825 hostnameMaxLen = 255,
5826 hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
5827 hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
5828 // protocols that can allow "unsafe" and "unwise" chars.
5833 // protocols that never have a hostname.
5834 hostlessProtocol = {
5838 // protocols that always contain a // bit.
5851 querystring = require('querystring');
5853 function urlParse(url, parseQueryString, slashesDenoteHost) {
5854 if (url && util.isObject(url) && url instanceof Url) return url;
5857 u.parse(url, parseQueryString, slashesDenoteHost);
5861 Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
5862 if (!util.isString(url)) {
5863 throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
5866 // Copy chrome, IE, opera backslash-handling behavior.
5867 // Back slashes before the query string get converted to forward slashes
5868 // See: https://code.google.com/p/chromium/issues/detail?id=25916
5869 var queryIndex = url.indexOf('?'),
5871 (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
5872 uSplit = url.split(splitter),
5874 uSplit[0] = uSplit[0].replace(slashRegex, '/');
5875 url = uSplit.join(splitter);
5879 // trim before proceeding.
5880 // This is to support parse stuff like " http://foo.com \n"
5883 if (!slashesDenoteHost && url.split('#').length === 1) {
5884 // Try fast path regexp
5885 var simplePath = simplePathPattern.exec(rest);
5889 this.pathname = simplePath[1];
5890 if (simplePath[2]) {
5891 this.search = simplePath[2];
5892 if (parseQueryString) {
5893 this.query = querystring.parse(this.search.substr(1));
5895 this.query = this.search.substr(1);
5897 } else if (parseQueryString) {
5905 var proto = protocolPattern.exec(rest);
5908 var lowerProto = proto.toLowerCase();
5909 this.protocol = lowerProto;
5910 rest = rest.substr(proto.length);
5913 // figure out if it's got a host
5914 // user@server is *always* interpreted as a hostname, and url
5915 // resolution will treat //foo/bar as host=foo,path=bar because that's
5916 // how the browser resolves relative URLs.
5917 if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
5918 var slashes = rest.substr(0, 2) === '//';
5919 if (slashes && !(proto && hostlessProtocol[proto])) {
5920 rest = rest.substr(2);
5921 this.slashes = true;
5925 if (!hostlessProtocol[proto] &&
5926 (slashes || (proto && !slashedProtocol[proto]))) {
5928 // there's a hostname.
5929 // the first instance of /, ?, ;, or # ends the host.
5931 // If there is an @ in the hostname, then non-host chars *are* allowed
5932 // to the left of the last @ sign, unless some host-ending character
5933 // comes *before* the @-sign.
5934 // URLs are obnoxious.
5937 // http://a@b@c/ => user:a@b host:c
5938 // http://a@b?@c => user:a host:c path:/?@c
5940 // v0.12 TODO(isaacs): This is not quite how Chrome does things.
5941 // Review our test case against browsers more comprehensively.
5943 // find the first instance of any hostEndingChars
5945 for (var i = 0; i < hostEndingChars.length; i++) {
5946 var hec = rest.indexOf(hostEndingChars[i]);
5947 if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
5951 // at this point, either we have an explicit point where the
5952 // auth portion cannot go past, or the last @ char is the decider.
5954 if (hostEnd === -1) {
5955 // atSign can be anywhere.
5956 atSign = rest.lastIndexOf('@');
5958 // atSign must be in auth portion.
5959 // http://a@b/c@d => host:b auth:a path:/c@d
5960 atSign = rest.lastIndexOf('@', hostEnd);
5963 // Now we have a portion which is definitely the auth.
5965 if (atSign !== -1) {
5966 auth = rest.slice(0, atSign);
5967 rest = rest.slice(atSign + 1);
5968 this.auth = decodeURIComponent(auth);
5971 // the host is the remaining to the left of the first non-host char
5973 for (var i = 0; i < nonHostChars.length; i++) {
5974 var hec = rest.indexOf(nonHostChars[i]);
5975 if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
5978 // if we still have not hit it, then the entire thing is a host.
5980 hostEnd = rest.length;
5982 this.host = rest.slice(0, hostEnd);
5983 rest = rest.slice(hostEnd);
5988 // we've indicated that there is a hostname,
5989 // so even if it's empty, it has to be present.
5990 this.hostname = this.hostname || '';
5992 // if hostname begins with [ and ends with ]
5993 // assume that it's an IPv6 address.
5994 var ipv6Hostname = this.hostname[0] === '[' &&
5995 this.hostname[this.hostname.length - 1] === ']';
5997 // validate a little.
5998 if (!ipv6Hostname) {
5999 var hostparts = this.hostname.split(/\./);
6000 for (var i = 0, l = hostparts.length; i < l; i++) {
6001 var part = hostparts[i];
6002 if (!part) continue;
6003 if (!part.match(hostnamePartPattern)) {
6005 for (var j = 0, k = part.length; j < k; j++) {
6006 if (part.charCodeAt(j) > 127) {
6007 // we replace non-ASCII char with a temporary placeholder
6008 // we need this to make sure size of hostname is not
6009 // broken by replacing non-ASCII by nothing
6015 // we test again with ASCII char only
6016 if (!newpart.match(hostnamePartPattern)) {
6017 var validParts = hostparts.slice(0, i);
6018 var notHost = hostparts.slice(i + 1);
6019 var bit = part.match(hostnamePartStart);
6021 validParts.push(bit[1]);
6022 notHost.unshift(bit[2]);
6024 if (notHost.length) {
6025 rest = '/' + notHost.join('.') + rest;
6027 this.hostname = validParts.join('.');
6034 if (this.hostname.length > hostnameMaxLen) {
6037 // hostnames are always lower case.
6038 this.hostname = this.hostname.toLowerCase();
6041 if (!ipv6Hostname) {
6042 // IDNA Support: Returns a punycoded representation of "domain".
6043 // It only converts parts of the domain name that
6044 // have non-ASCII characters, i.e. it doesn't matter if
6045 // you call it with a domain that already is ASCII-only.
6046 this.hostname = punycode.toASCII(this.hostname);
6049 var p = this.port ? ':' + this.port : '';
6050 var h = this.hostname || '';
6052 this.href += this.host;
6054 // strip [ and ] from the hostname
6055 // the host field still retains them, though
6057 this.hostname = this.hostname.substr(1, this.hostname.length - 2);
6058 if (rest[0] !== '/') {
6064 // now rest is set to the post-host stuff.
6065 // chop off any delim chars.
6066 if (!unsafeProtocol[lowerProto]) {
6068 // First, make 100% sure that any "autoEscape" chars get
6069 // escaped, even if encodeURIComponent doesn't think they
6071 for (var i = 0, l = autoEscape.length; i < l; i++) {
6072 var ae = autoEscape[i];
6073 if (rest.indexOf(ae) === -1)
6075 var esc = encodeURIComponent(ae);
6079 rest = rest.split(ae).join(esc);
6084 // chop off from the tail first.
6085 var hash = rest.indexOf('#');
6087 // got a fragment string.
6088 this.hash = rest.substr(hash);
6089 rest = rest.slice(0, hash);
6091 var qm = rest.indexOf('?');
6093 this.search = rest.substr(qm);
6094 this.query = rest.substr(qm + 1);
6095 if (parseQueryString) {
6096 this.query = querystring.parse(this.query);
6098 rest = rest.slice(0, qm);
6099 } else if (parseQueryString) {
6100 // no query string, but parseQueryString still requested
6104 if (rest) this.pathname = rest;
6105 if (slashedProtocol[lowerProto] &&
6106 this.hostname && !this.pathname) {
6107 this.pathname = '/';
6110 //to support http.request
6111 if (this.pathname || this.search) {
6112 var p = this.pathname || '';
6113 var s = this.search || '';
6117 // finally, reconstruct the href based on what has been validated.
6118 this.href = this.format();
6122 // format a parsed object into a url string
6123 function urlFormat(obj) {
6124 // ensure it's an object, and not a string url.
6125 // If it's an obj, this is a no-op.
6126 // this way, you can call url_format() on strings
6127 // to clean up potentially wonky urls.
6128 if (util.isString(obj)) obj = urlParse(obj);
6129 if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
6130 return obj.format();
6133 Url.prototype.format = function() {
6134 var auth = this.auth || '';
6136 auth = encodeURIComponent(auth);
6137 auth = auth.replace(/%3A/i, ':');
6141 var protocol = this.protocol || '',
6142 pathname = this.pathname || '',
6143 hash = this.hash || '',
6148 host = auth + this.host;
6149 } else if (this.hostname) {
6150 host = auth + (this.hostname.indexOf(':') === -1 ?
6152 '[' + this.hostname + ']');
6154 host += ':' + this.port;
6159 util.isObject(this.query) &&
6160 Object.keys(this.query).length) {
6161 query = querystring.stringify(this.query);
6164 var search = this.search || (query && ('?' + query)) || '';
6166 if (protocol && protocol.substr(-1) !== ':') protocol += ':';
6168 // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
6169 // unless they had them to begin with.
6171 (!protocol || slashedProtocol[protocol]) && host !== false) {
6172 host = '//' + (host || '');
6173 if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
6178 if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
6179 if (search && search.charAt(0) !== '?') search = '?' + search;
6181 pathname = pathname.replace(/[?#]/g, function(match) {
6182 return encodeURIComponent(match);
6184 search = search.replace('#', '%23');
6186 return protocol + host + pathname + search + hash;
6189 function urlResolve(source, relative) {
6190 return urlParse(source, false, true).resolve(relative);
6193 Url.prototype.resolve = function(relative) {
6194 return this.resolveObject(urlParse(relative, false, true)).format();
6197 function urlResolveObject(source, relative) {
6198 if (!source) return relative;
6199 return urlParse(source, false, true).resolveObject(relative);
6202 Url.prototype.resolveObject = function(relative) {
6203 if (util.isString(relative)) {
6204 var rel = new Url();
6205 rel.parse(relative, false, true);
6209 var result = new Url();
6210 var tkeys = Object.keys(this);
6211 for (var tk = 0; tk < tkeys.length; tk++) {
6212 var tkey = tkeys[tk];
6213 result[tkey] = this[tkey];
6216 // hash is always overridden, no matter what.
6217 // even href="" will remove it.
6218 result.hash = relative.hash;
6220 // if the relative url is empty, then there's nothing left to do here.
6221 if (relative.href === '') {
6222 result.href = result.format();
6226 // hrefs like //foo/bar always cut to the protocol.
6227 if (relative.slashes && !relative.protocol) {
6228 // take everything except the protocol from relative
6229 var rkeys = Object.keys(relative);
6230 for (var rk = 0; rk < rkeys.length; rk++) {
6231 var rkey = rkeys[rk];
6232 if (rkey !== 'protocol')
6233 result[rkey] = relative[rkey];
6236 //urlParse appends trailing / to urls like http://www.example.com
6237 if (slashedProtocol[result.protocol] &&
6238 result.hostname && !result.pathname) {
6239 result.path = result.pathname = '/';
6242 result.href = result.format();
6246 if (relative.protocol && relative.protocol !== result.protocol) {
6247 // if it's a known url protocol, then changing
6248 // the protocol does weird things
6249 // first, if it's not file:, then we MUST have a host,
6250 // and if there was a path
6251 // to begin with, then we MUST have a path.
6252 // if it is file:, then the host is dropped,
6253 // because that's known to be hostless.
6254 // anything else is assumed to be absolute.
6255 if (!slashedProtocol[relative.protocol]) {
6256 var keys = Object.keys(relative);
6257 for (var v = 0; v < keys.length; v++) {
6259 result[k] = relative[k];
6261 result.href = result.format();
6265 result.protocol = relative.protocol;
6266 if (!relative.host && !hostlessProtocol[relative.protocol]) {
6267 var relPath = (relative.pathname || '').split('/');
6268 while (relPath.length && !(relative.host = relPath.shift()));
6269 if (!relative.host) relative.host = '';
6270 if (!relative.hostname) relative.hostname = '';
6271 if (relPath[0] !== '') relPath.unshift('');
6272 if (relPath.length < 2) relPath.unshift('');
6273 result.pathname = relPath.join('/');
6275 result.pathname = relative.pathname;
6277 result.search = relative.search;
6278 result.query = relative.query;
6279 result.host = relative.host || '';
6280 result.auth = relative.auth;
6281 result.hostname = relative.hostname || relative.host;
6282 result.port = relative.port;
6283 // to support http.request
6284 if (result.pathname || result.search) {
6285 var p = result.pathname || '';
6286 var s = result.search || '';
6287 result.path = p + s;
6289 result.slashes = result.slashes || relative.slashes;
6290 result.href = result.format();
6294 var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
6297 relative.pathname && relative.pathname.charAt(0) === '/'
6299 mustEndAbs = (isRelAbs || isSourceAbs ||
6300 (result.host && relative.pathname)),
6301 removeAllDots = mustEndAbs,
6302 srcPath = result.pathname && result.pathname.split('/') || [],
6303 relPath = relative.pathname && relative.pathname.split('/') || [],
6304 psychotic = result.protocol && !slashedProtocol[result.protocol];
6306 // if the url is a non-slashed url, then relative
6307 // links like ../.. should be able
6308 // to crawl up to the hostname, as well. This is strange.
6309 // result.protocol has already been set by now.
6310 // Later on, put the first path part into the host field.
6312 result.hostname = '';
6315 if (srcPath[0] === '') srcPath[0] = result.host;
6316 else srcPath.unshift(result.host);
6319 if (relative.protocol) {
6320 relative.hostname = null;
6321 relative.port = null;
6322 if (relative.host) {
6323 if (relPath[0] === '') relPath[0] = relative.host;
6324 else relPath.unshift(relative.host);
6326 relative.host = null;
6328 mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
6333 result.host = (relative.host || relative.host === '') ?
6334 relative.host : result.host;
6335 result.hostname = (relative.hostname || relative.hostname === '') ?
6336 relative.hostname : result.hostname;
6337 result.search = relative.search;
6338 result.query = relative.query;
6340 // fall through to the dot-handling below.
6341 } else if (relPath.length) {
6343 // throw away the existing file, and take the new path instead.
6344 if (!srcPath) srcPath = [];
6346 srcPath = srcPath.concat(relPath);
6347 result.search = relative.search;
6348 result.query = relative.query;
6349 } else if (!util.isNullOrUndefined(relative.search)) {
6350 // just pull out the search.
6351 // like href='?foo'.
6352 // Put this after the other two cases because it simplifies the booleans
6354 result.hostname = result.host = srcPath.shift();
6355 //occationaly the auth can get stuck only in host
6356 //this especially happens in cases like
6357 //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
6358 var authInHost = result.host && result.host.indexOf('@') > 0 ?
6359 result.host.split('@') : false;
6361 result.auth = authInHost.shift();
6362 result.host = result.hostname = authInHost.shift();
6365 result.search = relative.search;
6366 result.query = relative.query;
6367 //to support http.request
6368 if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
6369 result.path = (result.pathname ? result.pathname : '') +
6370 (result.search ? result.search : '');
6372 result.href = result.format();
6376 if (!srcPath.length) {
6377 // no path at all. easy.
6378 // we've already handled the other stuff above.
6379 result.pathname = null;
6380 //to support http.request
6381 if (result.search) {
6382 result.path = '/' + result.search;
6386 result.href = result.format();
6390 // if a url ENDs in . or .., then it must get a trailing slash.
6391 // however, if it ends in anything else non-slashy,
6392 // then it must NOT get a trailing slash.
6393 var last = srcPath.slice(-1)[0];
6394 var hasTrailingSlash = (
6395 (result.host || relative.host || srcPath.length > 1) &&
6396 (last === '.' || last === '..') || last === '');
6398 // strip single dots, resolve double dots to parent dir
6399 // if the path tries to go above the root, `up` ends up > 0
6401 for (var i = srcPath.length; i >= 0; i--) {
6404 srcPath.splice(i, 1);
6405 } else if (last === '..') {
6406 srcPath.splice(i, 1);
6409 srcPath.splice(i, 1);
6414 // if the path is allowed to go above the root, restore leading ..s
6415 if (!mustEndAbs && !removeAllDots) {
6417 srcPath.unshift('..');
6421 if (mustEndAbs && srcPath[0] !== '' &&
6422 (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
6423 srcPath.unshift('');
6426 if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
6430 var isAbsolute = srcPath[0] === '' ||
6431 (srcPath[0] && srcPath[0].charAt(0) === '/');
6433 // put the host back
6435 result.hostname = result.host = isAbsolute ? '' :
6436 srcPath.length ? srcPath.shift() : '';
6437 //occationaly the auth can get stuck only in host
6438 //this especially happens in cases like
6439 //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
6440 var authInHost = result.host && result.host.indexOf('@') > 0 ?
6441 result.host.split('@') : false;
6443 result.auth = authInHost.shift();
6444 result.host = result.hostname = authInHost.shift();
6448 mustEndAbs = mustEndAbs || (result.host && srcPath.length);
6450 if (mustEndAbs && !isAbsolute) {
6451 srcPath.unshift('');
6454 if (!srcPath.length) {
6455 result.pathname = null;
6458 result.pathname = srcPath.join('/');
6461 //to support request.http
6462 if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
6463 result.path = (result.pathname ? result.pathname : '') +
6464 (result.search ? result.search : '');
6466 result.auth = relative.auth || result.auth;
6467 result.slashes = result.slashes || relative.slashes;
6468 result.href = result.format();
6472 Url.prototype.parseHost = function() {
6473 var host = this.host;
6474 var port = portPattern.exec(host);
6478 this.port = port.substr(1);
6480 host = host.substr(0, host.length - port.length);
6482 if (host) this.hostname = host;
6485 },{"./util":44,"punycode":39,"querystring":42}],44:[function(require,module,exports){
6489 isString: function(arg) {
6490 return typeof(arg) === 'string';
6492 isObject: function(arg) {
6493 return typeof(arg) === 'object' && arg !== null;
6495 isNull: function(arg) {
6496 return arg === null;
6498 isNullOrUndefined: function(arg) {
6503 },{}],45:[function(require,module,exports){
6506 * slice() reference.
6509 var slice = Array.prototype.slice;
6515 module.exports = co['default'] = co.co = co;
6518 * Wrap the given generator `fn` into a
6519 * function that returns a promise.
6520 * This is a separate function so that
6521 * every `co()` call doesn't create a new,
6522 * unnecessary closure.
6524 * @param {GeneratorFunction} fn
6525 * @return {Function}
6529 co.wrap = function (fn) {
6530 createPromise.__generatorFunction__ = fn;
6531 return createPromise;
6532 function createPromise() {
6533 return co.call(this, fn.apply(this, arguments));
6538 * Execute the generator function or a generator
6539 * and return a promise.
6541 * @param {Function} fn
6548 var args = slice.call(arguments, 1)
6550 // we wrap everything in a promise to avoid promise chaining,
6551 // which leads to memory leak errors.
6552 // see https://github.com/tj/co/issues/180
6553 return new Promise(function(resolve, reject) {
6554 if (typeof gen === 'function') gen = gen.apply(ctx, args);
6555 if (!gen || typeof gen.next !== 'function') return resolve(gen);
6560 * @param {Mixed} res
6565 function onFulfilled(res) {
6568 ret = gen.next(res);
6576 * @param {Error} err
6581 function onRejected(err) {
6584 ret = gen.throw(err);
6592 * Get the next value in the generator,
6595 * @param {Object} ret
6600 function next(ret) {
6601 if (ret.done) return resolve(ret.value);
6602 var value = toPromise.call(ctx, ret.value);
6603 if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
6604 return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
6605 + 'but the following object was passed: "' + String(ret.value) + '"'));
6611 * Convert a `yield`ed value into a promise.
6613 * @param {Mixed} obj
6618 function toPromise(obj) {
6619 if (!obj) return obj;
6620 if (isPromise(obj)) return obj;
6621 if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
6622 if ('function' == typeof obj) return thunkToPromise.call(this, obj);
6623 if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
6624 if (isObject(obj)) return objectToPromise.call(this, obj);
6629 * Convert a thunk to a promise.
6636 function thunkToPromise(fn) {
6638 return new Promise(function (resolve, reject) {
6639 fn.call(ctx, function (err, res) {
6640 if (err) return reject(err);
6641 if (arguments.length > 2) res = slice.call(arguments, 1);
6648 * Convert an array of "yieldables" to a promise.
6649 * Uses `Promise.all()` internally.
6651 * @param {Array} obj
6656 function arrayToPromise(obj) {
6657 return Promise.all(obj.map(toPromise, this));
6661 * Convert an object of "yieldables" to a promise.
6662 * Uses `Promise.all()` internally.
6664 * @param {Object} obj
6669 function objectToPromise(obj){
6670 var results = new obj.constructor();
6671 var keys = Object.keys(obj);
6673 for (var i = 0; i < keys.length; i++) {
6675 var promise = toPromise.call(this, obj[key]);
6676 if (promise && isPromise(promise)) defer(promise, key);
6677 else results[key] = obj[key];
6679 return Promise.all(promises).then(function () {
6683 function defer(promise, key) {
6684 // predefine the key in the result
6685 results[key] = undefined;
6686 promises.push(promise.then(function (res) {
6693 * Check if `obj` is a promise.
6695 * @param {Object} obj
6700 function isPromise(obj) {
6701 return 'function' == typeof obj.then;
6705 * Check if `obj` is a generator.
6707 * @param {Mixed} obj
6712 function isGenerator(obj) {
6713 return 'function' == typeof obj.next && 'function' == typeof obj.throw;
6717 * Check if `obj` is a generator function.
6719 * @param {Mixed} obj
6723 function isGeneratorFunction(obj) {
6724 var constructor = obj.constructor;
6725 if (!constructor) return false;
6726 if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
6727 return isGenerator(constructor.prototype);
6731 * Check for plain object.
6733 * @param {Mixed} val
6738 function isObject(val) {
6739 return Object == val.constructor;
6742 },{}],46:[function(require,module,exports){
6743 var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');
6745 module.exports = function (obj, opts) {
6746 if (!opts) opts = {};
6747 if (typeof opts === 'function') opts = { cmp: opts };
6748 var space = opts.space || '';
6749 if (typeof space === 'number') space = Array(space+1).join(' ');
6750 var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
6751 var replacer = opts.replacer || function(key, value) { return value; };
6753 var cmp = opts.cmp && (function (f) {
6754 return function (node) {
6755 return function (a, b) {
6756 var aobj = { key: a, value: node[a] };
6757 var bobj = { key: b, value: node[b] };
6758 return f(aobj, bobj);
6764 return (function stringify (parent, key, node, level) {
6765 var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
6766 var colonSeparator = space ? ': ' : ':';
6768 if (node && node.toJSON && typeof node.toJSON === 'function') {
6769 node = node.toJSON();
6772 node = replacer.call(parent, key, node);
6774 if (node === undefined) {
6777 if (typeof node !== 'object' || node === null) {
6778 return json.stringify(node);
6780 if (isArray(node)) {
6782 for (var i = 0; i < node.length; i++) {
6783 var item = stringify(node, i, node[i], level+1) || json.stringify(null);
6784 out.push(indent + space + item);
6786 return '[' + out.join(',') + indent + ']';
6789 if (seen.indexOf(node) !== -1) {
6790 if (cycles) return json.stringify('__cycle__');
6791 throw new TypeError('Converting circular structure to JSON');
6793 else seen.push(node);
6795 var keys = objectKeys(node).sort(cmp && cmp(node));
6797 for (var i = 0; i < keys.length; i++) {
6799 var value = stringify(node, key, node[key], level+1);
6801 if(!value) continue;
6803 var keyValue = json.stringify(key)
6807 out.push(indent + space + keyValue);
6809 seen.splice(seen.indexOf(node), 1);
6810 return '{' + out.join(',') + indent + '}';
6812 })({ '': obj }, '', obj, 0);
6815 var isArray = Array.isArray || function (x) {
6816 return {}.toString.call(x) === '[object Array]';
6819 var objectKeys = Object.keys || function (obj) {
6820 var has = Object.prototype.hasOwnProperty || function () { return true };
6822 for (var key in obj) {
6823 if (has.call(obj, key)) keys.push(key);
6828 },{"jsonify":47}],47:[function(require,module,exports){
6829 exports.parse = require('./lib/parse');
6830 exports.stringify = require('./lib/stringify');
6832 },{"./lib/parse":48,"./lib/stringify":49}],48:[function(require,module,exports){
6833 var at, // The index of the current character
6834 ch, // The current character
6847 error = function (m) {
6848 // Call error when something is wrong.
6850 name: 'SyntaxError',
6857 next = function (c) {
6858 // If a c parameter is provided, verify that it matches the current character.
6859 if (c && c !== ch) {
6860 error("Expected '" + c + "' instead of '" + ch + "'");
6863 // Get the next character. When there are no more characters,
6864 // return the empty string.
6866 ch = text.charAt(at);
6871 number = function () {
6872 // Parse a number value.
6880 while (ch >= '0' && ch <= '9') {
6886 while (next() && ch >= '0' && ch <= '9') {
6890 if (ch === 'e' || ch === 'E') {
6893 if (ch === '-' || ch === '+') {
6897 while (ch >= '0' && ch <= '9') {
6903 if (!isFinite(number)) {
6904 error("Bad number");
6910 string = function () {
6911 // Parse a string value.
6917 // When parsing for string values, we must look for " and \ characters.
6923 } else if (ch === '\\') {
6927 for (i = 0; i < 4; i += 1) {
6928 hex = parseInt(next(), 16);
6929 if (!isFinite(hex)) {
6932 uffff = uffff * 16 + hex;
6934 string += String.fromCharCode(uffff);
6935 } else if (typeof escapee[ch] === 'string') {
6936 string += escapee[ch];
6945 error("Bad string");
6948 white = function () {
6952 while (ch && ch <= ' ') {
6957 word = function () {
6959 // true, false, or null.
6982 error("Unexpected '" + ch + "'");
6985 value, // Place holder for the value function.
6987 array = function () {
6989 // Parse an array value.
6998 return array; // empty array
7001 array.push(value());
7014 object = function () {
7016 // Parse an object value.
7026 return object; // empty object
7032 if (Object.hasOwnProperty.call(object, key)) {
7033 error('Duplicate key "' + key + '"');
7035 object[key] = value();
7045 error("Bad object");
7048 value = function () {
7050 // Parse a JSON value. It could be an object, an array, a string, a number,
7064 return ch >= '0' && ch <= '9' ? number() : word();
7068 // Return the json_parse function. It will have access to all of the above
7069 // functions and variables.
7071 module.exports = function (source, reviver) {
7080 error("Syntax error");
7083 // If there is a reviver function, we recursively walk the new structure,
7084 // passing each name/value pair to the reviver function for possible
7085 // transformation, starting with a temporary root object that holds the result
7086 // in an empty key. If there is not a reviver function, we simply return the
7089 return typeof reviver === 'function' ? (function walk(holder, key) {
7090 var k, v, value = holder[key];
7091 if (value && typeof value === 'object') {
7093 if (Object.prototype.hasOwnProperty.call(value, k)) {
7095 if (v !== undefined) {
7103 return reviver.call(holder, key, value);
7104 }({'': result}, '')) : result;
7107 },{}],49:[function(require,module,exports){
7108 var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
7109 escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
7112 meta = { // table of character substitutions
7123 function quote(string) {
7124 // If the string contains no control characters, no quote characters, and no
7125 // backslash characters, then we can safely slap some quotes around it.
7126 // Otherwise we must also replace the offending characters with safe escape
7129 escapable.lastIndex = 0;
7130 return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
7132 return typeof c === 'string' ? c :
7133 '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
7134 }) + '"' : '"' + string + '"';
7137 function str(key, holder) {
7138 // Produce a string from holder[key].
7139 var i, // The loop counter.
7140 k, // The member key.
7141 v, // The member value.
7145 value = holder[key];
7147 // If the value has a toJSON method, call it to obtain a replacement value.
7148 if (value && typeof value === 'object' &&
7149 typeof value.toJSON === 'function') {
7150 value = value.toJSON(key);
7153 // If we were called with a replacer function, then call the replacer to
7154 // obtain a replacement value.
7155 if (typeof rep === 'function') {
7156 value = rep.call(holder, key, value);
7159 // What happens next depends on the value's type.
7160 switch (typeof value) {
7162 return quote(value);
7165 // JSON numbers must be finite. Encode non-finite numbers as null.
7166 return isFinite(value) ? String(value) : 'null';
7170 // If the value is a boolean or null, convert it to a string. Note:
7171 // typeof null does not produce 'null'. The case is included here in
7172 // the remote chance that this gets fixed someday.
7173 return String(value);
7176 if (!value) return 'null';
7181 if (Object.prototype.toString.apply(value) === '[object Array]') {
7182 length = value.length;
7183 for (i = 0; i < length; i += 1) {
7184 partial[i] = str(i, value) || 'null';
7187 // Join all of the elements together, separated with commas, and
7188 // wrap them in brackets.
7189 v = partial.length === 0 ? '[]' : gap ?
7190 '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
7191 '[' + partial.join(',') + ']';
7196 // If the replacer is an array, use it to select the members to be
7198 if (rep && typeof rep === 'object') {
7199 length = rep.length;
7200 for (i = 0; i < length; i += 1) {
7202 if (typeof k === 'string') {
7205 partial.push(quote(k) + (gap ? ': ' : ':') + v);
7211 // Otherwise, iterate through all of the keys in the object.
7213 if (Object.prototype.hasOwnProperty.call(value, k)) {
7216 partial.push(quote(k) + (gap ? ': ' : ':') + v);
7222 // Join all of the member texts together, separated with commas,
7223 // and wrap them in braces.
7225 v = partial.length === 0 ? '{}' : gap ?
7226 '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
7227 '{' + partial.join(',') + '}';
7233 module.exports = function (value, replacer, space) {
7238 // If the space parameter is a number, make an indent string containing that
7240 if (typeof space === 'number') {
7241 for (i = 0; i < space; i += 1) {
7245 // If the space parameter is a string, it will be used as the indent string.
7246 else if (typeof space === 'string') {
7250 // If there is a replacer, it must be a function or an array.
7251 // Otherwise, throw an error.
7253 if (replacer && typeof replacer !== 'function'
7254 && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
7255 throw new Error('JSON.stringify');
7258 // Make a fake root object containing our value under the key of ''.
7259 // Return the result of stringifying the value.
7260 return str('', {'': value});
7263 },{}],"ajv":[function(require,module,exports){
7266 var compileSchema = require('./compile')
7267 , resolve = require('./compile/resolve')
7268 , Cache = require('./cache')
7269 , SchemaObject = require('./compile/schema_obj')
7270 , stableStringify = require('json-stable-stringify')
7271 , formats = require('./compile/formats')
7272 , rules = require('./compile/rules')
7273 , v5 = require('./v5')
7274 , util = require('./compile/util')
7275 , async = require('./async')
7276 , co = require('co');
7278 module.exports = Ajv;
7280 Ajv.prototype.compileAsync = async.compile;
7281 Ajv.prototype.addKeyword = require('./keyword');
7282 Ajv.ValidationError = require('./compile/validation_error');
7284 var META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema';
7285 var SCHEMA_URI_FORMAT = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i;
7286 function SCHEMA_URI_FORMAT_FUNC(str) {
7287 return SCHEMA_URI_FORMAT.test(str);
7290 var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ];
7293 * Creates validator instance.
7294 * Usage: `Ajv(opts)`
7295 * @param {Object} opts optional options
7296 * @return {Object} ajv instance
7298 function Ajv(opts) {
7299 if (!(this instanceof Ajv)) return new Ajv(opts);
7302 opts = this._opts = util.copy(opts) || {};
7305 this._formats = formats(opts.format);
7306 this._cache = opts.cache || new Cache;
7307 this._loadingSchemas = {};
7308 this.RULES = rules();
7310 // this is done on purpose, so that methods are bound to the instance
7311 // (without using bind) so that they can be used without the instance
7312 this.validate = validate;
7313 this.compile = compile;
7314 this.addSchema = addSchema;
7315 this.addMetaSchema = addMetaSchema;
7316 this.validateSchema = validateSchema;
7317 this.getSchema = getSchema;
7318 this.removeSchema = removeSchema;
7319 this.addFormat = addFormat;
7320 this.errorsText = errorsText;
7322 this._addSchema = _addSchema;
7323 this._compile = _compile;
7325 opts.loopRequired = opts.loopRequired || Infinity;
7326 if (opts.async || opts.transpile) async.setup(opts);
7327 if (opts.beautify === true) opts.beautify = { indent_size: 2 };
7328 if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
7329 this._metaOpts = getMetaSchemaOptions();
7331 if (opts.formats) addInitialFormats();
7332 addDraft4MetaSchema();
7333 if (opts.v5) v5.enable(this);
7334 if (typeof opts.meta == 'object') addMetaSchema(opts.meta);
7335 addInitialSchemas();
7339 * Validate data using schema
7340 * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
7341 * @param {String|Object} schemaKeyRef key, ref or schema object
7342 * @param {Any} data to be validated
7343 * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
7345 function validate(schemaKeyRef, data) {
7347 if (typeof schemaKeyRef == 'string') {
7348 v = getSchema(schemaKeyRef);
7349 if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
7351 var schemaObj = _addSchema(schemaKeyRef);
7352 v = schemaObj.validate || _compile(schemaObj);
7355 var valid = v(data);
7356 if (v.$async === true)
7357 return self._opts.async == '*' ? co(valid) : valid;
7358 self.errors = v.errors;
7364 * Create validating function for passed schema.
7365 * @param {Object} schema schema object
7366 * @return {Function} validating function
7368 function compile(schema) {
7369 var schemaObj = _addSchema(schema);
7370 return schemaObj.validate || _compile(schemaObj);
7375 * Adds schema to the instance.
7376 * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
7377 * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
7378 * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
7379 * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
7381 function addSchema(schema, key, _skipValidation, _meta) {
7382 if (Array.isArray(schema)){
7383 for (var i=0; i<schema.length; i++) addSchema(schema[i], undefined, _skipValidation, _meta);
7386 // can key/id have # inside?
7387 key = resolve.normalizeId(key || schema.id);
7389 var schemaObj = self._schemas[key] = _addSchema(schema, _skipValidation, true);
7390 schemaObj.meta = _meta;
7395 * Add schema that will be used to validate other schemas
7396 * options in META_IGNORE_OPTIONS are alway set to false
7397 * @param {Object} schema schema object
7398 * @param {String} key optional schema key
7399 * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
7401 function addMetaSchema(schema, key, skipValidation) {
7402 addSchema(schema, key, skipValidation, true);
7408 * @param {Object} schema schema to validate
7409 * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
7410 * @return {Boolean} true if schema is valid
7412 function validateSchema(schema, throwOrLogError) {
7413 var $schema = schema.$schema || self._opts.defaultMeta || defaultMeta();
7414 var currentUriFormat = self._formats.uri;
7415 self._formats.uri = typeof currentUriFormat == 'function'
7416 ? SCHEMA_URI_FORMAT_FUNC
7417 : SCHEMA_URI_FORMAT;
7418 var valid = validate($schema, schema);
7419 self._formats.uri = currentUriFormat;
7420 if (!valid && throwOrLogError) {
7421 var message = 'schema is invalid:' + errorsText();
7422 if (self._opts.validateSchema == 'log') console.error(message);
7423 else throw new Error(message);
7429 function defaultMeta() {
7430 var meta = self._opts.meta;
7431 self._opts.defaultMeta = typeof meta == 'object'
7436 return self._opts.defaultMeta;
7441 * Get compiled schema from the instance by `key` or `ref`.
7442 * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
7443 * @return {Function} schema validating function (with property `schema`).
7445 function getSchema(keyRef) {
7446 var schemaObj = _getSchemaObj(keyRef);
7447 switch (typeof schemaObj) {
7448 case 'object': return schemaObj.validate || _compile(schemaObj);
7449 case 'string': return getSchema(schemaObj);
7454 function _getSchemaObj(keyRef) {
7455 keyRef = resolve.normalizeId(keyRef);
7456 return self._schemas[keyRef] || self._refs[keyRef];
7461 * Remove cached schema(s).
7462 * If no parameter is passed all schemas but meta-schemas are removed.
7463 * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
7464 * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
7465 * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
7467 function removeSchema(schemaKeyRef) {
7468 if (schemaKeyRef instanceof RegExp) {
7469 _removeAllSchemas(self._schemas, schemaKeyRef);
7470 _removeAllSchemas(self._refs, schemaKeyRef);
7473 switch (typeof schemaKeyRef) {
7475 _removeAllSchemas(self._schemas);
7476 _removeAllSchemas(self._refs);
7477 self._cache.clear();
7480 var schemaObj = _getSchemaObj(schemaKeyRef);
7481 if (schemaObj) self._cache.del(schemaObj.jsonStr);
7482 delete self._schemas[schemaKeyRef];
7483 delete self._refs[schemaKeyRef];
7486 var jsonStr = stableStringify(schemaKeyRef);
7487 self._cache.del(jsonStr);
7488 var id = schemaKeyRef.id;
7490 id = resolve.normalizeId(id);
7491 delete self._schemas[id];
7492 delete self._refs[id];
7498 function _removeAllSchemas(schemas, regex) {
7499 for (var keyRef in schemas) {
7500 var schemaObj = schemas[keyRef];
7501 if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
7502 self._cache.del(schemaObj.jsonStr);
7503 delete schemas[keyRef];
7509 function _addSchema(schema, skipValidation, shouldAddSchema) {
7510 if (typeof schema != 'object') throw new Error('schema should be object');
7511 var jsonStr = stableStringify(schema);
7512 var cached = self._cache.get(jsonStr);
7513 if (cached) return cached;
7515 shouldAddSchema = shouldAddSchema || self._opts.addUsedSchema !== false;
7517 var id = resolve.normalizeId(schema.id);
7518 if (id && shouldAddSchema) checkUnique(id);
7520 if (self._opts.validateSchema !== false && !skipValidation)
7521 validateSchema(schema, true);
7523 var localRefs = resolve.ids.call(self, schema);
7525 var schemaObj = new SchemaObject({
7528 localRefs: localRefs,
7532 if (id[0] != '#' && shouldAddSchema) self._refs[id] = schemaObj;
7533 self._cache.put(jsonStr, schemaObj);
7539 function _compile(schemaObj, root) {
7540 if (schemaObj.compiling) {
7541 schemaObj.validate = callValidate;
7542 callValidate.schema = schemaObj.schema;
7543 callValidate.errors = null;
7544 callValidate.root = root ? root : callValidate;
7545 if (schemaObj.schema.$async === true)
7546 callValidate.$async = true;
7547 return callValidate;
7549 schemaObj.compiling = true;
7552 if (schemaObj.meta) {
7553 currentOpts = self._opts;
7554 self._opts = self._metaOpts;
7558 try { v = compileSchema.call(self, schemaObj.schema, root, schemaObj.localRefs); }
7560 schemaObj.compiling = false;
7561 if (schemaObj.meta) self._opts = currentOpts;
7564 schemaObj.validate = v;
7565 schemaObj.refs = v.refs;
7566 schemaObj.refVal = v.refVal;
7567 schemaObj.root = v.root;
7571 function callValidate() {
7572 var _validate = schemaObj.validate;
7573 var result = _validate.apply(null, arguments);
7574 callValidate.errors = _validate.errors;
7581 * Convert array of error message objects to string
7582 * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
7583 * @param {Object} options optional options with properties `separator` and `dataVar`.
7584 * @return {String} human readable string with all errors descriptions
7586 function errorsText(errors, options) {
7587 errors = errors || self.errors;
7588 if (!errors) return 'No errors';
7589 options = options || {};
7590 var separator = options.separator === undefined ? ', ' : options.separator;
7591 var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
7594 for (var i=0; i<errors.length; i++) {
7596 if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
7598 return text.slice(0, -separator.length);
7604 * @param {String} name format name
7605 * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
7607 function addFormat(name, format) {
7608 if (typeof format == 'string') format = new RegExp(format);
7609 self._formats[name] = format;
7613 function addDraft4MetaSchema() {
7614 if (self._opts.meta !== false) {
7615 var metaSchema = require('./refs/json-schema-draft-04.json');
7616 addMetaSchema(metaSchema, META_SCHEMA_ID, true);
7617 self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
7622 function addInitialSchemas() {
7623 var optsSchemas = self._opts.schemas;
7624 if (!optsSchemas) return;
7625 if (Array.isArray(optsSchemas)) addSchema(optsSchemas);
7626 else for (var key in optsSchemas) addSchema(optsSchemas[key], key);
7630 function addInitialFormats() {
7631 for (var name in self._opts.formats) {
7632 var format = self._opts.formats[name];
7633 addFormat(name, format);
7638 function checkUnique(id) {
7639 if (self._schemas[id] || self._refs[id])
7640 throw new Error('schema with key or id "' + id + '" already exists');
7644 function getMetaSchemaOptions() {
7645 var metaOpts = util.copy(self._opts);
7646 for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
7647 delete metaOpts[META_IGNORE_OPTIONS[i]];
7652 },{"./async":1,"./cache":2,"./compile":6,"./compile/formats":5,"./compile/resolve":7,"./compile/rules":8,"./compile/schema_obj":9,"./compile/util":10,"./compile/validation_error":11,"./keyword":35,"./refs/json-schema-draft-04.json":36,"./v5":38,"co":45,"json-stable-stringify":46}]},{},[])("ajv")