Bug 1586807 - Make pseudoclass locking work with Fission. r=pbro
[gecko.git] / testing / modules / ajv-4.1.1.js
blob9702c410c0f3c650c164c62d152237f5f7f4d24a
1 "use strict";
2 const global = this;
4 var EXPORTED_SYMBOLS = ["Ajv"];
6 /*
7  * ajv 4.1.1: Another JSON Schema Validator
8  *
9  * https://github.com/epoberezkin/ajv
10  *
11  * The MIT License (MIT)
12  *
13  * Copyright (c) 2015 Evgeny Poberezkin
14  *
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
31  * SOFTWARE.
32  */
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){
39 'use strict';
41 module.exports = {
42   setup: setupAsync,
43   compile: compileAsync
47 var util = require('./compile/util');
49 var ASYNC = {
50   '*': checkGenerators,
51   'co*': checkGenerators,
52   'es7': checkAsyncFunction
55 var TRANSPILE = {
56   'nodent': getNodent,
57   'regenerator': getRegenerator
60 var MODES = [
61   { async: 'co*' },
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
74     , check;
76   switch (typeof transpile) {
77     case 'string':
78       var get = TRANSPILE[transpile];
79       if (!get) throw new Error('bad transpiler: ' + transpile);
80       return (opts._transpileFunc = get(opts, required));
81     case 'undefined':
82     case 'boolean':
83       if (typeof async == 'string') {
84         check = ASYNC[async];
85         if (!check) throw new Error('bad async mode: ' + async);
86         return (opts.transpile = check(opts, required));
87       }
89       for (var i=0; i<MODES.length; i++) {
90         var _opts = MODES[i];
91         if (setupAsync(_opts, false)) {
92           util.copy(_opts, opts);
93           return opts.transpile;
94         }
95       }
96       /* istanbul ignore next */
97       throw new Error('generators, nodent and regenerator are not available');
98     case 'function':
99       return (opts._transpileFunc = opts.transpile);
100     default:
101       throw new Error('bad transpiler: ' + transpile);
102   }
106 function checkGenerators(opts, required) {
107   /* jshint evil: true */
108   try {
109     eval('(function*(){})()');
110     return true;
111   } catch(e) {
112     /* istanbul ignore next */
113     if (required) throw new Error('generators not supported');
114   }
118 function checkAsyncFunction(opts, required) {
119   /* jshint evil: true */
120   try {
121     eval('(async function(){})()');
122     /* istanbul ignore next */
123     return true;
124   } catch(e) {
125     if (required) throw new Error('es7 async functions not supported');
126   }
130 function getRegenerator(opts, required) {
131   try {
132     if (!regenerator) {
133       regenerator = require('' + 'regenerator');
134       regenerator.runtime();
135     }
136     if (!opts.async || opts.async === true)
137       opts.async = 'es7';
138     return regeneratorTranspile;
139   } catch(e) {
140     /* istanbul ignore next */
141     if (required) throw new Error('regenerator not available');
142   }
146 function regeneratorTranspile(code) {
147   return regenerator.compile(code).code;
151 function getNodent(opts, required) {
152   /* jshint evil: true */
153   try {
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');
157       opts.async = 'es7';
158     }
159     return nodentTranspile;
160   } catch(e) {
161     /* istanbul ignore next */
162     if (required) throw new Error('nodent not available');
163   }
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.
175  * @this  Ajv
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.
178  */
179 function compileAsync(schema, callback) {
180   /* eslint no-shadow: 0 */
181   /* jshint validthis: true */
182   var schemaObj;
183   var self = this;
184   try {
185     schemaObj = this._addSchema(schema);
186   } catch(e) {
187     setTimeout(function() { callback(e); });
188     return;
189   }
190   if (schemaObj.validate) {
191     setTimeout(function() { callback(null, schemaObj.validate); });
192   } else {
193     if (typeof this._opts.loadSchema != 'function')
194       throw new Error('options.loadSchema should be a function');
195     _compileAsync(schema, callback, true);
196   }
199   function _compileAsync(schema, callback, firstCall) {
200     var validate;
201     try { validate = self.compile(schema); }
202     catch(e) {
203       if (e.missingSchema) loadMissingSchema(e);
204       else deferCallback(e);
205       return;
206     }
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];
214       if (_callbacks) {
215         if (typeof _callbacks == 'function')
216           self._loadingSchemas[ref] = [_callbacks, schemaLoaded];
217         else
218           _callbacks[_callbacks.length] = schemaLoaded;
219       } else {
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);
226           } else {
227             for (var i=0; i<_callbacks.length; i++)
228               _callbacks[i](err, sch);
229           }
230         });
231       }
233       function schemaLoaded(err, sch) {
234         if (err) return callback(err);
235         if (!(self._refs[ref] || self._schemas[ref])) {
236           try {
237             self.addSchema(sch, ref);
238           } catch(e) {
239             callback(e);
240             return;
241           }
242         }
243         _compileAsync(schema, callback);
244       }
245     }
247     function deferCallback(err, validate) {
248       if (firstCall) setTimeout(function() { callback(err, validate); });
249       else return callback(err, validate);
250     }
251   }
254 },{"./compile/util":10}],2:[function(require,module,exports){
255 'use strict';
258 var Cache = module.exports = function Cache() {
259   this._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() {
279   this._cache = {};
282 },{}],3:[function(require,module,exports){
283 'use strict';
285 //all requires must be explicit because browserify won't work with dynamic requires
286 module.exports = {
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){
313 'use strict';
315 module.exports = function equal(a, b) {
316   if (a === b) return true;
318   var arrA = Array.isArray(a)
319     , arrB = Array.isArray(b)
320     , i;
322   if (arrA && arrB) {
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;
326     return true;
327   }
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;
342     return true;
343   }
345   return false;
348 },{}],5:[function(require,module,exports){
349 'use strict';
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]
372     };
373   }
374   return formatDefs;
378 formats.fast = {
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,
390   hostname: HOSTNAME,
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,
395   regex: regex,
396   // uuid: http://tools.ietf.org/html/rfc4122
397   uuid: UUID,
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
406 formats.full = {
407   date: date,
408   time: time,
409   'date-time': date_time,
410   uri: uri,
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,
412   hostname: hostname,
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,
415   regex: regex,
416   uuid: UUID,
417   'json-pointer': JSON_POINTER,
418   'relative-json-pointer': RELATIVE_JSON_POINTER
422 formats.compare = {
423   date: compareDate,
424   time: compareTime,
425   'date-time': compareDateTime
429 function date(str) {
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 = /\/|\:/;
467 function uri(str) {
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) {
474   try {
475     new RegExp(str);
476     return true;
477   } catch(e) {
478     return false;
479   }
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;
493   t1 = t1.match(TIME);
494   t2 = t2.match(TIME);
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){
514 'use strict';
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
530  * @this   Ajv
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
536  */
537 function compile(schema, root, localRefs, baseId) {
538   /* jshint validthis: true, evil: true */
539   /* eslint no-shadow: 0 */
540   var self = this
541     , opts = this._opts
542     , refVal = [ undefined ]
543     , refs = {}
544     , patterns = []
545     , patternsHash = {}
546     , defaults = []
547     , defaultsHash = {}
548     , customRules = [];
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({
567       isTop: true,
568       schema: _schema,
569       isRoot: isRoot,
570       baseId: baseId,
571       root: _root,
572       schemaPath: '',
573       errSchemaPath: '#',
574       errorPath: '""',
575       RULES: RULES,
576       validate: validateGenerator,
577       util: util,
578       resolve: resolve,
579       resolveRef: resolveRef,
580       usePattern: usePattern,
581       useDefault: useDefault,
582       useCustomRule: useCustomRule,
583       opts: opts,
584       formats: formats,
585       self: self
586     });
588     sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
589                    + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
590                    + sourceCode;
592     if (opts.beautify) {
593       /* istanbul ignore else */
594       if (beautify) sourceCode = beautify(sourceCode, opts.beautify);
595       else console.error('"npm install js-beautify" to use beautify option');
596     }
597     // console.log('\n\n\n *** \n', sourceCode);
598     var validate, validateCode
599       , transpile = opts._transpileFunc;
600     try {
601       validateCode = $async && transpile
602                       ? transpile(sourceCode)
603                       : sourceCode;
604       eval(validateCode);
605       refVal[0] = validate;
606     } catch(e) {
607       console.error('Error compiling schema, function code:', validateCode);
608       throw e;
609     }
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;
619     return validate;
620   }
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);
630     }
631     if (!isRoot) {
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);
637       }
638     }
640     refCode = addLocalRef(ref);
641     var v = resolve.call(self, localCompile, root, ref);
642     if (!v) {
643       var localSchema = localRefs && localRefs[ref];
644       if (localSchema) {
645         v = resolve.inlineRef(localSchema, opts.inlineRefs)
646             ? localSchema
647             : compile.call(self, localSchema, root, localRefs, baseId);
648       }
649     }
651     if (v) {
652       replaceLocalRef(ref, v);
653       return resolvedRef(v, refCode);
654     }
655   }
657   function addLocalRef(ref, v) {
658     var refId = refVal.length;
659     refVal[refId] = v;
660     refs[ref] = refId;
661     return 'refVal' + refId;
662   }
664   function replaceLocalRef(ref, v) {
665     var refId = refs[ref];
666     refVal[refId] = v;
667   }
669   function resolvedRef(refVal, code) {
670     return typeof refVal == 'object'
671             ? { code: code, schema: refVal, inline: true }
672             : { code: code, $async: refVal && refVal.$async };
673   }
675   function usePattern(regexStr) {
676     var index = patternsHash[regexStr];
677     if (index === undefined) {
678       index = patternsHash[regexStr] = patterns.length;
679       patterns[index] = regexStr;
680     }
681     return 'pattern' + index;
682   }
684   function useDefault(value) {
685     switch (typeof value) {
686       case 'boolean':
687       case 'number':
688         return '' + value;
689       case 'string':
690         return util.toQuotedString(value);
691       case 'object':
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;
698         }
699         return 'default' + index;
700     }
701   }
703   function useCustomRule(rule, schema, parentSchema, it) {
704     var compile = rule.definition.compile
705       , inline = rule.definition.inline
706       , macro = rule.definition.macro;
708     var validate;
709     if (compile) {
710       validate = compile.call(self, schema, parentSchema);
711     } else if (macro) {
712       validate = macro.call(self, schema, parentSchema);
713       if (opts.validateSchema !== false) self.validateSchema(validate, true);
714     } else if (inline) {
715       validate = inline.call(self, it, rule.keyword, schema, parentSchema);
716     } else {
717       validate = rule.definition.validate;
718     }
720     var index = customRules.length;
721     customRules[index] = validate;
723     return {
724       code: 'customRule' + index,
725       validate: validate
726     };
727   }
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 '';
753   var code = '';
754   for (var i=0; i<arr.length; i++)
755     code += statement(i, arr);
756   return code;
760 /*eslint-disable no-unused-vars */
763  * Functions below are used inside compiled validations function
764  */
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){
778 'use strict';
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)]
795  * @this   Ajv
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
800  */
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);
807   }
809   refVal = refVal || this._schemas[ref];
810   if (refVal instanceof SchemaObject) {
811     return inlineRef(refVal.schema, this._opts.inlineRefs)
812             ? refVal.schema
813             : refVal.validate || this._compile(refVal);
814   }
816   var res = _resolve.call(this, root, ref);
817   var schema, v, baseId;
818   if (res) {
819     schema = res.schema;
820     root = res.root;
821     baseId = res.baseId;
822   }
824   if (schema instanceof SchemaObject) {
825     v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
826   } else if (schema) {
827     v = inlineRef(schema, this._opts.inlineRefs)
828         ? schema
829         : compile.call(this, schema, root, undefined, baseId);
830   }
832   return v;
836 /* @this Ajv */
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);
849       root = refVal;
850     } else {
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 };
856         root = refVal;
857       }
858     }
859     if (!root.schema) return;
860     baseId = getFullPath(root.schema.id);
861   }
862   return getJsonPointer.call(this, p, baseId, root.schema, root);
866 /* @this Ajv */
867 function resolveRecursive(root, ref, parsedRef) {
868   /* jshint validthis: true */
869   var res = _resolve.call(this, root, ref);
870   if (res) {
871     var schema = res.schema;
872     var baseId = res.baseId;
873     root = res.root;
874     if (schema.id) baseId = resolveUrl(baseId, schema.id);
875     return getJsonPointer.call(this, parsedRef, baseId, schema, root);
876   }
880 var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
881 /* @this Ajv */
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++) {
889     var part = parts[i];
890     if (part) {
891       part = util.unescapeFragment(part);
892       schema = schema[part];
893       if (!schema) break;
894       if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id);
895       if (schema.$ref) {
896         var $ref = resolveUrl(baseId, schema.$ref);
897         var res = _resolve.call(this, root, $ref);
898         if (res) {
899           schema = res.schema;
900           root = res.root;
901           baseId = res.baseId;
902         }
903       }
904     }
905   }
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',
918   'required', 'enum'
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) {
928   var item;
929   if (Array.isArray(schema)) {
930     for (var i=0; i<schema.length; i++) {
931       item = schema[i];
932       if (typeof item == 'object' && !checkNoRef(item)) return false;
933     }
934   } else {
935     for (var key in schema) {
936       if (key == '$ref') return false;
937       item = schema[key];
938       if (typeof item == 'object' && !checkNoRef(item)) return false;
939     }
940   }
941   return true;
945 function countKeys(schema) {
946   var count = 0, item;
947   if (Array.isArray(schema)) {
948     for (var i=0; i<schema.length; i++) {
949       item = schema[i];
950       if (typeof item == 'object') count += countKeys(item);
951       if (count == Infinity) return Infinity;
952     }
953   } else {
954     for (var key in schema) {
955       if (key == '$ref') return Infinity;
956       if (SIMPLE_INLINED[key]) {
957         count++;
958       } else {
959         item = schema[key];
960         if (typeof item == 'object') count += countKeys(item) + 1;
961         if (count == Infinity) return Infinity;
962       }
963     }
964   }
965   return count;
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);
993 /* @this Ajv */
994 function resolveIds(schema) {
995   /* eslint no-shadow: 0 */
996   /* jshint validthis: true */
997   var id = normalizeId(schema.id);
998   var localRefs = {};
999   _resolveIds.call(this, schema, getFullPath(id, false), id);
1000   return localRefs;
1002   /* @this Ajv */
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)
1012                           : 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)) {
1021           if (id[0] == '#') {
1022             if (localRefs[id] && !equal(schema, localRefs[id]))
1023               throw new Error('id "' + id + '" resolves to more than one schema');
1024             localRefs[id] = schema;
1025           } else {
1026             this._refs[id] = fullPath;
1027           }
1028         }
1029       }
1030       for (var key in schema)
1031         _resolveIds.call(this, schema[key], fullPath+'/'+util.escapeFragment(key), baseId);
1032     }
1033   }
1036 },{"./equal":4,"./schema_obj":9,"./util":10,"url":43}],8:[function(require,module,exports){
1037 'use strict';
1039 var ruleModules = require('./_rules')
1040   , util = require('./util');
1042 module.exports = function rules() {
1043   var RULES = [
1044     { type: 'number',
1045       rules: [ 'maximum', 'minimum', 'multipleOf'] },
1046     { type: 'string',
1047       rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
1048     { type: 'array',
1049       rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
1050     { type: 'object',
1051       rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
1052     { rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
1053   ];
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);
1062       return {
1063         keyword: keyword,
1064         code: ruleModules[keyword]
1065       };
1066     });
1067   });
1069   RULES.keywords = util.toHash(RULES.all.concat(RULES.keywords));
1070   RULES.all = util.toHash(RULES.all);
1071   RULES.types = util.toHash(RULES.types);
1073   return RULES;
1076 },{"./_rules":3,"./util":10}],9:[function(require,module,exports){
1077 'use strict';
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){
1088 'use strict';
1091 module.exports = {
1092   copy: copy,
1093   checkDataType: checkDataType,
1094   checkDataTypes: checkDataTypes,
1095   coerceToTypes: coerceToTypes,
1096   toHash: toHash,
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,
1108   getPath: getPath,
1109   getData: getData,
1110   unescapeFragment: unescapeFragment,
1111   escapeFragment: escapeFragment,
1112   escapeJsonPointer: escapeJsonPointer
1116 function copy(o, to) {
1117   to = to || {};
1118   for (var key in o) to[key] = o[key];
1119   return to;
1123 function checkDataType(dataType, data, negate) {
1124   var EQUAL = negate ? ' !== ' : ' === '
1125     , AND = negate ? ' || ' : ' && '
1126     , OK = negate ? '!' : ''
1127     , NOT = negate ? '' : '!';
1128   switch (dataType) {
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 + '"';
1138   }
1142 function checkDataTypes(dataTypes, data) {
1143   switch (dataTypes.length) {
1144     case 1: return checkDataType(dataTypes[0], data, true);
1145     default:
1146       var code = '';
1147       var types = toHash(dataTypes);
1148       if (types.array && types.object) {
1149         code = types.null ? '(': '(!' + data + ' || ';
1150         code += 'typeof ' + data + ' !== "object")';
1151         delete types.null;
1152         delete types.array;
1153         delete types.object;
1154       }
1155       if (types.number) delete types.integer;
1156       for (var t in types)
1157         code += (code ? ' && ' : '' ) + checkDataType(t, data, true);
1159       return code;
1160   }
1164 var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
1165 function coerceToTypes(dataTypes) {
1166   if (Array.isArray(dataTypes)) {
1167     var types = [];
1168     for (var i=0; i<dataTypes.length; i++) {
1169       var t = dataTypes[i];
1170       if (COERCE_TO_TYPES[t]) types[types.length] = t;
1171     }
1172     if (types.length) return types;
1173   } else if (COERCE_TO_TYPES[dataTypes]) {
1174     return [dataTypes];
1175   }
1179 function toHash(arr) {
1180   var hash = {};
1181   for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
1182   return hash;
1186 var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
1187 var SINGLE_QUOTE = /'|\\/g;
1188 function getProperty(key) {
1189   return typeof key == 'number'
1190           ? '[' + key + ']'
1191           : IDENTIFIER.test(key)
1192             ? '.' + 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) {
1205   var length = 0
1206     , len = str.length
1207     , pos = 0
1208     , value;
1209   while (pos < len) {
1210     length++;
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
1216     }
1217   }
1218   return length;
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;
1257   return async
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];
1300   }
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;
1306   var expr = data;
1307   var segments = jsonPointer.split('/');
1308   for (var i=0; i<segments.length; i++) {
1309     var segment = segments[i];
1310     if (segment) {
1311       data += getProperty(unescapeJsonPointer(segment));
1312       expr += ' && ' + data;
1313     }
1314   }
1315   return expr;
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){
1345 'use strict';
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){
1361 'use strict';
1362 module.exports = function generate__formatLimit(it, $keyword) {
1363   var out = ' ';
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;
1370   var $errorKeyword;
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; ';
1376     return out;
1377   }
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;';
1386   } else {
1387     var $format = it.formats[$schemaFormat];
1388     if (!($format && $format.compare)) {
1389       out += '  ' + ($valid) + ' = true; ';
1390       return out;
1391     }
1392     var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare';
1393   }
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;
1402   if ($isData) {
1403     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1404     $schemaValue = 'schema' + $lvl;
1405   }
1406   if ($isDataExcl) {
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\' ';
1422       }
1423       if (it.opts.verbose) {
1424         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1425       }
1426       out += ' } ';
1427     } else {
1428       out += ' {} ';
1429     }
1430     var __err = out;
1431     out = $$outStack.pop();
1432     if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1433       if (it.async) {
1434         out += ' throw new ValidationError([' + (__err) + ']); ';
1435       } else {
1436         out += ' validate.errors = [' + (__err) + ']; return false; ';
1437       }
1438     } else {
1439       out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1440     }
1441     out += ' }  ';
1442     if ($breakOnError) {
1443       $closingBraces += '}';
1444       out += ' else { ';
1445     }
1446     if ($isData) {
1447       out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
1448       $closingBraces += '}';
1449     }
1450     if ($isDataFormat) {
1451       out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
1452       $closingBraces += '}';
1453     }
1454     out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ',  ';
1455     if ($isData) {
1456       out += '' + ($schemaValue);
1457     } else {
1458       out += '' + (it.util.toQuotedString($schema));
1459     }
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) + '=\';';
1461   } else {
1462     var $exclusive = $schemaExcl === true,
1463       $opStr = $op;
1464     if (!$exclusive) $opStr += '=';
1465     var $opExpr = '\'' + $opStr + '\'';
1466     if ($isData) {
1467       out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
1468       $closingBraces += '}';
1469     }
1470     if ($isDataFormat) {
1471       out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
1472       $closingBraces += '}';
1473     }
1474     out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ',  ';
1475     if ($isData) {
1476       out += '' + ($schemaValue);
1477     } else {
1478       out += '' + (it.util.toQuotedString($schema));
1479     }
1480     out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; if (' + ($valid) + ' === undefined) ' + ($valid) + ' = ' + ($result) + ' ' + ($op);
1481     if (!$exclusive) {
1482       out += '=';
1483     }
1484     out += ' 0;';
1485   }
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:  ';
1493     if ($isData) {
1494       out += '' + ($schemaValue);
1495     } else {
1496       out += '' + (it.util.toQuotedString($schema));
1497     }
1498     out += ' , exclusive: ' + ($exclusive) + ' } ';
1499     if (it.opts.messages !== false) {
1500       out += ' , message: \'should be ' + ($opStr) + ' "';
1501       if ($isData) {
1502         out += '\' + ' + ($schemaValue) + ' + \'';
1503       } else {
1504         out += '' + (it.util.escapeQuotes($schema));
1505       }
1506       out += '"\' ';
1507     }
1508     if (it.opts.verbose) {
1509       out += ' , schema:  ';
1510       if ($isData) {
1511         out += 'validate.schema' + ($schemaPath);
1512       } else {
1513         out += '' + (it.util.toQuotedString($schema));
1514       }
1515       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1516     }
1517     out += ' } ';
1518   } else {
1519     out += ' {} ';
1520   }
1521   var __err = out;
1522   out = $$outStack.pop();
1523   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1524     if (it.async) {
1525       out += ' throw new ValidationError([' + (__err) + ']); ';
1526     } else {
1527       out += ' validate.errors = [' + (__err) + ']; return false; ';
1528     }
1529   } else {
1530     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1531   }
1532   out += '}';
1533   return out;
1536 },{}],13:[function(require,module,exports){
1537 'use strict';
1538 module.exports = function generate__limit(it, $keyword) {
1539   var out = ' ';
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;
1546   var $errorKeyword;
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;
1550   if ($isData) {
1551     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1552     $schemaValue = 'schema' + $lvl;
1553   }
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 ? '>' : '<';
1560   if ($isDataExcl) {
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\' ';
1576       }
1577       if (it.opts.verbose) {
1578         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1579       }
1580       out += ' } ';
1581     } else {
1582       out += ' {} ';
1583     }
1584     var __err = out;
1585     out = $$outStack.pop();
1586     if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1587       if (it.async) {
1588         out += ' throw new ValidationError([' + (__err) + ']); ';
1589       } else {
1590         out += ' validate.errors = [' + (__err) + ']; return false; ';
1591       }
1592     } else {
1593       out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1594     }
1595     out += ' } else if( ';
1596     if ($isData) {
1597       out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1598     }
1599     out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ') || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
1600   } else {
1601     var $exclusive = $schemaExcl === true,
1602       $opStr = $op;
1603     if (!$exclusive) $opStr += '=';
1604     var $opExpr = '\'' + $opStr + '\'';
1605     out += ' if ( ';
1606     if ($isData) {
1607       out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1608     }
1609     out += ' ' + ($data) + ' ' + ($notOp);
1610     if ($exclusive) {
1611       out += '=';
1612     }
1613     out += ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') {';
1614   }
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) + ' ';
1623       if ($isData) {
1624         out += '\' + ' + ($schemaValue);
1625       } else {
1626         out += '' + ($schema) + '\'';
1627       }
1628     }
1629     if (it.opts.verbose) {
1630       out += ' , schema:  ';
1631       if ($isData) {
1632         out += 'validate.schema' + ($schemaPath);
1633       } else {
1634         out += '' + ($schema);
1635       }
1636       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1637     }
1638     out += ' } ';
1639   } else {
1640     out += ' {} ';
1641   }
1642   var __err = out;
1643   out = $$outStack.pop();
1644   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1645     if (it.async) {
1646       out += ' throw new ValidationError([' + (__err) + ']); ';
1647     } else {
1648       out += ' validate.errors = [' + (__err) + ']; return false; ';
1649     }
1650   } else {
1651     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1652   }
1653   out += ' } ';
1654   if ($breakOnError) {
1655     out += ' else { ';
1656   }
1657   return out;
1660 },{}],14:[function(require,module,exports){
1661 'use strict';
1662 module.exports = function generate__limitItems(it, $keyword) {
1663   var out = ' ';
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;
1670   var $errorKeyword;
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;
1674   if ($isData) {
1675     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1676     $schemaValue = 'schema' + $lvl;
1677   }
1678   var $op = $keyword == 'maxItems' ? '>' : '<';
1679   out += 'if ( ';
1680   if ($isData) {
1681     out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1682   }
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') {
1693         out += 'more';
1694       } else {
1695         out += 'less';
1696       }
1697       out += ' than ';
1698       if ($isData) {
1699         out += '\' + ' + ($schemaValue) + ' + \'';
1700       } else {
1701         out += '' + ($schema);
1702       }
1703       out += ' items\' ';
1704     }
1705     if (it.opts.verbose) {
1706       out += ' , schema:  ';
1707       if ($isData) {
1708         out += 'validate.schema' + ($schemaPath);
1709       } else {
1710         out += '' + ($schema);
1711       }
1712       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1713     }
1714     out += ' } ';
1715   } else {
1716     out += ' {} ';
1717   }
1718   var __err = out;
1719   out = $$outStack.pop();
1720   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1721     if (it.async) {
1722       out += ' throw new ValidationError([' + (__err) + ']); ';
1723     } else {
1724       out += ' validate.errors = [' + (__err) + ']; return false; ';
1725     }
1726   } else {
1727     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1728   }
1729   out += '} ';
1730   if ($breakOnError) {
1731     out += ' else { ';
1732   }
1733   return out;
1736 },{}],15:[function(require,module,exports){
1737 'use strict';
1738 module.exports = function generate__limitLength(it, $keyword) {
1739   var out = ' ';
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;
1746   var $errorKeyword;
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;
1750   if ($isData) {
1751     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1752     $schemaValue = 'schema' + $lvl;
1753   }
1754   var $op = $keyword == 'maxLength' ? '>' : '<';
1755   out += 'if ( ';
1756   if ($isData) {
1757     out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1758   }
1759   if (it.opts.unicode === false) {
1760     out += ' ' + ($data) + '.length ';
1761   } else {
1762     out += ' ucs2length(' + ($data) + ') ';
1763   }
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') {
1774         out += 'longer';
1775       } else {
1776         out += 'shorter';
1777       }
1778       out += ' than ';
1779       if ($isData) {
1780         out += '\' + ' + ($schemaValue) + ' + \'';
1781       } else {
1782         out += '' + ($schema);
1783       }
1784       out += ' characters\' ';
1785     }
1786     if (it.opts.verbose) {
1787       out += ' , schema:  ';
1788       if ($isData) {
1789         out += 'validate.schema' + ($schemaPath);
1790       } else {
1791         out += '' + ($schema);
1792       }
1793       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1794     }
1795     out += ' } ';
1796   } else {
1797     out += ' {} ';
1798   }
1799   var __err = out;
1800   out = $$outStack.pop();
1801   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1802     if (it.async) {
1803       out += ' throw new ValidationError([' + (__err) + ']); ';
1804     } else {
1805       out += ' validate.errors = [' + (__err) + ']; return false; ';
1806     }
1807   } else {
1808     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1809   }
1810   out += '} ';
1811   if ($breakOnError) {
1812     out += ' else { ';
1813   }
1814   return out;
1817 },{}],16:[function(require,module,exports){
1818 'use strict';
1819 module.exports = function generate__limitProperties(it, $keyword) {
1820   var out = ' ';
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;
1827   var $errorKeyword;
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;
1831   if ($isData) {
1832     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
1833     $schemaValue = 'schema' + $lvl;
1834   }
1835   var $op = $keyword == 'maxProperties' ? '>' : '<';
1836   out += 'if ( ';
1837   if ($isData) {
1838     out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
1839   }
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') {
1850         out += 'more';
1851       } else {
1852         out += 'less';
1853       }
1854       out += ' than ';
1855       if ($isData) {
1856         out += '\' + ' + ($schemaValue) + ' + \'';
1857       } else {
1858         out += '' + ($schema);
1859       }
1860       out += ' properties\' ';
1861     }
1862     if (it.opts.verbose) {
1863       out += ' , schema:  ';
1864       if ($isData) {
1865         out += 'validate.schema' + ($schemaPath);
1866       } else {
1867         out += '' + ($schema);
1868       }
1869       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1870     }
1871     out += ' } ';
1872   } else {
1873     out += ' {} ';
1874   }
1875   var __err = out;
1876   out = $$outStack.pop();
1877   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
1878     if (it.async) {
1879       out += ' throw new ValidationError([' + (__err) + ']); ';
1880     } else {
1881       out += ' validate.errors = [' + (__err) + ']; return false; ';
1882     }
1883   } else {
1884     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
1885   }
1886   out += '} ';
1887   if ($breakOnError) {
1888     out += ' else { ';
1889   }
1890   return out;
1893 },{}],17:[function(require,module,exports){
1894 'use strict';
1895 module.exports = function generate_allOf(it, $keyword) {
1896   var out = ' ';
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 = '';
1903   $it.level++;
1904   var $currentBaseId = $it.baseId;
1905   var arr1 = $schema;
1906   if (arr1) {
1907     var $sch, $i = -1,
1908       l1 = arr1.length - 1;
1909     while ($i < l1) {
1910       $sch = arr1[$i += 1];
1911       if (it.util.schemaHasRules($sch, it.RULES.all)) {
1912         $it.schema = $sch;
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 += '}';
1920         }
1921       }
1922     }
1923   }
1924   if ($breakOnError) {
1925     out += ' ' + ($closingBraces.slice(0, -1));
1926   }
1927   out = it.util.cleanUpCode(out);
1928   return out;
1931 },{}],18:[function(require,module,exports){
1932 'use strict';
1933 module.exports = function generate_anyOf(it, $keyword) {
1934   var out = ' ';
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;
1941   var $errorKeyword;
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 = '';
1947   $it.level++;
1948   var $noEmptySchema = $schema.every(function($sch) {
1949     return it.util.schemaHasRules($sch, it.RULES.all);
1950   });
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;
1956     var arr1 = $schema;
1957     if (arr1) {
1958       var $sch, $i = -1,
1959         l1 = arr1.length - 1;
1960       while ($i < l1) {
1961         $sch = arr1[$i += 1];
1962         $it.schema = $sch;
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 += '}';
1969       }
1970     }
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\' ';
1977       }
1978       if (it.opts.verbose) {
1979         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
1980       }
1981       out += ' } ';
1982     } else {
1983       out += ' {} ';
1984     }
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) {
1987       out += ' } ';
1988     }
1989     out = it.util.cleanUpCode(out);
1990   } else {
1991     if ($breakOnError) {
1992       out += ' if (true) { ';
1993     }
1994   }
1995   return out;
1998 },{}],19:[function(require,module,exports){
1999 'use strict';
2000 module.exports = function generate_constant(it, $keyword) {
2001   var out = ' ';
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;
2008   var $errorKeyword;
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;
2013   if ($isData) {
2014     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2015     $schemaValue = 'schema' + $lvl;
2016   }
2017   if (!$isData) {
2018     out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
2019   }
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\' ';
2028     }
2029     if (it.opts.verbose) {
2030       out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2031     }
2032     out += ' } ';
2033   } else {
2034     out += ' {} ';
2035   }
2036   var __err = out;
2037   out = $$outStack.pop();
2038   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2039     if (it.async) {
2040       out += ' throw new ValidationError([' + (__err) + ']); ';
2041     } else {
2042       out += ' validate.errors = [' + (__err) + ']; return false; ';
2043     }
2044   } else {
2045     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2046   }
2047   out += ' }';
2048   return out;
2051 },{}],20:[function(require,module,exports){
2052 'use strict';
2053 module.exports = function generate_dependencies(it, $keyword) {
2054   var out = ' ';
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;
2061   var $errorKeyword;
2062   var $data = 'data' + ($dataLvl || '');
2063   var $errs = 'errs__' + $lvl;
2064   var $it = it.util.copy(it);
2065   var $closingBraces = '';
2066   $it.level++;
2067   var $schemaDeps = {},
2068     $propertyDeps = {};
2069   for ($property in $schema) {
2070     var $sch = $schema[$property];
2071     var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
2072     $deps[$property] = $sch;
2073   }
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) {
2081       out += ' && ( ';
2082       var arr1 = $deps;
2083       if (arr1) {
2084         var _$property, $i = -1,
2085           l1 = arr1.length - 1;
2086         while ($i < l1) {
2087           _$property = arr1[$i += 1];
2088           if ($i) {
2089             out += ' || ';
2090           }
2091           var $prop = it.util.getProperty(_$property);
2092           out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
2093         }
2094       }
2095       out += ')) {  ';
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;
2100       }
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]));
2110           } else {
2111             out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2112           }
2113           out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2114         }
2115         if (it.opts.verbose) {
2116           out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2117         }
2118         out += ' } ';
2119       } else {
2120         out += ' {} ';
2121       }
2122       var __err = out;
2123       out = $$outStack.pop();
2124       if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2125         if (it.async) {
2126           out += ' throw new ValidationError([' + (__err) + ']); ';
2127         } else {
2128           out += ' validate.errors = [' + (__err) + ']; return false; ';
2129         }
2130       } else {
2131         out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2132       }
2133     } else {
2134       out += ' ) { ';
2135       var arr2 = $deps;
2136       if (arr2) {
2137         var $reqProperty, i2 = -1,
2138           l2 = arr2.length - 1;
2139         while (i2 < l2) {
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);
2145           }
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]));
2153               } else {
2154                 out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
2155               }
2156               out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
2157             }
2158             if (it.opts.verbose) {
2159               out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2160             }
2161             out += ' } ';
2162           } else {
2163             out += ' {} ';
2164           }
2165           out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
2166         }
2167       }
2168     }
2169     out += ' }   ';
2170     if ($breakOnError) {
2171       $closingBraces += '}';
2172       out += ' else { ';
2173     }
2174   }
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) { ';
2181       $it.schema = $sch;
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;
2186       out += ' }  ';
2187       if ($breakOnError) {
2188         out += ' if (valid' + ($it.level) + ') { ';
2189         $closingBraces += '}';
2190       }
2191     }
2192   }
2193   if ($breakOnError) {
2194     out += '   ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2195   }
2196   out = it.util.cleanUpCode(out);
2197   return out;
2200 },{}],21:[function(require,module,exports){
2201 'use strict';
2202 module.exports = function generate_enum(it, $keyword) {
2203   var out = ' ';
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;
2210   var $errorKeyword;
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;
2215   if ($isData) {
2216     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2217     $schemaValue = 'schema' + $lvl;
2218   }
2219   var $i = 'i' + $lvl;
2220   if (!$isData) {
2221     out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
2222   }
2223   out += 'var ' + ($valid) + ';';
2224   if ($isData) {
2225     out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
2226   }
2227   out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<schema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', schema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
2228   if ($isData) {
2229     out += '  }  ';
2230   }
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\' ';
2239     }
2240     if (it.opts.verbose) {
2241       out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2242     }
2243     out += ' } ';
2244   } else {
2245     out += ' {} ';
2246   }
2247   var __err = out;
2248   out = $$outStack.pop();
2249   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2250     if (it.async) {
2251       out += ' throw new ValidationError([' + (__err) + ']); ';
2252     } else {
2253       out += ' validate.errors = [' + (__err) + ']; return false; ';
2254     }
2255   } else {
2256     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2257   }
2258   out += ' }';
2259   if ($breakOnError) {
2260     out += ' else { ';
2261   }
2262   return out;
2265 },{}],22:[function(require,module,exports){
2266 'use strict';
2267 module.exports = function generate_format(it, $keyword) {
2268   var out = ' ';
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;
2275   var $errorKeyword;
2276   var $data = 'data' + ($dataLvl || '');
2277   if (it.opts.format === false) {
2278     if ($breakOnError) {
2279       out += ' if (true) { ';
2280     }
2281     return out;
2282   }
2283   var $isData = it.opts.v5 && $schema.$data;
2284   var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema;
2285   if ($isData) {
2286     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2287     $schemaValue = 'schema' + $lvl;
2288   }
2289   if ($isData) {
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 (  ';
2292     if ($isData) {
2293       out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2294     }
2295     out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? ';
2296     if (it.async) {
2297       out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
2298     } else {
2299       out += ' ' + ($format) + '(' + ($data) + ') ';
2300     }
2301     out += ' : ' + ($format) + '.test(' + ($data) + ')))) {';
2302   } else {
2303     var $format = it.formats[$schema];
2304     if (!$format) {
2305       if ($breakOnError) {
2306         out += ' if (true) { ';
2307       }
2308       return out;
2309     }
2310     var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
2311     if ($isObject) {
2312       var $async = $format.async === true;
2313       $format = $format.validate;
2314     }
2315     if ($async) {
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) + '))) { ';
2319     } else {
2320       out += ' if (! ';
2321       var $formatRef = 'formats' + it.util.getProperty($schema);
2322       if ($isObject) $formatRef += '.validate';
2323       if (typeof $format == 'function') {
2324         out += ' ' + ($formatRef) + '(' + ($data) + ') ';
2325       } else {
2326         out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
2327       }
2328       out += ') { ';
2329     }
2330   }
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:  ';
2336     if ($isData) {
2337       out += '' + ($schemaValue);
2338     } else {
2339       out += '' + (it.util.toQuotedString($schema));
2340     }
2341     out += '  } ';
2342     if (it.opts.messages !== false) {
2343       out += ' , message: \'should match format "';
2344       if ($isData) {
2345         out += '\' + ' + ($schemaValue) + ' + \'';
2346       } else {
2347         out += '' + (it.util.escapeQuotes($schema));
2348       }
2349       out += '"\' ';
2350     }
2351     if (it.opts.verbose) {
2352       out += ' , schema:  ';
2353       if ($isData) {
2354         out += 'validate.schema' + ($schemaPath);
2355       } else {
2356         out += '' + (it.util.toQuotedString($schema));
2357       }
2358       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2359     }
2360     out += ' } ';
2361   } else {
2362     out += ' {} ';
2363   }
2364   var __err = out;
2365   out = $$outStack.pop();
2366   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2367     if (it.async) {
2368       out += ' throw new ValidationError([' + (__err) + ']); ';
2369     } else {
2370       out += ' validate.errors = [' + (__err) + ']; return false; ';
2371     }
2372   } else {
2373     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2374   }
2375   out += ' } ';
2376   if ($breakOnError) {
2377     out += ' else { ';
2378   }
2379   return out;
2382 },{}],23:[function(require,module,exports){
2383 'use strict';
2384 module.exports = function generate_items(it, $keyword) {
2385   var out = ' ';
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;
2392   var $errorKeyword;
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 = '';
2398   $it.level++;
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\' ';
2417         }
2418         if (it.opts.verbose) {
2419           out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2420         }
2421         out += ' } ';
2422       } else {
2423         out += ' {} ';
2424       }
2425       var __err = out;
2426       out = $$outStack.pop();
2427       if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2428         if (it.async) {
2429           out += ' throw new ValidationError([' + (__err) + ']); ';
2430         } else {
2431           out += ' validate.errors = [' + (__err) + ']; return false; ';
2432         }
2433       } else {
2434         out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2435       }
2436       out += ' } ';
2437       $errSchemaPath = $currErrSchemaPath;
2438       if ($breakOnError) {
2439         $closingBraces += '}';
2440         out += ' else { ';
2441       }
2442     }
2443     var arr1 = $schema;
2444     if (arr1) {
2445       var $sch, $i = -1,
2446         l1 = arr1.length - 1;
2447       while ($i < l1) {
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 + ']';
2452           $it.schema = $sch;
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)) + ' ';
2461           } else {
2462             out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2463           }
2464           out += ' }  ';
2465           if ($breakOnError) {
2466             out += ' if (valid' + ($it.level) + ') { ';
2467             $closingBraces += '}';
2468           }
2469         }
2470       }
2471     }
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)) + ' ';
2484       } else {
2485         out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2486       }
2487       if ($breakOnError) {
2488         out += ' if (!valid' + ($it.level) + ') break; ';
2489       }
2490       out += ' } }  ';
2491       if ($breakOnError) {
2492         out += ' if (valid' + ($it.level) + ') { ';
2493         $closingBraces += '}';
2494       }
2495     }
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)) + ' ';
2508     } else {
2509       out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
2510     }
2511     if ($breakOnError) {
2512       out += ' if (!valid' + ($it.level) + ') break; ';
2513     }
2514     out += ' }  ';
2515     if ($breakOnError) {
2516       out += ' if (valid' + ($it.level) + ') { ';
2517       $closingBraces += '}';
2518     }
2519   }
2520   if ($breakOnError) {
2521     out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
2522   }
2523   out = it.util.cleanUpCode(out);
2524   return out;
2527 },{}],24:[function(require,module,exports){
2528 'use strict';
2529 module.exports = function generate_multipleOf(it, $keyword) {
2530   var out = ' ';
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;
2537   var $errorKeyword;
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;
2541   if ($isData) {
2542     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2543     $schemaValue = 'schema' + $lvl;
2544   }
2545   out += 'var division' + ($lvl) + ';if (';
2546   if ($isData) {
2547     out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
2548   }
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) + ' ';
2552   } else {
2553     out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
2554   }
2555   out += ' ) ';
2556   if ($isData) {
2557     out += '  )  ';
2558   }
2559   out += ' ) {   ';
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 ';
2567       if ($isData) {
2568         out += '\' + ' + ($schemaValue);
2569       } else {
2570         out += '' + ($schema) + '\'';
2571       }
2572     }
2573     if (it.opts.verbose) {
2574       out += ' , schema:  ';
2575       if ($isData) {
2576         out += 'validate.schema' + ($schemaPath);
2577       } else {
2578         out += '' + ($schema);
2579       }
2580       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2581     }
2582     out += ' } ';
2583   } else {
2584     out += ' {} ';
2585   }
2586   var __err = out;
2587   out = $$outStack.pop();
2588   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2589     if (it.async) {
2590       out += ' throw new ValidationError([' + (__err) + ']); ';
2591     } else {
2592       out += ' validate.errors = [' + (__err) + ']; return false; ';
2593     }
2594   } else {
2595     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2596   }
2597   out += '} ';
2598   if ($breakOnError) {
2599     out += ' else { ';
2600   }
2601   return out;
2604 },{}],25:[function(require,module,exports){
2605 'use strict';
2606 module.exports = function generate_not(it, $keyword) {
2607   var out = ' ';
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;
2614   var $errorKeyword;
2615   var $data = 'data' + ($dataLvl || '');
2616   var $errs = 'errs__' + $lvl;
2617   var $it = it.util.copy(it);
2618   $it.level++;
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;
2631     }
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\' ';
2644       }
2645       if (it.opts.verbose) {
2646         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2647       }
2648       out += ' } ';
2649     } else {
2650       out += ' {} ';
2651     }
2652     var __err = out;
2653     out = $$outStack.pop();
2654     if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2655       if (it.async) {
2656         out += ' throw new ValidationError([' + (__err) + ']); ';
2657       } else {
2658         out += ' validate.errors = [' + (__err) + ']; return false; ';
2659       }
2660     } else {
2661       out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2662     }
2663     out += ' } else {  errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
2664     if (it.opts.allErrors) {
2665       out += ' } ';
2666     }
2667   } else {
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\' ';
2673       }
2674       if (it.opts.verbose) {
2675         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2676       }
2677       out += ' } ';
2678     } else {
2679       out += ' {} ';
2680     }
2681     out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2682     if ($breakOnError) {
2683       out += ' if (false) { ';
2684     }
2685   }
2686   return out;
2689 },{}],26:[function(require,module,exports){
2690 'use strict';
2691 module.exports = function generate_oneOf(it, $keyword) {
2692   var out = ' ';
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;
2699   var $errorKeyword;
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 = '';
2705   $it.level++;
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;
2710   var arr1 = $schema;
2711   if (arr1) {
2712     var $sch, $i = -1,
2713       l1 = arr1.length - 1;
2714     while ($i < l1) {
2715       $sch = arr1[$i += 1];
2716       if (it.util.schemaHasRules($sch, it.RULES.all)) {
2717         $it.schema = $sch;
2718         $it.schemaPath = $schemaPath + '[' + $i + ']';
2719         $it.errSchemaPath = $errSchemaPath + '/' + $i;
2720         out += '  ' + (it.validate($it)) + ' ';
2721         $it.baseId = $currentBaseId;
2722       } else {
2723         out += ' var valid' + ($it.level) + ' = true; ';
2724       }
2725       if ($i) {
2726         out += ' if (valid' + ($it.level) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
2727         $closingBraces += '}';
2728       }
2729       out += ' if (valid' + ($it.level) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
2730     }
2731   }
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\' ';
2741     }
2742     if (it.opts.verbose) {
2743       out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2744     }
2745     out += ' } ';
2746   } else {
2747     out += ' {} ';
2748   }
2749   var __err = out;
2750   out = $$outStack.pop();
2751   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2752     if (it.async) {
2753       out += ' throw new ValidationError([' + (__err) + ']); ';
2754     } else {
2755       out += ' validate.errors = [' + (__err) + ']; return false; ';
2756     }
2757   } else {
2758     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2759   }
2760   out += '} else {  errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
2761   if (it.opts.allErrors) {
2762     out += ' } ';
2763   }
2764   return out;
2767 },{}],27:[function(require,module,exports){
2768 'use strict';
2769 module.exports = function generate_pattern(it, $keyword) {
2770   var out = ' ';
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;
2777   var $errorKeyword;
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;
2781   if ($isData) {
2782     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
2783     $schemaValue = 'schema' + $lvl;
2784   }
2785   var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
2786   out += 'if ( ';
2787   if ($isData) {
2788     out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
2789   }
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:  ';
2796     if ($isData) {
2797       out += '' + ($schemaValue);
2798     } else {
2799       out += '' + (it.util.toQuotedString($schema));
2800     }
2801     out += '  } ';
2802     if (it.opts.messages !== false) {
2803       out += ' , message: \'should match pattern "';
2804       if ($isData) {
2805         out += '\' + ' + ($schemaValue) + ' + \'';
2806       } else {
2807         out += '' + (it.util.escapeQuotes($schema));
2808       }
2809       out += '"\' ';
2810     }
2811     if (it.opts.verbose) {
2812       out += ' , schema:  ';
2813       if ($isData) {
2814         out += 'validate.schema' + ($schemaPath);
2815       } else {
2816         out += '' + (it.util.toQuotedString($schema));
2817       }
2818       out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2819     }
2820     out += ' } ';
2821   } else {
2822     out += ' {} ';
2823   }
2824   var __err = out;
2825   out = $$outStack.pop();
2826   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
2827     if (it.async) {
2828       out += ' throw new ValidationError([' + (__err) + ']); ';
2829     } else {
2830       out += ' validate.errors = [' + (__err) + ']; return false; ';
2831     }
2832   } else {
2833     out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
2834   }
2835   out += '} ';
2836   if ($breakOnError) {
2837     out += ' else { ';
2838   }
2839   return out;
2842 },{}],28:[function(require,module,exports){
2843 'use strict';
2844 module.exports = function generate_patternRequired(it, $keyword) {
2845   var out = ' ';
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;
2852   var $errorKeyword;
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;';
2860   var arr1 = $schema;
2861   if (arr1) {
2862     var $pProperty, i1 = -1,
2863       l1 = arr1.length - 1;
2864     while (i1 < l1) {
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; ';
2869       }
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) + '\\\'\' ';
2877         }
2878         if (it.opts.verbose) {
2879           out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
2880         }
2881         out += ' } ';
2882       } else {
2883         out += ' {} ';
2884       }
2885       out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }   ';
2886       if ($breakOnError) {
2887         $closingBraces += '}';
2888         out += ' else { ';
2889       }
2890     }
2891   }
2892   out += '' + ($closingBraces);
2893   return out;
2896 },{}],29:[function(require,module,exports){
2897 'use strict';
2898 module.exports = function generate_properties(it, $keyword) {
2899   var out = ' ';
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;
2906   var $errorKeyword;
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 = '';
2912   $it.level++;
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);
2929   if (it.opts.v5) {
2930     var $pgProperties = it.schema.patternGroups || {},
2931       $pgPropertyKeys = Object.keys($pgProperties);
2932   }
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; ';
2938     }
2939     if ($someProperties) {
2940       out += ' var isAdditional' + ($lvl) + ' = !(false ';
2941       if ($schemaKeys.length) {
2942         if ($schemaKeys.length > 5) {
2943           out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] ';
2944         } else {
2945           var arr1 = $schemaKeys;
2946           if (arr1) {
2947             var $propertyKey, i1 = -1,
2948               l1 = arr1.length - 1;
2949             while (i1 < l1) {
2950               $propertyKey = arr1[i1 += 1];
2951               out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
2952             }
2953           }
2954         }
2955       }
2956       if ($pPropertyKeys.length) {
2957         var arr2 = $pPropertyKeys;
2958         if (arr2) {
2959           var $pProperty, $i = -1,
2960             l2 = arr2.length - 1;
2961           while ($i < l2) {
2962             $pProperty = arr2[$i += 1];
2963             out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
2964           }
2965         }
2966       }
2967       if (it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length) {
2968         var arr3 = $pgPropertyKeys;
2969         if (arr3) {
2970           var $pgProperty, $i = -1,
2971             l3 = arr3.length - 1;
2972           while ($i < l3) {
2973             $pgProperty = arr3[$i += 1];
2974             out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') ';
2975           }
2976         }
2977       }
2978       out += ' ); if (isAdditional' + ($lvl) + ') { ';
2979     }
2980     if ($removeAdditional == 'all') {
2981       out += ' delete ' + ($data) + '[' + ($key) + ']; ';
2982     } else {
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);
2987       }
2988       if ($noAdditional) {
2989         if ($removeAdditional) {
2990           out += ' delete ' + ($data) + '[' + ($key) + ']; ';
2991         } else {
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\' ';
3002             }
3003             if (it.opts.verbose) {
3004               out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3005             }
3006             out += ' } ';
3007           } else {
3008             out += ' {} ';
3009           }
3010           var __err = out;
3011           out = $$outStack.pop();
3012           if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3013             if (it.async) {
3014               out += ' throw new ValidationError([' + (__err) + ']); ';
3015             } else {
3016               out += ' validate.errors = [' + (__err) + ']; return false; ';
3017             }
3018           } else {
3019             out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3020           }
3021           $errSchemaPath = $currErrSchemaPath;
3022           if ($breakOnError) {
3023             out += ' break; ';
3024           }
3025         }
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)) + ' ';
3041           } else {
3042             out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3043           }
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;
3046         } else {
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)) + ' ';
3057           } else {
3058             out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3059           }
3060           if ($breakOnError) {
3061             out += ' if (!valid' + ($it.level) + ') break; ';
3062           }
3063         }
3064       }
3065       it.errorPath = $currentErrorPath;
3066     }
3067     if ($someProperties) {
3068       out += ' } ';
3069     }
3070     out += ' }  ';
3071     if ($breakOnError) {
3072       out += ' if (valid' + ($it.level) + ') { ';
3073       $closingBraces += '}';
3074     }
3075   }
3076   var $useDefaults = it.opts.useDefaults && !it.compositeRule;
3077   if ($schemaKeys.length) {
3078     var arr4 = $schemaKeys;
3079     if (arr4) {
3080       var $propertyKey, i4 = -1,
3081         l4 = arr4.length - 1;
3082       while (i4 < l4) {
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;
3089           $it.schema = $sch;
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;
3099           } else {
3100             var $useData = $nextData;
3101             out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
3102           }
3103           if ($hasDefault) {
3104             out += ' ' + ($code) + ' ';
3105           } else {
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);
3113               }
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';
3124                   } else {
3125                     out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3126                   }
3127                   out += '\' ';
3128                 }
3129                 if (it.opts.verbose) {
3130                   out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3131                 }
3132                 out += ' } ';
3133               } else {
3134                 out += ' {} ';
3135               }
3136               var __err = out;
3137               out = $$outStack.pop();
3138               if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3139                 if (it.async) {
3140                   out += ' throw new ValidationError([' + (__err) + ']); ';
3141                 } else {
3142                   out += ' validate.errors = [' + (__err) + ']; return false; ';
3143                 }
3144               } else {
3145                 out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3146               }
3147               $errSchemaPath = $currErrSchemaPath;
3148               it.errorPath = $currentErrorPath;
3149               out += ' } else { ';
3150             } else {
3151               if ($breakOnError) {
3152                 out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = true; } else { ';
3153               } else {
3154                 out += ' if (' + ($useData) + ' !== undefined) { ';
3155               }
3156             }
3157             out += ' ' + ($code) + ' } ';
3158           }
3159         }
3160         if ($breakOnError) {
3161           out += ' if (valid' + ($it.level) + ') { ';
3162           $closingBraces += '}';
3163         }
3164       }
3165     }
3166   }
3167   var arr5 = $pPropertyKeys;
3168   if (arr5) {
3169     var $pProperty, i5 = -1,
3170       l5 = arr5.length - 1;
3171     while (i5 < l5) {
3172       $pProperty = arr5[i5 += 1];
3173       var $sch = $pProperties[$pProperty];
3174       if (it.util.schemaHasRules($sch, it.RULES.all)) {
3175         $it.schema = $sch;
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; ';
3181         }
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)) + ' ';
3190         } else {
3191           out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3192         }
3193         if ($breakOnError) {
3194           out += ' if (!valid' + ($it.level) + ') break; ';
3195         }
3196         out += ' } ';
3197         if ($breakOnError) {
3198           out += ' else valid' + ($it.level) + ' = true; ';
3199         }
3200         out += ' }  ';
3201         if ($breakOnError) {
3202           out += ' if (valid' + ($it.level) + ') { ';
3203           $closingBraces += '}';
3204         }
3205       }
3206     }
3207   }
3208   if (it.opts.v5) {
3209     var arr6 = $pgPropertyKeys;
3210     if (arr6) {
3211       var $pgProperty, i6 = -1,
3212         l6 = arr6.length - 1;
3213       while (i6 < l6) {
3214         $pgProperty = arr6[i6 += 1];
3215         var $pgSchema = $pgProperties[$pgProperty],
3216           $sch = $pgSchema.schema;
3217         if (it.util.schemaHasRules($sch, it.RULES.all)) {
3218           $it.schema = $sch;
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; ';
3224           }
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)) + ' ';
3233           } else {
3234             out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
3235           }
3236           if ($breakOnError) {
3237             out += ' if (!valid' + ($it.level) + ') break; ';
3238           }
3239           out += ' } ';
3240           if ($breakOnError) {
3241             out += ' else valid' + ($it.level) + ' = true; ';
3242           }
3243           out += ' }  ';
3244           if ($breakOnError) {
3245             out += ' if (valid' + ($it.level) + ') { ';
3246             $closingBraces += '}';
3247           }
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)) + '"\' ';
3267                 }
3268                 if (it.opts.verbose) {
3269                   out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3270                 }
3271                 out += ' } ';
3272               } else {
3273                 out += ' {} ';
3274               }
3275               var __err = out;
3276               out = $$outStack.pop();
3277               if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3278                 if (it.async) {
3279                   out += ' throw new ValidationError([' + (__err) + ']); ';
3280                 } else {
3281                   out += ' validate.errors = [' + (__err) + ']; return false; ';
3282                 }
3283               } else {
3284                 out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3285               }
3286               out += ' } ';
3287               if ($pgMax !== undefined) {
3288                 out += ' else ';
3289               }
3290             }
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)) + '"\' ';
3305                 }
3306                 if (it.opts.verbose) {
3307                   out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3308                 }
3309                 out += ' } ';
3310               } else {
3311                 out += ' {} ';
3312               }
3313               var __err = out;
3314               out = $$outStack.pop();
3315               if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3316                 if (it.async) {
3317                   out += ' throw new ValidationError([' + (__err) + ']); ';
3318                 } else {
3319                   out += ' validate.errors = [' + (__err) + ']; return false; ';
3320                 }
3321               } else {
3322                 out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3323               }
3324               out += ' } ';
3325             }
3326             $errSchemaPath = $currErrSchemaPath;
3327             if ($breakOnError) {
3328               out += ' if (' + ($valid) + ') { ';
3329               $closingBraces += '}';
3330             }
3331           }
3332         }
3333       }
3334     }
3335   }
3336   if ($breakOnError) {
3337     out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
3338   }
3339   out = it.util.cleanUpCode(out);
3340   return out;
3343 },{}],30:[function(require,module,exports){
3344 'use strict';
3345 module.exports = function generate_ref(it, $keyword) {
3346   var out = ' ';
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;
3352   var $errorKeyword;
3353   var $data = 'data' + ($dataLvl || '');
3354   var $valid = 'valid' + $lvl;
3355   var $async, $refCode;
3356   if ($schema == '#' || $schema == '#/') {
3357     if (it.isRoot) {
3358       $async = it.async;
3359       $refCode = 'validate';
3360     } else {
3361       $async = it.root.schema.$async === true;
3362       $refCode = 'root.refVal[0]';
3363     }
3364   } else {
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)) + '\' ';
3377           }
3378           if (it.opts.verbose) {
3379             out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3380           }
3381           out += ' } ';
3382         } else {
3383           out += ' {} ';
3384         }
3385         var __err = out;
3386         out = $$outStack.pop();
3387         if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3388           if (it.async) {
3389             out += ' throw new ValidationError([' + (__err) + ']); ';
3390           } else {
3391             out += ' validate.errors = [' + (__err) + ']; return false; ';
3392           }
3393         } else {
3394           out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3395         }
3396         if ($breakOnError) {
3397           out += ' if (false) { ';
3398         }
3399       } else if (it.opts.missingRefs == 'ignore') {
3400         console.log($message);
3401         if ($breakOnError) {
3402           out += ' if (true) { ';
3403         }
3404       } else {
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));
3408         throw $error;
3409       }
3410     } else if ($refVal.inline) {
3411       var $it = it.util.copy(it);
3412       $it.level++;
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) + ') { ';
3420       }
3421     } else {
3422       $async = $refVal.$async === true;
3423       $refCode = $refVal.code;
3424     }
3425   }
3426   if ($refCode) {
3427     var $$outStack = $$outStack || [];
3428     $$outStack.push(out);
3429     out = '';
3430     if (it.opts.passContext) {
3431       out += ' ' + ($refCode) + '.call(this, ';
3432     } else {
3433       out += ' ' + ($refCode) + '( ';
3434     }
3435     out += ' ' + ($data) + ', (dataPath || \'\')';
3436     if (it.errorPath != '""') {
3437       out += ' + ' + (it.errorPath);
3438     }
3439     if ($dataLvl) {
3440       out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
3441     } else {
3442       out += ' , parentData , parentDataProperty ';
3443     }
3444     out += ')  ';
3445     var __callValidate = out;
3446     out = $$outStack.pop();
3447     if ($async) {
3448       if (!it.async) throw new Error('async schema referenced by sync schema');
3449       out += ' try { ';
3450       if ($breakOnError) {
3451         out += 'var ' + ($valid) + ' =';
3452       }
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) + ') { ';
3456       }
3457     } else {
3458       out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
3459       if ($breakOnError) {
3460         out += ' else { ';
3461       }
3462     }
3463   }
3464   return out;
3467 },{}],31:[function(require,module,exports){
3468 'use strict';
3469 module.exports = function generate_required(it, $keyword) {
3470   var out = ' ';
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;
3477   var $errorKeyword;
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;
3482   if ($isData) {
3483     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
3484     $schemaValue = 'schema' + $lvl;
3485   }
3486   if (!$isData) {
3487     if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
3488       var $required = [];
3489       var arr1 = $schema;
3490       if (arr1) {
3491         var $property, i1 = -1,
3492           l1 = arr1.length - 1;
3493         while (i1 < l1) {
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;
3498           }
3499         }
3500       }
3501     } else {
3502       var $required = $schema;
3503     }
3504   }
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) {
3511         if (!$isData) {
3512           out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
3513         }
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);
3519         }
3520         out += ' var ' + ($valid) + ' = true; ';
3521         if ($isData) {
3522           out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
3523         }
3524         out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } ';
3525         if ($isData) {
3526           out += '  }  ';
3527         }
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';
3538             } else {
3539               out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3540             }
3541             out += '\' ';
3542           }
3543           if (it.opts.verbose) {
3544             out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3545           }
3546           out += ' } ';
3547         } else {
3548           out += ' {} ';
3549         }
3550         var __err = out;
3551         out = $$outStack.pop();
3552         if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3553           if (it.async) {
3554             out += ' throw new ValidationError([' + (__err) + ']); ';
3555           } else {
3556             out += ' validate.errors = [' + (__err) + ']; return false; ';
3557           }
3558         } else {
3559           out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3560         }
3561         out += ' } else { ';
3562       } else {
3563         out += ' if ( ';
3564         var arr2 = $required;
3565         if (arr2) {
3566           var _$property, $i = -1,
3567             l2 = arr2.length - 1;
3568           while ($i < l2) {
3569             _$property = arr2[$i += 1];
3570             if ($i) {
3571               out += ' || ';
3572             }
3573             var $prop = it.util.getProperty(_$property);
3574             out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
3575           }
3576         }
3577         out += ') {  ';
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;
3582         }
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';
3592             } else {
3593               out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3594             }
3595             out += '\' ';
3596           }
3597           if (it.opts.verbose) {
3598             out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3599           }
3600           out += ' } ';
3601         } else {
3602           out += ' {} ';
3603         }
3604         var __err = out;
3605         out = $$outStack.pop();
3606         if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3607           if (it.async) {
3608             out += ' throw new ValidationError([' + (__err) + ']); ';
3609           } else {
3610             out += ' validate.errors = [' + (__err) + ']; return false; ';
3611           }
3612         } else {
3613           out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3614         }
3615         out += ' } else { ';
3616       }
3617     } else {
3618       if ($loopRequired) {
3619         if (!$isData) {
3620           out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; ';
3621         }
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);
3627         }
3628         if ($isData) {
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';
3636               } else {
3637                 out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3638               }
3639               out += '\' ';
3640             }
3641             if (it.opts.verbose) {
3642               out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3643             }
3644             out += ' } ';
3645           } else {
3646             out += ' {} ';
3647           }
3648           out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (schema' + ($lvl) + ' !== undefined) { ';
3649         }
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';
3657             } else {
3658               out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3659             }
3660             out += '\' ';
3661           }
3662           if (it.opts.verbose) {
3663             out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3664           }
3665           out += ' } ';
3666         } else {
3667           out += ' {} ';
3668         }
3669         out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
3670         if ($isData) {
3671           out += '  }  ';
3672         }
3673       } else {
3674         var arr3 = $required;
3675         if (arr3) {
3676           var $reqProperty, i3 = -1,
3677             l3 = arr3.length - 1;
3678           while (i3 < l3) {
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);
3684             }
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';
3692                 } else {
3693                   out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
3694                 }
3695                 out += '\' ';
3696               }
3697               if (it.opts.verbose) {
3698                 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3699               }
3700               out += ' } ';
3701             } else {
3702               out += ' {} ';
3703             }
3704             out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
3705           }
3706         }
3707       }
3708     }
3709     it.errorPath = $currentErrorPath;
3710   } else if ($breakOnError) {
3711     out += ' if (true) {';
3712   }
3713   return out;
3716 },{}],32:[function(require,module,exports){
3717 'use strict';
3718 module.exports = function generate_switch(it, $keyword) {
3719   var out = ' ';
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;
3726   var $errorKeyword;
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 = '';
3732   $it.level++;
3733   var $ifPassed = 'ifPassed' + it.level,
3734     $currentBaseId = $it.baseId,
3735     $shouldContinue;
3736   out += 'var ' + ($ifPassed) + ';';
3737   var arr1 = $schema;
3738   if (arr1) {
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 += '}';
3746       }
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\' ';
3769               }
3770               if (it.opts.verbose) {
3771                 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3772               }
3773               out += ' } ';
3774             } else {
3775               out += ' {} ';
3776             }
3777             var __err = out;
3778             out = $$outStack.pop();
3779             if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3780               if (it.async) {
3781                 out += ' throw new ValidationError([' + (__err) + ']); ';
3782               } else {
3783                 out += ' validate.errors = [' + (__err) + ']; return false; ';
3784               }
3785             } else {
3786               out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3787             }
3788           }
3789           out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
3790         } else {
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;
3796         }
3797         out += '  } else {  errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } } ';
3798       } else {
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\' ';
3809               }
3810               if (it.opts.verbose) {
3811                 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3812               }
3813               out += ' } ';
3814             } else {
3815               out += ' {} ';
3816             }
3817             var __err = out;
3818             out = $$outStack.pop();
3819             if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3820               if (it.async) {
3821                 out += ' throw new ValidationError([' + (__err) + ']); ';
3822               } else {
3823                 out += ' validate.errors = [' + (__err) + ']; return false; ';
3824               }
3825             } else {
3826               out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3827             }
3828           }
3829           out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; ';
3830         } else {
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;
3836         }
3837       }
3838       $shouldContinue = $sch.continue
3839     }
3840   }
3841   out += '' + ($closingBraces) + 'var ' + ($valid) + ' = valid' + ($it.level) + '; ';
3842   out = it.util.cleanUpCode(out);
3843   return out;
3846 },{}],33:[function(require,module,exports){
3847 'use strict';
3848 module.exports = function generate_uniqueItems(it, $keyword) {
3849   var out = ' ';
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;
3856   var $errorKeyword;
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;
3861   if ($isData) {
3862     out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; ';
3863     $schemaValue = 'schema' + $lvl;
3864   }
3865   if (($schema || $isData) && it.opts.uniqueItems !== false) {
3866     if ($isData) {
3867       out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
3868     }
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; } } } } ';
3870     if ($isData) {
3871       out += '  }  ';
3872     }
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)\' ';
3881       }
3882       if (it.opts.verbose) {
3883         out += ' , schema:  ';
3884         if ($isData) {
3885           out += 'validate.schema' + ($schemaPath);
3886         } else {
3887           out += '' + ($schema);
3888         }
3889         out += '         , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
3890       }
3891       out += ' } ';
3892     } else {
3893       out += ' {} ';
3894     }
3895     var __err = out;
3896     out = $$outStack.pop();
3897     if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
3898       if (it.async) {
3899         out += ' throw new ValidationError([' + (__err) + ']); ';
3900       } else {
3901         out += ' validate.errors = [' + (__err) + ']; return false; ';
3902       }
3903     } else {
3904       out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
3905     }
3906     out += ' } ';
3907     if ($breakOnError) {
3908       out += ' else { ';
3909     }
3910   } else {
3911     if ($breakOnError) {
3912       out += ' if (true) { ';
3913     }
3914   }
3915   return out;
3918 },{}],34:[function(require,module,exports){
3919 'use strict';
3920 module.exports = function generate_validate(it, $keyword) {
3921   var out = '';
3922   var $async = it.schema.$async === true;
3923   if (it.isTop) {
3924     var $top = it.isTop,
3925       $lvl = it.level = 0,
3926       $dataLvl = it.dataLevel = 0,
3927       $data = 'data';
3928     it.rootId = it.resolve.fullPath(it.root.schema.id);
3929     it.baseId = it.baseId || it.rootId;
3930     if ($async) {
3931       it.async = true;
3932       var $es7 = it.opts.async == 'es7';
3933       it.yieldAwait = $es7 ? 'await' : 'yield';
3934     }
3935     delete it.isTop;
3936     it.dataPathArr = [undefined];
3937     out += ' validate = ';
3938     if ($async) {
3939       if ($es7) {
3940         out += ' (async function ';
3941       } else {
3942         if (it.opts.async == 'co*') {
3943           out += 'co.wrap';
3944         }
3945         out += '(function* ';
3946       }
3947     } else {
3948       out += ' (function ';
3949     }
3950     out += ' (data, dataPath, parentData, parentDataProperty) { \'use strict\'; var vErrors = null; ';
3951     out += ' var errors = 0;     ';
3952   } else {
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;';
3959   }
3960   var $valid = 'valid' + $lvl,
3961     $breakOnError = !it.opts.allErrors,
3962     $closingBraces1 = '',
3963     $closingBraces2 = '',
3964     $errorKeyword;
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;
3979       if (arr1) {
3980         var $type, $i = -1,
3981           l1 = arr1.length - 1;
3982         while ($i < l1) {
3983           $type = arr1[$i += 1];
3984           if ($i) {
3985             out += ' if (' + ($coerced) + ' === undefined) { ';
3986             $bracesCoercion += '}';
3987           }
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)';
3994             }
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; ';
4000           }
4001         }
4002       }
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: \'';
4009         if ($typeIsArray) {
4010           out += '' + ($typeSchema.join(","));
4011         } else {
4012           out += '' + ($typeSchema);
4013         }
4014         out += '\' } ';
4015         if (it.opts.messages !== false) {
4016           out += ' , message: \'should be ';
4017           if ($typeIsArray) {
4018             out += '' + ($typeSchema.join(","));
4019           } else {
4020             out += '' + ($typeSchema);
4021           }
4022           out += '\' ';
4023         }
4024         if (it.opts.verbose) {
4025           out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4026         }
4027         out += ' } ';
4028       } else {
4029         out += ' {} ';
4030       }
4031       var __err = out;
4032       out = $$outStack.pop();
4033       if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4034         if (it.async) {
4035           out += ' throw new ValidationError([' + (__err) + ']); ';
4036         } else {
4037           out += ' validate.errors = [' + (__err) + ']; return false; ';
4038         }
4039       } else {
4040         out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4041       }
4042       out += ' } else { ';
4043       if ($dataLvl) {
4044         var $parentData = 'data' + (($dataLvl - 1) || ''),
4045           $dataProperty = it.dataPathArr[$dataLvl];
4046         out += ' ' + ($data) + ' = ' + ($parentData) + '[' + ($dataProperty) + '] = ' + ($coerced) + '; ';
4047       } else {
4048         out += ' data = ' + ($coerced) + '; if (parentData !== undefined) parentData[parentDataProperty] = ' + ($coerced) + '; ';
4049       }
4050       out += ' } } ';
4051     }
4052   }
4053   var arr2 = it.RULES;
4054   if (arr2) {
4055     var $rulesGroup, i2 = -1,
4056       l2 = arr2.length - 1;
4057     while (i2 < l2) {
4058       $rulesGroup = arr2[i2 += 1];
4059       if ($shouldUseGroup($rulesGroup)) {
4060         if ($rulesGroup.type) {
4061           out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
4062         }
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;
4068             if (arr3) {
4069               var $propertyKey, i3 = -1,
4070                 l3 = arr3.length - 1;
4071               while (i3 < l3) {
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)) + ' ';
4079                   } else {
4080                     out += ' ' + (JSON.stringify($sch.default)) + ' ';
4081                   }
4082                   out += '; ';
4083                 }
4084               }
4085             }
4086           } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
4087             var arr4 = it.schema.items;
4088             if (arr4) {
4089               var $sch, $i = -1,
4090                 l4 = arr4.length - 1;
4091               while ($i < l4) {
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)) + ' ';
4098                   } else {
4099                     out += ' ' + (JSON.stringify($sch.default)) + ' ';
4100                   }
4101                   out += '; ';
4102                 }
4103               }
4104             }
4105           }
4106         }
4107         var arr5 = $rulesGroup.rules;
4108         if (arr5) {
4109           var $rule, i5 = -1,
4110             l5 = arr5.length - 1;
4111           while (i5 < l5) {
4112             $rule = arr5[i5 += 1];
4113             if ($shouldUseRule($rule)) {
4114               if ($rule.custom) {
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,
4121                   $i = 'i' + $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;';
4130                 }
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);
4136                   $it.level++;
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);
4147                   out = '';
4148                   out += '  ' + ($ruleValidate.code) + '.call( ';
4149                   if (it.opts.passContext) {
4150                     out += 'this';
4151                   } else {
4152                     out += 'self';
4153                   }
4154                   if ($rDef.compile || $rDef.schema === false) {
4155                     out += ' , ' + ($data) + ' ';
4156                   } else {
4157                     out += ' , validate.schema' + ($schemaPath) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
4158                   }
4159                   out += ' , (dataPath || \'\')';
4160                   if (it.errorPath != '""') {
4161                     out += ' + ' + (it.errorPath);
4162                   }
4163                   if ($dataLvl) {
4164                     out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' ';
4165                   } else {
4166                     out += ' , parentData , parentDataProperty ';
4167                   }
4168                   out += ' )  ';
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; } ';
4175                     } else {
4176                       out += ' ' + ($ruleValidate.code) + '.errors = null; ';
4177                     }
4178                   }
4179                 }
4180                 out += 'if (! ';
4181                 if ($inline) {
4182                   if ($rDef.statements) {
4183                     out += ' valid' + ($lvl) + ' ';
4184                   } else {
4185                     out += ' (' + ($ruleValidate.validate) + ') ';
4186                   }
4187                 } else if ($macro) {
4188                   out += ' valid' + ($it.level) + ' ';
4189                 } else {
4190                   if ($asyncKeyword) {
4191                     if ($rDef.errors === false) {
4192                       out += ' (' + (it.yieldAwait) + (def_callRuleValidate) + ') ';
4193                     } else {
4194                       out += ' valid' + ($lvl) + ' ';
4195                     }
4196                   } else {
4197                     out += ' ' + (def_callRuleValidate) + ' ';
4198                   }
4199                 }
4200                 out += ') { ';
4201                 $errorKeyword = $rule.keyword;
4202                 var $$outStack = $$outStack || [];
4203                 $$outStack.push(out);
4204                 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\' ';
4212                   }
4213                   if (it.opts.verbose) {
4214                     out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4215                   }
4216                   out += ' } ';
4217                 } else {
4218                   out += ' {} ';
4219                 }
4220                 var __err = out;
4221                 out = $$outStack.pop();
4222                 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4223                   if (it.async) {
4224                     out += ' throw new ValidationError([' + (__err) + ']); ';
4225                   } else {
4226                     out += ' validate.errors = [' + (__err) + ']; return false; ';
4227                   }
4228                 } else {
4229                   out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4230                 }
4231                 var def_customError = out;
4232                 out = $$outStack.pop();
4233                 if ($inline) {
4234                   if ($rDef.errors) {
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) + '; ';
4239                       }
4240                       out += ' } ';
4241                     }
4242                   } else {
4243                     if ($rDef.errors === false) {
4244                       out += ' ' + (def_customError) + ' ';
4245                     } else {
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) + '; ';
4249                       }
4250                       out += ' } } ';
4251                     }
4252                   }
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\' ';
4259                     }
4260                     if (it.opts.verbose) {
4261                       out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4262                     }
4263                     out += ' } ';
4264                   } else {
4265                     out += ' {} ';
4266                   }
4267                   out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4268                   if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4269                     if (it.async) {
4270                       out += ' throw new ValidationError(vErrors); ';
4271                     } else {
4272                       out += ' validate.errors = vErrors; return false ';
4273                     }
4274                   }
4275                 } else {
4276                   if ($rDef.errors === false) {
4277                     out += ' ' + (def_customError) + ' ';
4278                   } else {
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) + '; ';
4282                     }
4283                     out += ' } } else { ' + (def_customError) + ' } ';
4284                   }
4285                 }
4286                 $errorKeyword = undefined;
4287                 out += ' } ';
4288                 if ($breakOnError) {
4289                   out += ' else { ';
4290                 }
4291               } else {
4292                 out += ' ' + ($rule.code(it, $rule.keyword)) + ' ';
4293               }
4294               if ($breakOnError) {
4295                 $closingBraces1 += '}';
4296               }
4297             }
4298           }
4299         }
4300         if ($breakOnError) {
4301           out += ' ' + ($closingBraces1) + ' ';
4302           $closingBraces1 = '';
4303         }
4304         if ($rulesGroup.type) {
4305           out += ' } ';
4306           if ($typeSchema && $typeSchema === $rulesGroup.type) {
4307             var $typeChecked = true;
4308             out += ' else { ';
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: \'';
4316               if ($typeIsArray) {
4317                 out += '' + ($typeSchema.join(","));
4318               } else {
4319                 out += '' + ($typeSchema);
4320               }
4321               out += '\' } ';
4322               if (it.opts.messages !== false) {
4323                 out += ' , message: \'should be ';
4324                 if ($typeIsArray) {
4325                   out += '' + ($typeSchema.join(","));
4326                 } else {
4327                   out += '' + ($typeSchema);
4328                 }
4329                 out += '\' ';
4330               }
4331               if (it.opts.verbose) {
4332                 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4333               }
4334               out += ' } ';
4335             } else {
4336               out += ' {} ';
4337             }
4338             var __err = out;
4339             out = $$outStack.pop();
4340             if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4341               if (it.async) {
4342                 out += ' throw new ValidationError([' + (__err) + ']); ';
4343               } else {
4344                 out += ' validate.errors = [' + (__err) + ']; return false; ';
4345               }
4346             } else {
4347               out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4348             }
4349             out += ' } ';
4350           }
4351         }
4352         if ($breakOnError) {
4353           out += ' if (errors === ';
4354           if ($top) {
4355             out += '0';
4356           } else {
4357             out += 'errs_' + ($lvl);
4358           }
4359           out += ') { ';
4360           $closingBraces2 += '}';
4361         }
4362       }
4363     }
4364   }
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: \'';
4375       if ($typeIsArray) {
4376         out += '' + ($typeSchema.join(","));
4377       } else {
4378         out += '' + ($typeSchema);
4379       }
4380       out += '\' } ';
4381       if (it.opts.messages !== false) {
4382         out += ' , message: \'should be ';
4383         if ($typeIsArray) {
4384           out += '' + ($typeSchema.join(","));
4385         } else {
4386           out += '' + ($typeSchema);
4387         }
4388         out += '\' ';
4389       }
4390       if (it.opts.verbose) {
4391         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
4392       }
4393       out += ' } ';
4394     } else {
4395       out += ' {} ';
4396     }
4397     var __err = out;
4398     out = $$outStack.pop();
4399     if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
4400       if (it.async) {
4401         out += ' throw new ValidationError([' + (__err) + ']); ';
4402       } else {
4403         out += ' validate.errors = [' + (__err) + ']; return false; ';
4404       }
4405     } else {
4406       out += ' var err = ' + (__err) + ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
4407     }
4408     out += ' }';
4409   }
4410   if ($breakOnError) {
4411     out += ' ' + ($closingBraces2) + ' ';
4412   }
4413   if ($top) {
4414     if ($async) {
4415       out += ' if (errors === 0) return true;           ';
4416       out += ' else throw new ValidationError(vErrors); ';
4417     } else {
4418       out += ' validate.errors = vErrors; ';
4419       out += ' return errors === 0;       ';
4420     }
4421     out += ' });';
4422   } else {
4423     out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
4424   }
4425   out = it.util.cleanUpCode(out);
4426   if ($top && $breakOnError) {
4427     out = it.util.cleanUpVarErrors(out, $async);
4428   }
4430   function $shouldUseGroup($rulesGroup) {
4431     for (var i = 0; i < $rulesGroup.rules.length; i++)
4432       if ($shouldUseRule($rulesGroup.rules[i])) return true;
4433   }
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)));
4437   }
4438   return out;
4441 },{}],35:[function(require,module,exports){
4442 'use strict';
4444 var IDENTIFIER = /^[a-z_$][a-z0-9_$]*$/i;
4447  * Define custom keyword
4448  * @this  Ajv
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`.
4451  */
4452 module.exports = function addKeyword(keyword, definition) {
4453   /* eslint no-shadow: 0 */
4454   var self = this;
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');
4461   if (definition) {
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);
4467     } else {
4468       if (dataType) checkDataType(dataType);
4469       _addRule(keyword, dataType, definition);
4470     }
4471   }
4473   this.RULES.keywords[keyword] = true;
4474   this.RULES.all[keyword] = true;
4477   function _addRule(keyword, dataType, definition) {
4478     var ruleGroup;
4479     for (var i=0; i<self.RULES.length; i++) {
4480       var rg = self.RULES[i];
4481       if (rg.type == dataType) {
4482         ruleGroup = rg;
4483         break;
4484       }
4485     }
4487     if (!ruleGroup) {
4488       ruleGroup = { type: dataType, rules: [] };
4489       self.RULES.push(ruleGroup);
4490     }
4492     var rule = { keyword: keyword, definition: definition, custom: true };
4493     ruleGroup.rules.push(rule);
4494   }
4497   function checkDataType(dataType) {
4498     if (!self.RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
4499   }
4502 },{}],36:[function(require,module,exports){
4503 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",
4507     "definitions": {
4508         "schemaArray": {
4509             "type": "array",
4510             "minItems": 1,
4511             "items": { "$ref": "#" }
4512         },
4513         "positiveInteger": {
4514             "type": "integer",
4515             "minimum": 0
4516         },
4517         "positiveIntegerDefault0": {
4518             "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
4519         },
4520         "simpleTypes": {
4521             "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
4522         },
4523         "stringArray": {
4524             "type": "array",
4525             "items": { "type": "string" },
4526             "minItems": 1,
4527             "uniqueItems": true
4528         }
4529     },
4530     "type": "object",
4531     "properties": {
4532         "id": {
4533             "type": "string",
4534             "format": "uri"
4535         },
4536         "$schema": {
4537             "type": "string",
4538             "format": "uri"
4539         },
4540         "title": {
4541             "type": "string"
4542         },
4543         "description": {
4544             "type": "string"
4545         },
4546         "default": {},
4547         "multipleOf": {
4548             "type": "number",
4549             "minimum": 0,
4550             "exclusiveMinimum": true
4551         },
4552         "maximum": {
4553             "type": "number"
4554         },
4555         "exclusiveMaximum": {
4556             "type": "boolean",
4557             "default": false
4558         },
4559         "minimum": {
4560             "type": "number"
4561         },
4562         "exclusiveMinimum": {
4563             "type": "boolean",
4564             "default": false
4565         },
4566         "maxLength": { "$ref": "#/definitions/positiveInteger" },
4567         "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
4568         "pattern": {
4569             "type": "string",
4570             "format": "regex"
4571         },
4572         "additionalItems": {
4573             "anyOf": [
4574                 { "type": "boolean" },
4575                 { "$ref": "#" }
4576             ],
4577             "default": {}
4578         },
4579         "items": {
4580             "anyOf": [
4581                 { "$ref": "#" },
4582                 { "$ref": "#/definitions/schemaArray" }
4583             ],
4584             "default": {}
4585         },
4586         "maxItems": { "$ref": "#/definitions/positiveInteger" },
4587         "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
4588         "uniqueItems": {
4589             "type": "boolean",
4590             "default": false
4591         },
4592         "maxProperties": { "$ref": "#/definitions/positiveInteger" },
4593         "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
4594         "required": { "$ref": "#/definitions/stringArray" },
4595         "additionalProperties": {
4596             "anyOf": [
4597                 { "type": "boolean" },
4598                 { "$ref": "#" }
4599             ],
4600             "default": {}
4601         },
4602         "definitions": {
4603             "type": "object",
4604             "additionalProperties": { "$ref": "#" },
4605             "default": {}
4606         },
4607         "properties": {
4608             "type": "object",
4609             "additionalProperties": { "$ref": "#" },
4610             "default": {}
4611         },
4612         "patternProperties": {
4613             "type": "object",
4614             "additionalProperties": { "$ref": "#" },
4615             "default": {}
4616         },
4617         "dependencies": {
4618             "type": "object",
4619             "additionalProperties": {
4620                 "anyOf": [
4621                     { "$ref": "#" },
4622                     { "$ref": "#/definitions/stringArray" }
4623                 ]
4624             }
4625         },
4626         "enum": {
4627             "type": "array",
4628             "minItems": 1,
4629             "uniqueItems": true
4630         },
4631         "type": {
4632             "anyOf": [
4633                 { "$ref": "#/definitions/simpleTypes" },
4634                 {
4635                     "type": "array",
4636                     "items": { "$ref": "#/definitions/simpleTypes" },
4637                     "minItems": 1,
4638                     "uniqueItems": true
4639                 }
4640             ]
4641         },
4642         "allOf": { "$ref": "#/definitions/schemaArray" },
4643         "anyOf": { "$ref": "#/definitions/schemaArray" },
4644         "oneOf": { "$ref": "#/definitions/schemaArray" },
4645         "not": { "$ref": "#" }
4646     },
4647     "dependencies": {
4648         "exclusiveMaximum": [ "maximum" ],
4649         "exclusiveMinimum": [ "minimum" ]
4650     },
4651     "default": {}
4654 },{}],37:[function(require,module,exports){
4655 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)",
4659     "definitions": {
4660         "schemaArray": {
4661             "type": "array",
4662             "minItems": 1,
4663             "items": { "$ref": "#" }
4664         },
4665         "positiveInteger": {
4666             "type": "integer",
4667             "minimum": 0
4668         },
4669         "positiveIntegerDefault0": {
4670             "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
4671         },
4672         "simpleTypes": {
4673             "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
4674         },
4675         "stringArray": {
4676             "type": "array",
4677             "items": { "type": "string" },
4678             "minItems": 1,
4679             "uniqueItems": true
4680         },
4681         "$data": {
4682             "type": "object",
4683             "required": [ "$data" ],
4684             "properties": {
4685                 "$data": {
4686                     "type": "string",
4687                     "format": "relative-json-pointer"
4688                 }
4689             },
4690             "additionalProperties": false
4691         }
4692     },
4693     "type": "object",
4694     "properties": {
4695         "id": {
4696             "type": "string",
4697             "format": "uri"
4698         },
4699         "$schema": {
4700             "type": "string",
4701             "format": "uri"
4702         },
4703         "title": {
4704             "type": "string"
4705         },
4706         "description": {
4707             "type": "string"
4708         },
4709         "default": {},
4710         "multipleOf": {
4711             "anyOf": [
4712                 {
4713                     "type": "number",
4714                     "minimum": 0,
4715                     "exclusiveMinimum": true
4716                 },
4717                 { "$ref": "#/definitions/$data" }
4718             ]
4719         },
4720         "maximum": {
4721             "anyOf": [
4722                 { "type": "number" },
4723                 { "$ref": "#/definitions/$data" }
4724             ]
4725         },
4726         "exclusiveMaximum": {
4727             "anyOf": [
4728                 {
4729                     "type": "boolean",
4730                     "default": false
4731                 },
4732                 { "$ref": "#/definitions/$data" }
4733             ]
4734         },
4735         "minimum": {
4736             "anyOf": [
4737                 { "type": "number" },
4738                 { "$ref": "#/definitions/$data" }
4739             ]
4740         },
4741         "exclusiveMinimum": {
4742             "anyOf": [
4743                 {
4744                     "type": "boolean",
4745                     "default": false
4746                 },
4747                 { "$ref": "#/definitions/$data" }
4748             ]
4749         },
4750         "maxLength": {
4751             "anyOf": [
4752                 { "$ref": "#/definitions/positiveInteger" },
4753                 { "$ref": "#/definitions/$data" }
4754             ]
4755         },
4756         "minLength": {
4757             "anyOf": [
4758                 { "$ref": "#/definitions/positiveIntegerDefault0" },
4759                 { "$ref": "#/definitions/$data" }
4760             ]
4761         },
4762         "pattern": {
4763             "anyOf": [
4764                 {
4765                     "type": "string",
4766                     "format": "regex"
4767                 },
4768                 { "$ref": "#/definitions/$data" }
4769             ]
4770         },
4771         "additionalItems": {
4772             "anyOf": [
4773                 { "type": "boolean" },
4774                 { "$ref": "#" },
4775                 { "$ref": "#/definitions/$data" }
4776             ],
4777             "default": {}
4778         },
4779         "items": {
4780             "anyOf": [
4781                 { "$ref": "#" },
4782                 { "$ref": "#/definitions/schemaArray" }
4783             ],
4784             "default": {}
4785         },
4786         "maxItems": {
4787             "anyOf": [
4788                 { "$ref": "#/definitions/positiveInteger" },
4789                 { "$ref": "#/definitions/$data" }
4790             ]
4791         },
4792         "minItems": {
4793             "anyOf": [
4794                 { "$ref": "#/definitions/positiveIntegerDefault0" },
4795                 { "$ref": "#/definitions/$data" }
4796             ]
4797         },
4798         "uniqueItems": {
4799             "anyOf": [
4800                 {
4801                     "type": "boolean",
4802                     "default": false
4803                 },
4804                 { "$ref": "#/definitions/$data" }
4805             ]
4806         },
4807         "maxProperties": {
4808             "anyOf": [
4809                 { "$ref": "#/definitions/positiveInteger" },
4810                 { "$ref": "#/definitions/$data" }
4811             ]
4812         },
4813         "minProperties": {
4814             "anyOf": [
4815                 { "$ref": "#/definitions/positiveIntegerDefault0" },
4816                 { "$ref": "#/definitions/$data" }
4817             ]
4818         },
4819         "required": {
4820             "anyOf": [
4821                 { "$ref": "#/definitions/stringArray" },
4822                 { "$ref": "#/definitions/$data" }
4823             ]
4824         },
4825         "additionalProperties": {
4826             "anyOf": [
4827                 { "type": "boolean" },
4828                 { "$ref": "#" },
4829                 { "$ref": "#/definitions/$data" }
4830             ],
4831             "default": {}
4832         },
4833         "definitions": {
4834             "type": "object",
4835             "additionalProperties": { "$ref": "#" },
4836             "default": {}
4837         },
4838         "properties": {
4839             "type": "object",
4840             "additionalProperties": { "$ref": "#" },
4841             "default": {}
4842         },
4843         "patternProperties": {
4844             "type": "object",
4845             "additionalProperties": { "$ref": "#" },
4846             "default": {}
4847         },
4848         "dependencies": {
4849             "type": "object",
4850             "additionalProperties": {
4851                 "anyOf": [
4852                     { "$ref": "#" },
4853                     { "$ref": "#/definitions/stringArray" }
4854                 ]
4855             }
4856         },
4857         "enum": {
4858             "anyOf": [
4859                 {
4860                     "type": "array",
4861                     "minItems": 1,
4862                     "uniqueItems": true
4863                 },
4864                 { "$ref": "#/definitions/$data" }
4865             ]
4866         },
4867         "type": {
4868             "anyOf": [
4869                 { "$ref": "#/definitions/simpleTypes" },
4870                 {
4871                     "type": "array",
4872                     "items": { "$ref": "#/definitions/simpleTypes" },
4873                     "minItems": 1,
4874                     "uniqueItems": true
4875                 }
4876             ]
4877         },
4878         "allOf": { "$ref": "#/definitions/schemaArray" },
4879         "anyOf": { "$ref": "#/definitions/schemaArray" },
4880         "oneOf": { "$ref": "#/definitions/schemaArray" },
4881         "not": { "$ref": "#" },
4882         "format": {
4883             "anyOf": [
4884                 { "type": "string" },
4885                 { "$ref": "#/definitions/$data" }
4886             ]
4887         },
4888         "formatMaximum": {
4889             "anyOf": [
4890                 { "type": "string" },
4891                 { "$ref": "#/definitions/$data" }
4892             ]
4893         },
4894         "formatMinimum": {
4895             "anyOf": [
4896                 { "type": "string" },
4897                 { "$ref": "#/definitions/$data" }
4898             ]
4899         },
4900         "formatExclusiveMaximum": {
4901             "anyOf": [
4902                 {
4903                     "type": "boolean",
4904                     "default": false
4905                 },
4906                 { "$ref": "#/definitions/$data" }
4907             ]
4908         },
4909         "formatExclusiveMinimum": {
4910             "anyOf": [
4911                 {
4912                     "type": "boolean",
4913                     "default": false
4914                 },
4915                 { "$ref": "#/definitions/$data" }
4916             ]
4917         },
4918         "constant": {
4919             "anyOf": [
4920                 {},
4921                 { "$ref": "#/definitions/$data" }
4922             ]
4923         },
4924         "contains": { "$ref": "#" },
4925         "patternGroups": {
4926             "type": "object",
4927             "additionalProperties": {
4928                 "type": "object",
4929                 "required": [ "schema" ],
4930                 "properties": {
4931                     "maximum": {
4932                         "anyOf": [
4933                             { "$ref": "#/definitions/positiveInteger" },
4934                             { "$ref": "#/definitions/$data" }
4935                         ]
4936                     },
4937                     "minimum": {
4938                         "anyOf": [
4939                             { "$ref": "#/definitions/positiveIntegerDefault0" },
4940                             { "$ref": "#/definitions/$data" }
4941                         ]
4942                     },
4943                     "schema": { "$ref": "#" }
4944                 },
4945                 "additionalProperties": false
4946             },
4947             "default": {}
4948         },
4949         "switch": {
4950             "type": "array",
4951             "items": {
4952                 "required": [ "then" ],
4953                 "properties": {
4954                     "if": { "$ref": "#" },
4955                     "then": {
4956                         "anyOf": [
4957                             { "type": "boolean" },
4958                             { "$ref": "#" }
4959                         ]
4960                     },
4961                     "continue": { "type": "boolean" }
4962                 },
4963                 "additionalProperties": false,
4964                 "dependencies": {
4965                     "continue": [ "if" ]
4966                 }
4967             }
4968         }
4969     },
4970     "dependencies": {
4971         "exclusiveMaximum": [ "maximum" ],
4972         "exclusiveMinimum": [ "minimum" ],
4973         "formatMaximum": [ "format" ],
4974         "formatMinimum": [ "format" ],
4975         "formatExclusiveMaximum": [ "formatMaximum" ],
4976         "formatExclusiveMinimum": [ "formatMinimum" ]
4977     },
4978     "default": {}
4981 },{}],38:[function(require,module,exports){
4982 'use strict';
4984 var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
4986 module.exports = {
4987   enable: enableV5,
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')
4998   };
5000   if (ajv._opts.meta !== false) {
5001     var metaSchema = require('./refs/json-schema-v5.json');
5002     ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
5003   }
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) {
5018     var definition = {
5019       inline: inlineFunc || inlineFunctions[keyword],
5020       statements: true,
5021       errors: 'full'
5022     };
5023     if (types) definition.type = types;
5024     ajv.addKeyword(keyword, definition);
5025   }
5029 function containsMacro(schema) {
5030   return {
5031     not: { items: { not: schema } }
5032   };
5035 },{"./dotjs/_formatLimit":12,"./dotjs/constant":19,"./dotjs/patternRequired":28,"./dotjs/switch":32,"./refs/json-schema-v5.json":37}],39:[function(require,module,exports){
5036 (function (global){
5037 /*! https://mths.be/punycode v1.4.1 by @mathias */
5038 ;(function(root) {
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;
5046   if (
5047     freeGlobal.global === freeGlobal ||
5048     freeGlobal.window === freeGlobal ||
5049     freeGlobal.self === freeGlobal
5050   ) {
5051     root = freeGlobal;
5052   }
5054   /**
5055    * The `punycode` object.
5056    * @name punycode
5057    * @type Object
5058    */
5059   var punycode,
5061   /** Highest positive signed 32-bit float value */
5062   maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
5064   /** Bootstring parameters */
5065   base = 36,
5066   tMin = 1,
5067   tMax = 26,
5068   skew = 38,
5069   damp = 700,
5070   initialBias = 72,
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 */
5080   errors = {
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'
5084   },
5086   /** Convenience shortcuts */
5087   baseMinusTMin = base - tMin,
5088   floor = Math.floor,
5089   stringFromCharCode = String.fromCharCode,
5091   /** Temporary variable */
5092   key;
5094   /*--------------------------------------------------------------------------*/
5096   /**
5097    * A generic error utility function.
5098    * @private
5099    * @param {String} type The error type.
5100    * @returns {Error} Throws a `RangeError` with the applicable error message.
5101    */
5102   function error(type) {
5103     throw new RangeError(errors[type]);
5104   }
5106   /**
5107    * A generic `Array#map` utility function.
5108    * @private
5109    * @param {Array} array The array to iterate over.
5110    * @param {Function} callback The function that gets called for every array
5111    * item.
5112    * @returns {Array} A new array of values returned by the callback function.
5113    */
5114   function map(array, fn) {
5115     var length = array.length;
5116     var result = [];
5117     while (length--) {
5118       result[length] = fn(array[length]);
5119     }
5120     return result;
5121   }
5123   /**
5124    * A simple `Array#map`-like wrapper to work with domain name strings or email
5125    * addresses.
5126    * @private
5127    * @param {String} domain The domain name or email address.
5128    * @param {Function} callback The function that gets called for every
5129    * character.
5130    * @returns {Array} A new string of characters returned by the callback
5131    * function.
5132    */
5133   function mapDomain(string, fn) {
5134     var parts = string.split('@');
5135     var result = '';
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] + '@';
5140       string = parts[1];
5141     }
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;
5147   }
5149   /**
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,
5154    * matching UTF-16.
5155    * @see `punycode.ucs2.encode`
5156    * @see <https://mathiasbynens.be/notes/javascript-encoding>
5157    * @memberOf punycode.ucs2
5158    * @name decode
5159    * @param {String} string The Unicode input string (UCS-2).
5160    * @returns {Array} The new array of code points.
5161    */
5162   function ucs2decode(string) {
5163     var output = [],
5164         counter = 0,
5165         length = string.length,
5166         value,
5167         extra;
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);
5175         } else {
5176           // unmatched surrogate; only append this code unit, in case the next
5177           // code unit is the high surrogate of a surrogate pair
5178           output.push(value);
5179           counter--;
5180         }
5181       } else {
5182         output.push(value);
5183       }
5184     }
5185     return output;
5186   }
5188   /**
5189    * Creates a string based on an array of numeric code points.
5190    * @see `punycode.ucs2.decode`
5191    * @memberOf punycode.ucs2
5192    * @name encode
5193    * @param {Array} codePoints The array of numeric code points.
5194    * @returns {String} The new Unicode string (UCS-2).
5195    */
5196   function ucs2encode(array) {
5197     return map(array, function(value) {
5198       var output = '';
5199       if (value > 0xFFFF) {
5200         value -= 0x10000;
5201         output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
5202         value = 0xDC00 | value & 0x3FF;
5203       }
5204       output += stringFromCharCode(value);
5205       return output;
5206     }).join('');
5207   }
5209   /**
5210    * Converts a basic code point into a digit/integer.
5211    * @see `digitToBasic()`
5212    * @private
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.
5217    */
5218   function basicToDigit(codePoint) {
5219     if (codePoint - 48 < 10) {
5220       return codePoint - 22;
5221     }
5222     if (codePoint - 65 < 26) {
5223       return codePoint - 65;
5224     }
5225     if (codePoint - 97 < 26) {
5226       return codePoint - 97;
5227     }
5228     return base;
5229   }
5231   /**
5232    * Converts a digit/integer into a basic code point.
5233    * @see `basicToDigit()`
5234    * @private
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.
5241    */
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);
5246   }
5248   /**
5249    * Bias adaptation function as per section 3.4 of RFC 3492.
5250    * https://tools.ietf.org/html/rfc3492#section-3.4
5251    * @private
5252    */
5253   function adapt(delta, numPoints, firstTime) {
5254     var k = 0;
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);
5259     }
5260     return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
5261   }
5263   /**
5264    * Converts a Punycode string of ASCII-only symbols to a string of Unicode
5265    * symbols.
5266    * @memberOf punycode
5267    * @param {String} input The Punycode string of ASCII-only symbols.
5268    * @returns {String} The resulting string of Unicode symbols.
5269    */
5270   function decode(input) {
5271     // Don't use UCS-2
5272     var output = [],
5273         inputLength = input.length,
5274         out,
5275         i = 0,
5276         n = initialN,
5277         bias = initialBias,
5278         basic,
5279         j,
5280         index,
5281         oldi,
5282         w,
5283         k,
5284         digit,
5285         t,
5286         /** Cached calculation results */
5287         baseMinusT;
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);
5294     if (basic < 0) {
5295       basic = 0;
5296     }
5298     for (j = 0; j < basic; ++j) {
5299       // if it's not a basic code point
5300       if (input.charCodeAt(j) >= 0x80) {
5301         error('not-basic');
5302       }
5303       output.push(input.charCodeAt(j));
5304     }
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');
5320         }
5322         digit = basicToDigit(input.charCodeAt(index++));
5324         if (digit >= base || digit > floor((maxInt - i) / w)) {
5325           error('overflow');
5326         }
5328         i += digit * w;
5329         t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
5331         if (digit < t) {
5332           break;
5333         }
5335         baseMinusT = base - t;
5336         if (w > floor(maxInt / baseMinusT)) {
5337           error('overflow');
5338         }
5340         w *= baseMinusT;
5342       }
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) {
5350         error('overflow');
5351       }
5353       n += floor(i / out);
5354       i %= out;
5356       // Insert `n` at position `i` of the output
5357       output.splice(i++, 0, n);
5359     }
5361     return ucs2encode(output);
5362   }
5364   /**
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.
5370    */
5371   function encode(input) {
5372     var n,
5373         delta,
5374         handledCPCount,
5375         basicLength,
5376         bias,
5377         j,
5378         m,
5379         q,
5380         k,
5381         t,
5382         currentValue,
5383         output = [],
5384         /** `inputLength` will hold the number of code points in `input`. */
5385         inputLength,
5386         /** Cached calculation results */
5387         handledCPCountPlusOne,
5388         baseMinusT,
5389         qMinusT;
5391     // Convert the input in UCS-2 to Unicode
5392     input = ucs2decode(input);
5394     // Cache the length
5395     inputLength = input.length;
5397     // Initialize the state
5398     n = initialN;
5399     delta = 0;
5400     bias = initialBias;
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));
5407       }
5408     }
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
5416     if (basicLength) {
5417       output.push(delimiter);
5418     }
5420     // Main encoding loop:
5421     while (handledCPCount < inputLength) {
5423       // All non-basic code points < n have been handled already. Find the next
5424       // larger one:
5425       for (m = maxInt, j = 0; j < inputLength; ++j) {
5426         currentValue = input[j];
5427         if (currentValue >= n && currentValue < m) {
5428           m = currentValue;
5429         }
5430       }
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)) {
5436         error('overflow');
5437       }
5439       delta += (m - n) * handledCPCountPlusOne;
5440       n = m;
5442       for (j = 0; j < inputLength; ++j) {
5443         currentValue = input[j];
5445         if (currentValue < n && ++delta > maxInt) {
5446           error('overflow');
5447         }
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);
5453             if (q < t) {
5454               break;
5455             }
5456             qMinusT = q - t;
5457             baseMinusT = base - t;
5458             output.push(
5459               stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
5460             );
5461             q = floor(qMinusT / baseMinusT);
5462           }
5464           output.push(stringFromCharCode(digitToBasic(q, 0)));
5465           bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
5466           delta = 0;
5467           ++handledCPCount;
5468         }
5469       }
5471       ++delta;
5472       ++n;
5474     }
5475     return output.join('');
5476   }
5478   /**
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
5487    * string.
5488    */
5489   function toUnicode(input) {
5490     return mapDomain(input, function(string) {
5491       return regexPunycode.test(string)
5492         ? decode(string.slice(4).toLowerCase())
5493         : string;
5494     });
5495   }
5497   /**
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
5501    * ASCII.
5502    * @memberOf punycode
5503    * @param {String} input The domain name or email address to convert, as a
5504    * Unicode string.
5505    * @returns {String} The Punycode representation of the given domain name or
5506    * email address.
5507    */
5508   function toASCII(input) {
5509     return mapDomain(input, function(string) {
5510       return regexNonASCII.test(string)
5511         ? 'xn--' + encode(string)
5512         : string;
5513     });
5514   }
5516   /*--------------------------------------------------------------------------*/
5518   /** Define the public API */
5519   punycode = {
5520     /**
5521      * A string representing the current Punycode.js version number.
5522      * @memberOf punycode
5523      * @type String
5524      */
5525     'version': '1.4.1',
5526     /**
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
5531      * @type Object
5532      */
5533     'ucs2': {
5534       'decode': ucs2decode,
5535       'encode': ucs2encode
5536     },
5537     'decode': decode,
5538     'encode': encode,
5539     'toASCII': toASCII,
5540     'toUnicode': toUnicode
5541   };
5543   /** Expose `punycode` */
5544   // Some AMD build optimizers, like r.js, check for specific condition patterns
5545   // like the following:
5546   if (
5547     typeof define == 'function' &&
5548     typeof define.amd == 'object' &&
5549     define.amd
5550   ) {
5551     define('punycode', function() {
5552       return punycode;
5553     });
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;
5558     } else {
5559       // in Narwhal or RingoJS v0.7.0-
5560       for (key in punycode) {
5561         punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
5562       }
5563     }
5564   } else {
5565     // in Rhino or a web browser
5566     root.punycode = punycode;
5567   }
5569 }(this));
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.
5594 'use strict';
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) {
5604   sep = sep || '&';
5605   eq = eq || '=';
5606   var obj = {};
5608   if (typeof qs !== 'string' || qs.length === 0) {
5609     return obj;
5610   }
5612   var regexp = /\+/g;
5613   qs = qs.split(sep);
5615   var maxKeys = 1000;
5616   if (options && typeof options.maxKeys === 'number') {
5617     maxKeys = options.maxKeys;
5618   }
5620   var len = qs.length;
5621   // maxKeys <= 0 means that we should not limit keys count
5622   if (maxKeys > 0 && len > maxKeys) {
5623     len = maxKeys;
5624   }
5626   for (var i = 0; i < len; ++i) {
5627     var x = qs[i].replace(regexp, '%20'),
5628         idx = x.indexOf(eq),
5629         kstr, vstr, k, v;
5631     if (idx >= 0) {
5632       kstr = x.substr(0, idx);
5633       vstr = x.substr(idx + 1);
5634     } else {
5635       kstr = x;
5636       vstr = '';
5637     }
5639     k = decodeURIComponent(kstr);
5640     v = decodeURIComponent(vstr);
5642     if (!hasOwnProperty(obj, k)) {
5643       obj[k] = v;
5644     } else if (isArray(obj[k])) {
5645       obj[k].push(v);
5646     } else {
5647       obj[k] = [obj[k], v];
5648     }
5649   }
5651   return obj;
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.
5680 'use strict';
5682 var stringifyPrimitive = function(v) {
5683   switch (typeof v) {
5684     case 'string':
5685       return v;
5687     case 'boolean':
5688       return v ? 'true' : 'false';
5690     case 'number':
5691       return isFinite(v) ? v : '';
5693     default:
5694       return '';
5695   }
5698 module.exports = function(obj, sep, eq, name) {
5699   sep = sep || '&';
5700   eq = eq || '=';
5701   if (obj === null) {
5702     obj = undefined;
5703   }
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));
5711         }).join(sep);
5712       } else {
5713         return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
5714       }
5715     }).join(sep);
5717   }
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);
5730   var res = [];
5731   for (var i = 0; i < xs.length; i++) {
5732     res.push(f(xs[i], i));
5733   }
5734   return res;
5737 var objectKeys = Object.keys || function (obj) {
5738   var res = [];
5739   for (var key in obj) {
5740     if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
5741   }
5742   return res;
5745 },{}],42:[function(require,module,exports){
5746 'use strict';
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.
5773 'use strict';
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;
5783 exports.Url = Url;
5785 function Url() {
5786   this.protocol = null;
5787   this.slashes = null;
5788   this.auth = null;
5789   this.host = null;
5790   this.port = null;
5791   this.hostname = null;
5792   this.hash = null;
5793   this.search = null;
5794   this.query = null;
5795   this.pathname = null;
5796   this.path = null;
5797   this.href = 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
5822     // them.
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.
5829     unsafeProtocol = {
5830       'javascript': true,
5831       'javascript:': true
5832     },
5833     // protocols that never have a hostname.
5834     hostlessProtocol = {
5835       'javascript': true,
5836       'javascript:': true
5837     },
5838     // protocols that always contain a // bit.
5839     slashedProtocol = {
5840       'http': true,
5841       'https': true,
5842       'ftp': true,
5843       'gopher': true,
5844       'file': true,
5845       'http:': true,
5846       'https:': true,
5847       'ftp:': true,
5848       'gopher:': true,
5849       'file:': true
5850     },
5851     querystring = require('querystring');
5853 function urlParse(url, parseQueryString, slashesDenoteHost) {
5854   if (url && util.isObject(url) && url instanceof Url) return url;
5856   var u = new Url;
5857   u.parse(url, parseQueryString, slashesDenoteHost);
5858   return u;
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);
5864   }
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('?'),
5870       splitter =
5871           (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
5872       uSplit = url.split(splitter),
5873       slashRegex = /\\/g;
5874   uSplit[0] = uSplit[0].replace(slashRegex, '/');
5875   url = uSplit.join(splitter);
5877   var rest = url;
5879   // trim before proceeding.
5880   // This is to support parse stuff like "  http://foo.com  \n"
5881   rest = rest.trim();
5883   if (!slashesDenoteHost && url.split('#').length === 1) {
5884     // Try fast path regexp
5885     var simplePath = simplePathPattern.exec(rest);
5886     if (simplePath) {
5887       this.path = rest;
5888       this.href = 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));
5894         } else {
5895           this.query = this.search.substr(1);
5896         }
5897       } else if (parseQueryString) {
5898         this.search = '';
5899         this.query = {};
5900       }
5901       return this;
5902     }
5903   }
5905   var proto = protocolPattern.exec(rest);
5906   if (proto) {
5907     proto = proto[0];
5908     var lowerProto = proto.toLowerCase();
5909     this.protocol = lowerProto;
5910     rest = rest.substr(proto.length);
5911   }
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;
5922     }
5923   }
5925   if (!hostlessProtocol[proto] &&
5926       (slashes || (proto && !slashedProtocol[proto]))) {
5928     // there's a hostname.
5929     // the first instance of /, ?, ;, or # ends the host.
5930     //
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.
5935     //
5936     // ex:
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
5944     var hostEnd = -1;
5945     for (var i = 0; i < hostEndingChars.length; i++) {
5946       var hec = rest.indexOf(hostEndingChars[i]);
5947       if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
5948         hostEnd = hec;
5949     }
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.
5953     var auth, atSign;
5954     if (hostEnd === -1) {
5955       // atSign can be anywhere.
5956       atSign = rest.lastIndexOf('@');
5957     } else {
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);
5961     }
5963     // Now we have a portion which is definitely the auth.
5964     // Pull that off.
5965     if (atSign !== -1) {
5966       auth = rest.slice(0, atSign);
5967       rest = rest.slice(atSign + 1);
5968       this.auth = decodeURIComponent(auth);
5969     }
5971     // the host is the remaining to the left of the first non-host char
5972     hostEnd = -1;
5973     for (var i = 0; i < nonHostChars.length; i++) {
5974       var hec = rest.indexOf(nonHostChars[i]);
5975       if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
5976         hostEnd = hec;
5977     }
5978     // if we still have not hit it, then the entire thing is a host.
5979     if (hostEnd === -1)
5980       hostEnd = rest.length;
5982     this.host = rest.slice(0, hostEnd);
5983     rest = rest.slice(hostEnd);
5985     // pull out port.
5986     this.parseHost();
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)) {
6004           var newpart = '';
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
6010               newpart += 'x';
6011             } else {
6012               newpart += part[j];
6013             }
6014           }
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);
6020             if (bit) {
6021               validParts.push(bit[1]);
6022               notHost.unshift(bit[2]);
6023             }
6024             if (notHost.length) {
6025               rest = '/' + notHost.join('.') + rest;
6026             }
6027             this.hostname = validParts.join('.');
6028             break;
6029           }
6030         }
6031       }
6032     }
6034     if (this.hostname.length > hostnameMaxLen) {
6035       this.hostname = '';
6036     } else {
6037       // hostnames are always lower case.
6038       this.hostname = this.hostname.toLowerCase();
6039     }
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);
6047     }
6049     var p = this.port ? ':' + this.port : '';
6050     var h = this.hostname || '';
6051     this.host = h + p;
6052     this.href += this.host;
6054     // strip [ and ] from the hostname
6055     // the host field still retains them, though
6056     if (ipv6Hostname) {
6057       this.hostname = this.hostname.substr(1, this.hostname.length - 2);
6058       if (rest[0] !== '/') {
6059         rest = '/' + rest;
6060       }
6061     }
6062   }
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
6070     // need to be.
6071     for (var i = 0, l = autoEscape.length; i < l; i++) {
6072       var ae = autoEscape[i];
6073       if (rest.indexOf(ae) === -1)
6074         continue;
6075       var esc = encodeURIComponent(ae);
6076       if (esc === ae) {
6077         esc = escape(ae);
6078       }
6079       rest = rest.split(ae).join(esc);
6080     }
6081   }
6084   // chop off from the tail first.
6085   var hash = rest.indexOf('#');
6086   if (hash !== -1) {
6087     // got a fragment string.
6088     this.hash = rest.substr(hash);
6089     rest = rest.slice(0, hash);
6090   }
6091   var qm = rest.indexOf('?');
6092   if (qm !== -1) {
6093     this.search = rest.substr(qm);
6094     this.query = rest.substr(qm + 1);
6095     if (parseQueryString) {
6096       this.query = querystring.parse(this.query);
6097     }
6098     rest = rest.slice(0, qm);
6099   } else if (parseQueryString) {
6100     // no query string, but parseQueryString still requested
6101     this.search = '';
6102     this.query = {};
6103   }
6104   if (rest) this.pathname = rest;
6105   if (slashedProtocol[lowerProto] &&
6106       this.hostname && !this.pathname) {
6107     this.pathname = '/';
6108   }
6110   //to support http.request
6111   if (this.pathname || this.search) {
6112     var p = this.pathname || '';
6113     var s = this.search || '';
6114     this.path = p + s;
6115   }
6117   // finally, reconstruct the href based on what has been validated.
6118   this.href = this.format();
6119   return this;
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 || '';
6135   if (auth) {
6136     auth = encodeURIComponent(auth);
6137     auth = auth.replace(/%3A/i, ':');
6138     auth += '@';
6139   }
6141   var protocol = this.protocol || '',
6142       pathname = this.pathname || '',
6143       hash = this.hash || '',
6144       host = false,
6145       query = '';
6147   if (this.host) {
6148     host = auth + this.host;
6149   } else if (this.hostname) {
6150     host = auth + (this.hostname.indexOf(':') === -1 ?
6151         this.hostname :
6152         '[' + this.hostname + ']');
6153     if (this.port) {
6154       host += ':' + this.port;
6155     }
6156   }
6158   if (this.query &&
6159       util.isObject(this.query) &&
6160       Object.keys(this.query).length) {
6161     query = querystring.stringify(this.query);
6162   }
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.
6170   if (this.slashes ||
6171       (!protocol || slashedProtocol[protocol]) && host !== false) {
6172     host = '//' + (host || '');
6173     if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
6174   } else if (!host) {
6175     host = '';
6176   }
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);
6183   });
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);
6206     relative = rel;
6207   }
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];
6214   }
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();
6223     return result;
6224   }
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];
6234     }
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 = '/';
6240     }
6242     result.href = result.format();
6243     return result;
6244   }
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++) {
6258         var k = keys[v];
6259         result[k] = relative[k];
6260       }
6261       result.href = result.format();
6262       return result;
6263     }
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('/');
6274     } else {
6275       result.pathname = relative.pathname;
6276     }
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;
6288     }
6289     result.slashes = result.slashes || relative.slashes;
6290     result.href = result.format();
6291     return result;
6292   }
6294   var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
6295       isRelAbs = (
6296           relative.host ||
6297           relative.pathname && relative.pathname.charAt(0) === '/'
6298       ),
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.
6311   if (psychotic) {
6312     result.hostname = '';
6313     result.port = null;
6314     if (result.host) {
6315       if (srcPath[0] === '') srcPath[0] = result.host;
6316       else srcPath.unshift(result.host);
6317     }
6318     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);
6325       }
6326       relative.host = null;
6327     }
6328     mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
6329   }
6331   if (isRelAbs) {
6332     // it's absolute.
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;
6339     srcPath = relPath;
6340     // fall through to the dot-handling below.
6341   } else if (relPath.length) {
6342     // it's relative
6343     // throw away the existing file, and take the new path instead.
6344     if (!srcPath) srcPath = [];
6345     srcPath.pop();
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
6353     if (psychotic) {
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;
6360       if (authInHost) {
6361         result.auth = authInHost.shift();
6362         result.host = result.hostname = authInHost.shift();
6363       }
6364     }
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 : '');
6371     }
6372     result.href = result.format();
6373     return result;
6374   }
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;
6383     } else {
6384       result.path = null;
6385     }
6386     result.href = result.format();
6387     return result;
6388   }
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
6400   var up = 0;
6401   for (var i = srcPath.length; i >= 0; i--) {
6402     last = srcPath[i];
6403     if (last === '.') {
6404       srcPath.splice(i, 1);
6405     } else if (last === '..') {
6406       srcPath.splice(i, 1);
6407       up++;
6408     } else if (up) {
6409       srcPath.splice(i, 1);
6410       up--;
6411     }
6412   }
6414   // if the path is allowed to go above the root, restore leading ..s
6415   if (!mustEndAbs && !removeAllDots) {
6416     for (; up--; up) {
6417       srcPath.unshift('..');
6418     }
6419   }
6421   if (mustEndAbs && srcPath[0] !== '' &&
6422       (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
6423     srcPath.unshift('');
6424   }
6426   if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
6427     srcPath.push('');
6428   }
6430   var isAbsolute = srcPath[0] === '' ||
6431       (srcPath[0] && srcPath[0].charAt(0) === '/');
6433   // put the host back
6434   if (psychotic) {
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;
6442     if (authInHost) {
6443       result.auth = authInHost.shift();
6444       result.host = result.hostname = authInHost.shift();
6445     }
6446   }
6448   mustEndAbs = mustEndAbs || (result.host && srcPath.length);
6450   if (mustEndAbs && !isAbsolute) {
6451     srcPath.unshift('');
6452   }
6454   if (!srcPath.length) {
6455     result.pathname = null;
6456     result.path = null;
6457   } else {
6458     result.pathname = srcPath.join('/');
6459   }
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 : '');
6465   }
6466   result.auth = relative.auth || result.auth;
6467   result.slashes = result.slashes || relative.slashes;
6468   result.href = result.format();
6469   return result;
6472 Url.prototype.parseHost = function() {
6473   var host = this.host;
6474   var port = portPattern.exec(host);
6475   if (port) {
6476     port = port[0];
6477     if (port !== ':') {
6478       this.port = port.substr(1);
6479     }
6480     host = host.substr(0, host.length - port.length);
6481   }
6482   if (host) this.hostname = host;
6485 },{"./util":44,"punycode":39,"querystring":42}],44:[function(require,module,exports){
6486 'use strict';
6488 module.exports = {
6489   isString: function(arg) {
6490     return typeof(arg) === 'string';
6491   },
6492   isObject: function(arg) {
6493     return typeof(arg) === 'object' && arg !== null;
6494   },
6495   isNull: function(arg) {
6496     return arg === null;
6497   },
6498   isNullOrUndefined: function(arg) {
6499     return arg == null;
6500   }
6503 },{}],45:[function(require,module,exports){
6506  * slice() reference.
6507  */
6509 var slice = Array.prototype.slice;
6512  * Expose `co`.
6513  */
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}
6526  * @api public
6527  */
6529 co.wrap = function (fn) {
6530   createPromise.__generatorFunction__ = fn;
6531   return createPromise;
6532   function createPromise() {
6533     return co.call(this, fn.apply(this, arguments));
6534   }
6538  * Execute the generator function or a generator
6539  * and return a promise.
6541  * @param {Function} fn
6542  * @return {Promise}
6543  * @api public
6544  */
6546 function co(gen) {
6547   var ctx = this;
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);
6557     onFulfilled();
6559     /**
6560      * @param {Mixed} res
6561      * @return {Promise}
6562      * @api private
6563      */
6565     function onFulfilled(res) {
6566       var ret;
6567       try {
6568         ret = gen.next(res);
6569       } catch (e) {
6570         return reject(e);
6571       }
6572       next(ret);
6573     }
6575     /**
6576      * @param {Error} err
6577      * @return {Promise}
6578      * @api private
6579      */
6581     function onRejected(err) {
6582       var ret;
6583       try {
6584         ret = gen.throw(err);
6585       } catch (e) {
6586         return reject(e);
6587       }
6588       next(ret);
6589     }
6591     /**
6592      * Get the next value in the generator,
6593      * return a promise.
6594      *
6595      * @param {Object} ret
6596      * @return {Promise}
6597      * @api private
6598      */
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) + '"'));
6606     }
6607   });
6611  * Convert a `yield`ed value into a promise.
6613  * @param {Mixed} obj
6614  * @return {Promise}
6615  * @api private
6616  */
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);
6625   return obj;
6629  * Convert a thunk to a promise.
6631  * @param {Function}
6632  * @return {Promise}
6633  * @api private
6634  */
6636 function thunkToPromise(fn) {
6637   var ctx = this;
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);
6642       resolve(res);
6643     });
6644   });
6648  * Convert an array of "yieldables" to a promise.
6649  * Uses `Promise.all()` internally.
6651  * @param {Array} obj
6652  * @return {Promise}
6653  * @api private
6654  */
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
6665  * @return {Promise}
6666  * @api private
6667  */
6669 function objectToPromise(obj){
6670   var results = new obj.constructor();
6671   var keys = Object.keys(obj);
6672   var promises = [];
6673   for (var i = 0; i < keys.length; i++) {
6674     var key = keys[i];
6675     var promise = toPromise.call(this, obj[key]);
6676     if (promise && isPromise(promise)) defer(promise, key);
6677     else results[key] = obj[key];
6678   }
6679   return Promise.all(promises).then(function () {
6680     return results;
6681   });
6683   function defer(promise, key) {
6684     // predefine the key in the result
6685     results[key] = undefined;
6686     promises.push(promise.then(function (res) {
6687       results[key] = res;
6688     }));
6689   }
6693  * Check if `obj` is a promise.
6695  * @param {Object} obj
6696  * @return {Boolean}
6697  * @api private
6698  */
6700 function isPromise(obj) {
6701   return 'function' == typeof obj.then;
6705  * Check if `obj` is a generator.
6707  * @param {Mixed} obj
6708  * @return {Boolean}
6709  * @api private
6710  */
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
6720  * @return {Boolean}
6721  * @api private
6722  */
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
6734  * @return {Boolean}
6735  * @api private
6736  */
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);
6759             };
6760         };
6761     })(opts.cmp);
6763     var seen = [];
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();
6770         }
6772         node = replacer.call(parent, key, node);
6774         if (node === undefined) {
6775             return;
6776         }
6777         if (typeof node !== 'object' || node === null) {
6778             return json.stringify(node);
6779         }
6780         if (isArray(node)) {
6781             var out = [];
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);
6785             }
6786             return '[' + out.join(',') + indent + ']';
6787         }
6788         else {
6789             if (seen.indexOf(node) !== -1) {
6790                 if (cycles) return json.stringify('__cycle__');
6791                 throw new TypeError('Converting circular structure to JSON');
6792             }
6793             else seen.push(node);
6795             var keys = objectKeys(node).sort(cmp && cmp(node));
6796             var out = [];
6797             for (var i = 0; i < keys.length; i++) {
6798                 var key = keys[i];
6799                 var value = stringify(node, key, node[key], level+1);
6801                 if(!value) continue;
6803                 var keyValue = json.stringify(key)
6804                     + colonSeparator
6805                     + value;
6806                 ;
6807                 out.push(indent + space + keyValue);
6808             }
6809             seen.splice(seen.indexOf(node), 1);
6810             return '{' + out.join(',') + indent + '}';
6811         }
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 };
6821     var keys = [];
6822     for (var key in obj) {
6823         if (has.call(obj, key)) keys.push(key);
6824     }
6825     return keys;
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
6835     escapee = {
6836         '"':  '"',
6837         '\\': '\\',
6838         '/':  '/',
6839         b:    '\b',
6840         f:    '\f',
6841         n:    '\n',
6842         r:    '\r',
6843         t:    '\t'
6844     },
6845     text,
6847     error = function (m) {
6848         // Call error when something is wrong.
6849         throw {
6850             name:    'SyntaxError',
6851             message: m,
6852             at:      at,
6853             text:    text
6854         };
6855     },
6856     
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 + "'");
6861         }
6862         
6863         // Get the next character. When there are no more characters,
6864         // return the empty string.
6865         
6866         ch = text.charAt(at);
6867         at += 1;
6868         return ch;
6869     },
6870     
6871     number = function () {
6872         // Parse a number value.
6873         var number,
6874             string = '';
6875         
6876         if (ch === '-') {
6877             string = '-';
6878             next('-');
6879         }
6880         while (ch >= '0' && ch <= '9') {
6881             string += ch;
6882             next();
6883         }
6884         if (ch === '.') {
6885             string += '.';
6886             while (next() && ch >= '0' && ch <= '9') {
6887                 string += ch;
6888             }
6889         }
6890         if (ch === 'e' || ch === 'E') {
6891             string += ch;
6892             next();
6893             if (ch === '-' || ch === '+') {
6894                 string += ch;
6895                 next();
6896             }
6897             while (ch >= '0' && ch <= '9') {
6898                 string += ch;
6899                 next();
6900             }
6901         }
6902         number = +string;
6903         if (!isFinite(number)) {
6904             error("Bad number");
6905         } else {
6906             return number;
6907         }
6908     },
6909     
6910     string = function () {
6911         // Parse a string value.
6912         var hex,
6913             i,
6914             string = '',
6915             uffff;
6916         
6917         // When parsing for string values, we must look for " and \ characters.
6918         if (ch === '"') {
6919             while (next()) {
6920                 if (ch === '"') {
6921                     next();
6922                     return string;
6923                 } else if (ch === '\\') {
6924                     next();
6925                     if (ch === 'u') {
6926                         uffff = 0;
6927                         for (i = 0; i < 4; i += 1) {
6928                             hex = parseInt(next(), 16);
6929                             if (!isFinite(hex)) {
6930                                 break;
6931                             }
6932                             uffff = uffff * 16 + hex;
6933                         }
6934                         string += String.fromCharCode(uffff);
6935                     } else if (typeof escapee[ch] === 'string') {
6936                         string += escapee[ch];
6937                     } else {
6938                         break;
6939                     }
6940                 } else {
6941                     string += ch;
6942                 }
6943             }
6944         }
6945         error("Bad string");
6946     },
6948     white = function () {
6950 // Skip whitespace.
6952         while (ch && ch <= ' ') {
6953             next();
6954         }
6955     },
6957     word = function () {
6959 // true, false, or null.
6961         switch (ch) {
6962         case 't':
6963             next('t');
6964             next('r');
6965             next('u');
6966             next('e');
6967             return true;
6968         case 'f':
6969             next('f');
6970             next('a');
6971             next('l');
6972             next('s');
6973             next('e');
6974             return false;
6975         case 'n':
6976             next('n');
6977             next('u');
6978             next('l');
6979             next('l');
6980             return null;
6981         }
6982         error("Unexpected '" + ch + "'");
6983     },
6985     value,  // Place holder for the value function.
6987     array = function () {
6989 // Parse an array value.
6991         var array = [];
6993         if (ch === '[') {
6994             next('[');
6995             white();
6996             if (ch === ']') {
6997                 next(']');
6998                 return array;   // empty array
6999             }
7000             while (ch) {
7001                 array.push(value());
7002                 white();
7003                 if (ch === ']') {
7004                     next(']');
7005                     return array;
7006                 }
7007                 next(',');
7008                 white();
7009             }
7010         }
7011         error("Bad array");
7012     },
7014     object = function () {
7016 // Parse an object value.
7018         var key,
7019             object = {};
7021         if (ch === '{') {
7022             next('{');
7023             white();
7024             if (ch === '}') {
7025                 next('}');
7026                 return object;   // empty object
7027             }
7028             while (ch) {
7029                 key = string();
7030                 white();
7031                 next(':');
7032                 if (Object.hasOwnProperty.call(object, key)) {
7033                     error('Duplicate key "' + key + '"');
7034                 }
7035                 object[key] = value();
7036                 white();
7037                 if (ch === '}') {
7038                     next('}');
7039                     return object;
7040                 }
7041                 next(',');
7042                 white();
7043             }
7044         }
7045         error("Bad object");
7046     };
7048 value = function () {
7050 // Parse a JSON value. It could be an object, an array, a string, a number,
7051 // or a word.
7053     white();
7054     switch (ch) {
7055     case '{':
7056         return object();
7057     case '[':
7058         return array();
7059     case '"':
7060         return string();
7061     case '-':
7062         return number();
7063     default:
7064         return ch >= '0' && ch <= '9' ? number() : word();
7065     }
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) {
7072     var result;
7073     
7074     text = source;
7075     at = 0;
7076     ch = ' ';
7077     result = value();
7078     white();
7079     if (ch) {
7080         error("Syntax error");
7081     }
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
7087     // result.
7089     return typeof reviver === 'function' ? (function walk(holder, key) {
7090         var k, v, value = holder[key];
7091         if (value && typeof value === 'object') {
7092             for (k in value) {
7093                 if (Object.prototype.hasOwnProperty.call(value, k)) {
7094                     v = walk(value, k);
7095                     if (v !== undefined) {
7096                         value[k] = v;
7097                     } else {
7098                         delete value[k];
7099                     }
7100                 }
7101             }
7102         }
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,
7110     gap,
7111     indent,
7112     meta = {    // table of character substitutions
7113         '\b': '\\b',
7114         '\t': '\\t',
7115         '\n': '\\n',
7116         '\f': '\\f',
7117         '\r': '\\r',
7118         '"' : '\\"',
7119         '\\': '\\\\'
7120     },
7121     rep;
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
7127     // sequences.
7128     
7129     escapable.lastIndex = 0;
7130     return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
7131         var c = meta[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.
7142         length,
7143         mind = gap,
7144         partial,
7145         value = holder[key];
7146     
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);
7151     }
7152     
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);
7157     }
7158     
7159     // What happens next depends on the value's type.
7160     switch (typeof value) {
7161         case 'string':
7162             return quote(value);
7163         
7164         case 'number':
7165             // JSON numbers must be finite. Encode non-finite numbers as null.
7166             return isFinite(value) ? String(value) : 'null';
7167         
7168         case 'boolean':
7169         case '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);
7174             
7175         case 'object':
7176             if (!value) return 'null';
7177             gap += indent;
7178             partial = [];
7179             
7180             // Array.isArray
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';
7185                 }
7186                 
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(',') + ']';
7192                 gap = mind;
7193                 return v;
7194             }
7195             
7196             // If the replacer is an array, use it to select the members to be
7197             // stringified.
7198             if (rep && typeof rep === 'object') {
7199                 length = rep.length;
7200                 for (i = 0; i < length; i += 1) {
7201                     k = rep[i];
7202                     if (typeof k === 'string') {
7203                         v = str(k, value);
7204                         if (v) {
7205                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
7206                         }
7207                     }
7208                 }
7209             }
7210             else {
7211                 // Otherwise, iterate through all of the keys in the object.
7212                 for (k in value) {
7213                     if (Object.prototype.hasOwnProperty.call(value, k)) {
7214                         v = str(k, value);
7215                         if (v) {
7216                             partial.push(quote(k) + (gap ? ': ' : ':') + v);
7217                         }
7218                     }
7219                 }
7220             }
7221             
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(',') + '}';
7228         gap = mind;
7229         return v;
7230     }
7233 module.exports = function (value, replacer, space) {
7234     var i;
7235     gap = '';
7236     indent = '';
7237     
7238     // If the space parameter is a number, make an indent string containing that
7239     // many spaces.
7240     if (typeof space === 'number') {
7241         for (i = 0; i < space; i += 1) {
7242             indent += ' ';
7243         }
7244     }
7245     // If the space parameter is a string, it will be used as the indent string.
7246     else if (typeof space === 'string') {
7247         indent = space;
7248     }
7250     // If there is a replacer, it must be a function or an array.
7251     // Otherwise, throw an error.
7252     rep = replacer;
7253     if (replacer && typeof replacer !== 'function'
7254     && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
7255         throw new Error('JSON.stringify');
7256     }
7257     
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){
7264 'use strict';
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
7297  */
7298 function Ajv(opts) {
7299   if (!(this instanceof Ajv)) return new Ajv(opts);
7300   var self = this;
7302   opts = this._opts = util.copy(opts) || {};
7303   this._schemas = {};
7304   this._refs = {};
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();
7338   /**
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`).
7344    */
7345   function validate(schemaKeyRef, data) {
7346     var v;
7347     if (typeof schemaKeyRef == 'string') {
7348       v = getSchema(schemaKeyRef);
7349       if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
7350     } else {
7351       var schemaObj = _addSchema(schemaKeyRef);
7352       v = schemaObj.validate || _compile(schemaObj);
7353     }
7355     var valid = v(data);
7356     if (v.$async === true)
7357       return self._opts.async == '*' ? co(valid) : valid;
7358     self.errors = v.errors;
7359     return valid;
7360   }
7363   /**
7364    * Create validating function for passed schema.
7365    * @param  {Object} schema schema object
7366    * @return {Function} validating function
7367    */
7368   function compile(schema) {
7369     var schemaObj = _addSchema(schema);
7370     return schemaObj.validate || _compile(schemaObj);
7371   }
7374   /**
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.
7380    */
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);
7384       return;
7385     }
7386     // can key/id have # inside?
7387     key = resolve.normalizeId(key || schema.id);
7388     checkUnique(key);
7389     var schemaObj = self._schemas[key] = _addSchema(schema, _skipValidation, true);
7390     schemaObj.meta = _meta;
7391   }
7394   /**
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
7400    */
7401   function addMetaSchema(schema, key, skipValidation) {
7402     addSchema(schema, key, skipValidation, true);
7403   }
7406   /**
7407    * Validate schema
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
7411    */
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);
7424     }
7425     return valid;
7426   }
7429   function defaultMeta() {
7430     var meta = self._opts.meta;
7431     self._opts.defaultMeta = typeof meta == 'object'
7432                               ? meta.id || meta
7433                               : self._opts.v5
7434                                 ? v5.META_SCHEMA_ID
7435                                 : META_SCHEMA_ID;
7436     return self._opts.defaultMeta;
7437   }
7440   /**
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`).
7444    */
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);
7450     }
7451   }
7454   function _getSchemaObj(keyRef) {
7455     keyRef = resolve.normalizeId(keyRef);
7456     return self._schemas[keyRef] || self._refs[keyRef];
7457   }
7460   /**
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
7466    */
7467   function removeSchema(schemaKeyRef) {
7468     if (schemaKeyRef instanceof RegExp) {
7469       _removeAllSchemas(self._schemas, schemaKeyRef);
7470       _removeAllSchemas(self._refs, schemaKeyRef);
7471       return;
7472     }
7473     switch (typeof schemaKeyRef) {
7474       case 'undefined':
7475         _removeAllSchemas(self._schemas);
7476         _removeAllSchemas(self._refs);
7477         self._cache.clear();
7478         return;
7479       case 'string':
7480         var schemaObj = _getSchemaObj(schemaKeyRef);
7481         if (schemaObj) self._cache.del(schemaObj.jsonStr);
7482         delete self._schemas[schemaKeyRef];
7483         delete self._refs[schemaKeyRef];
7484         return;
7485       case 'object':
7486         var jsonStr = stableStringify(schemaKeyRef);
7487         self._cache.del(jsonStr);
7488         var id = schemaKeyRef.id;
7489         if (id) {
7490           id = resolve.normalizeId(id);
7491           delete self._schemas[id];
7492           delete self._refs[id];
7493         }
7494     }
7495   }
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];
7504       }
7505     }
7506   }
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({
7526       id: id,
7527       schema: schema,
7528       localRefs: localRefs,
7529       jsonStr: jsonStr
7530     });
7532     if (id[0] != '#' && shouldAddSchema) self._refs[id] = schemaObj;
7533     self._cache.put(jsonStr, schemaObj);
7535     return schemaObj;
7536   }
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;
7548     }
7549     schemaObj.compiling = true;
7551     var currentOpts;
7552     if (schemaObj.meta) {
7553       currentOpts = self._opts;
7554       self._opts = self._metaOpts;
7555     }
7557     var v;
7558     try { v = compileSchema.call(self, schemaObj.schema, root, schemaObj.localRefs); }
7559     finally {
7560       schemaObj.compiling = false;
7561       if (schemaObj.meta) self._opts = currentOpts;
7562     }
7564     schemaObj.validate = v;
7565     schemaObj.refs = v.refs;
7566     schemaObj.refVal = v.refVal;
7567     schemaObj.root = v.root;
7568     return v;
7571     function callValidate() {
7572       var _validate = schemaObj.validate;
7573       var result = _validate.apply(null, arguments);
7574       callValidate.errors = _validate.errors;
7575       return result;
7576     }
7577   }
7580   /**
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
7585    */
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;
7593     var text = '';
7594     for (var i=0; i<errors.length; i++) {
7595       var e = errors[i];
7596       if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
7597     }
7598     return text.slice(0, -separator.length);
7599   }
7602   /**
7603    * Add custom format
7604    * @param {String} name format name
7605    * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
7606    */
7607   function addFormat(name, format) {
7608     if (typeof format == 'string') format = new RegExp(format);
7609     self._formats[name] = format;
7610   }
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;
7618     }
7619   }
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);
7627   }
7630   function addInitialFormats() {
7631     for (var name in self._opts.formats) {
7632       var format = self._opts.formats[name];
7633       addFormat(name, format);
7634     }
7635   }
7638   function checkUnique(id) {
7639     if (self._schemas[id] || self._refs[id])
7640       throw new Error('schema with key or id "' + id + '" already exists');
7641   }
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]];
7648     return metaOpts;
7649   }
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")