PageRenderTime 64ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ajax/libs/z-schema/3.16.1/ZSchema-browser.js

https://gitlab.com/Mirros/cdnjs
JavaScript | 1436 lines | 1244 code | 90 blank | 102 comment | 157 complexity | da6df99c3363fbc2fa5317b1a7294faf MD5 | raw file
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ZSchema=e()}}(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){
  2. // shim for using process in browser
  3. var process = module.exports = {};
  4. process.nextTick = (function () {
  5. var canSetImmediate = typeof window !== 'undefined'
  6. && window.setImmediate;
  7. var canMutationObserver = typeof window !== 'undefined'
  8. && window.MutationObserver;
  9. var canPost = typeof window !== 'undefined'
  10. && window.postMessage && window.addEventListener
  11. ;
  12. if (canSetImmediate) {
  13. return function (f) { return window.setImmediate(f) };
  14. }
  15. var queue = [];
  16. if (canMutationObserver) {
  17. var hiddenDiv = document.createElement("div");
  18. var observer = new MutationObserver(function () {
  19. var queueList = queue.slice();
  20. queue.length = 0;
  21. queueList.forEach(function (fn) {
  22. fn();
  23. });
  24. });
  25. observer.observe(hiddenDiv, { attributes: true });
  26. return function nextTick(fn) {
  27. if (!queue.length) {
  28. hiddenDiv.setAttribute('yes', 'no');
  29. }
  30. queue.push(fn);
  31. };
  32. }
  33. if (canPost) {
  34. window.addEventListener('message', function (ev) {
  35. var source = ev.source;
  36. if ((source === window || source === null) && ev.data === 'process-tick') {
  37. ev.stopPropagation();
  38. if (queue.length > 0) {
  39. var fn = queue.shift();
  40. fn();
  41. }
  42. }
  43. }, true);
  44. return function nextTick(fn) {
  45. queue.push(fn);
  46. window.postMessage('process-tick', '*');
  47. };
  48. }
  49. return function nextTick(fn) {
  50. setTimeout(fn, 0);
  51. };
  52. })();
  53. process.title = 'browser';
  54. process.browser = true;
  55. process.env = {};
  56. process.argv = [];
  57. function noop() {}
  58. process.on = noop;
  59. process.addListener = noop;
  60. process.once = noop;
  61. process.off = noop;
  62. process.removeListener = noop;
  63. process.removeAllListeners = noop;
  64. process.emit = noop;
  65. process.binding = function (name) {
  66. throw new Error('process.binding is not supported');
  67. };
  68. // TODO(shtylman)
  69. process.cwd = function () { return '/' };
  70. process.chdir = function (dir) {
  71. throw new Error('process.chdir is not supported');
  72. };
  73. },{}],2:[function(require,module,exports){
  74. /**
  75. * lodash 3.7.0 (Custom Build) <https://lodash.com/>
  76. * Build: `lodash modern modularize exports="npm" -o ./`
  77. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  78. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  79. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  80. * Available under MIT license <https://lodash.com/license>
  81. */
  82. var baseGet = require('lodash._baseget'),
  83. toPath = require('lodash._topath');
  84. /**
  85. * Gets the property value of `path` on `object`. If the resolved value is
  86. * `undefined` the `defaultValue` is used in its place.
  87. *
  88. * @static
  89. * @memberOf _
  90. * @category Object
  91. * @param {Object} object The object to query.
  92. * @param {Array|string} path The path of the property to get.
  93. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  94. * @returns {*} Returns the resolved value.
  95. * @example
  96. *
  97. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  98. *
  99. * _.get(object, 'a[0].b.c');
  100. * // => 3
  101. *
  102. * _.get(object, ['a', '0', 'b', 'c']);
  103. * // => 3
  104. *
  105. * _.get(object, 'a.b.c', 'default');
  106. * // => 'default'
  107. */
  108. function get(object, path, defaultValue) {
  109. var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
  110. return result === undefined ? defaultValue : result;
  111. }
  112. module.exports = get;
  113. },{"lodash._baseget":3,"lodash._topath":4}],3:[function(require,module,exports){
  114. /**
  115. * lodash 3.7.2 (Custom Build) <https://lodash.com/>
  116. * Build: `lodash modern modularize exports="npm" -o ./`
  117. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  118. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  119. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  120. * Available under MIT license <https://lodash.com/license>
  121. */
  122. /**
  123. * The base implementation of `get` without support for string paths
  124. * and default values.
  125. *
  126. * @private
  127. * @param {Object} object The object to query.
  128. * @param {Array} path The path of the property to get.
  129. * @param {string} [pathKey] The key representation of path.
  130. * @returns {*} Returns the resolved value.
  131. */
  132. function baseGet(object, path, pathKey) {
  133. if (object == null) {
  134. return;
  135. }
  136. if (pathKey !== undefined && pathKey in toObject(object)) {
  137. path = [pathKey];
  138. }
  139. var index = 0,
  140. length = path.length;
  141. while (object != null && index < length) {
  142. object = object[path[index++]];
  143. }
  144. return (index && index == length) ? object : undefined;
  145. }
  146. /**
  147. * Converts `value` to an object if it's not one.
  148. *
  149. * @private
  150. * @param {*} value The value to process.
  151. * @returns {Object} Returns the object.
  152. */
  153. function toObject(value) {
  154. return isObject(value) ? value : Object(value);
  155. }
  156. /**
  157. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  158. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  159. *
  160. * @static
  161. * @memberOf _
  162. * @category Lang
  163. * @param {*} value The value to check.
  164. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  165. * @example
  166. *
  167. * _.isObject({});
  168. * // => true
  169. *
  170. * _.isObject([1, 2, 3]);
  171. * // => true
  172. *
  173. * _.isObject(1);
  174. * // => false
  175. */
  176. function isObject(value) {
  177. // Avoid a V8 JIT bug in Chrome 19-20.
  178. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  179. var type = typeof value;
  180. return !!value && (type == 'object' || type == 'function');
  181. }
  182. module.exports = baseGet;
  183. },{}],4:[function(require,module,exports){
  184. /**
  185. * lodash 3.8.1 (Custom Build) <https://lodash.com/>
  186. * Build: `lodash modern modularize exports="npm" -o ./`
  187. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  188. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  189. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  190. * Available under MIT license <https://lodash.com/license>
  191. */
  192. var isArray = require('lodash.isarray');
  193. /** Used to match property names within property paths. */
  194. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  195. /** Used to match backslashes in property paths. */
  196. var reEscapeChar = /\\(\\)?/g;
  197. /**
  198. * Converts `value` to a string if it's not one. An empty string is returned
  199. * for `null` or `undefined` values.
  200. *
  201. * @private
  202. * @param {*} value The value to process.
  203. * @returns {string} Returns the string.
  204. */
  205. function baseToString(value) {
  206. return value == null ? '' : (value + '');
  207. }
  208. /**
  209. * Converts `value` to property path array if it's not one.
  210. *
  211. * @private
  212. * @param {*} value The value to process.
  213. * @returns {Array} Returns the property path array.
  214. */
  215. function toPath(value) {
  216. if (isArray(value)) {
  217. return value;
  218. }
  219. var result = [];
  220. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  221. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  222. });
  223. return result;
  224. }
  225. module.exports = toPath;
  226. },{"lodash.isarray":5}],5:[function(require,module,exports){
  227. /**
  228. * lodash 3.0.4 (Custom Build) <https://lodash.com/>
  229. * Build: `lodash modern modularize exports="npm" -o ./`
  230. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  231. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  232. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  233. * Available under MIT license <https://lodash.com/license>
  234. */
  235. /** `Object#toString` result references. */
  236. var arrayTag = '[object Array]',
  237. funcTag = '[object Function]';
  238. /** Used to detect host constructors (Safari > 5). */
  239. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  240. /**
  241. * Checks if `value` is object-like.
  242. *
  243. * @private
  244. * @param {*} value The value to check.
  245. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  246. */
  247. function isObjectLike(value) {
  248. return !!value && typeof value == 'object';
  249. }
  250. /** Used for native method references. */
  251. var objectProto = Object.prototype;
  252. /** Used to resolve the decompiled source of functions. */
  253. var fnToString = Function.prototype.toString;
  254. /** Used to check objects for own properties. */
  255. var hasOwnProperty = objectProto.hasOwnProperty;
  256. /**
  257. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  258. * of values.
  259. */
  260. var objToString = objectProto.toString;
  261. /** Used to detect if a method is native. */
  262. var reIsNative = RegExp('^' +
  263. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  264. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  265. );
  266. /* Native method references for those with the same name as other `lodash` methods. */
  267. var nativeIsArray = getNative(Array, 'isArray');
  268. /**
  269. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  270. * of an array-like value.
  271. */
  272. var MAX_SAFE_INTEGER = 9007199254740991;
  273. /**
  274. * Gets the native function at `key` of `object`.
  275. *
  276. * @private
  277. * @param {Object} object The object to query.
  278. * @param {string} key The key of the method to get.
  279. * @returns {*} Returns the function if it's native, else `undefined`.
  280. */
  281. function getNative(object, key) {
  282. var value = object == null ? undefined : object[key];
  283. return isNative(value) ? value : undefined;
  284. }
  285. /**
  286. * Checks if `value` is a valid array-like length.
  287. *
  288. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  289. *
  290. * @private
  291. * @param {*} value The value to check.
  292. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  293. */
  294. function isLength(value) {
  295. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  296. }
  297. /**
  298. * Checks if `value` is classified as an `Array` object.
  299. *
  300. * @static
  301. * @memberOf _
  302. * @category Lang
  303. * @param {*} value The value to check.
  304. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  305. * @example
  306. *
  307. * _.isArray([1, 2, 3]);
  308. * // => true
  309. *
  310. * _.isArray(function() { return arguments; }());
  311. * // => false
  312. */
  313. var isArray = nativeIsArray || function(value) {
  314. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  315. };
  316. /**
  317. * Checks if `value` is classified as a `Function` object.
  318. *
  319. * @static
  320. * @memberOf _
  321. * @category Lang
  322. * @param {*} value The value to check.
  323. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  324. * @example
  325. *
  326. * _.isFunction(_);
  327. * // => true
  328. *
  329. * _.isFunction(/abc/);
  330. * // => false
  331. */
  332. function isFunction(value) {
  333. // The use of `Object#toString` avoids issues with the `typeof` operator
  334. // in older versions of Chrome and Safari which return 'function' for regexes
  335. // and Safari 8 equivalents which return 'object' for typed array constructors.
  336. return isObject(value) && objToString.call(value) == funcTag;
  337. }
  338. /**
  339. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  340. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  341. *
  342. * @static
  343. * @memberOf _
  344. * @category Lang
  345. * @param {*} value The value to check.
  346. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  347. * @example
  348. *
  349. * _.isObject({});
  350. * // => true
  351. *
  352. * _.isObject([1, 2, 3]);
  353. * // => true
  354. *
  355. * _.isObject(1);
  356. * // => false
  357. */
  358. function isObject(value) {
  359. // Avoid a V8 JIT bug in Chrome 19-20.
  360. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  361. var type = typeof value;
  362. return !!value && (type == 'object' || type == 'function');
  363. }
  364. /**
  365. * Checks if `value` is a native function.
  366. *
  367. * @static
  368. * @memberOf _
  369. * @category Lang
  370. * @param {*} value The value to check.
  371. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  372. * @example
  373. *
  374. * _.isNative(Array.prototype.push);
  375. * // => true
  376. *
  377. * _.isNative(_);
  378. * // => false
  379. */
  380. function isNative(value) {
  381. if (value == null) {
  382. return false;
  383. }
  384. if (isFunction(value)) {
  385. return reIsNative.test(fnToString.call(value));
  386. }
  387. return isObjectLike(value) && reIsHostCtor.test(value);
  388. }
  389. module.exports = isArray;
  390. },{}],6:[function(require,module,exports){
  391. /*!
  392. * Copyright (c) 2015 Chris O'Hara <cohara87@gmail.com>
  393. *
  394. * Permission is hereby granted, free of charge, to any person obtaining
  395. * a copy of this software and associated documentation files (the
  396. * "Software"), to deal in the Software without restriction, including
  397. * without limitation the rights to use, copy, modify, merge, publish,
  398. * distribute, sublicense, and/or sell copies of the Software, and to
  399. * permit persons to whom the Software is furnished to do so, subject to
  400. * the following conditions:
  401. *
  402. * The above copyright notice and this permission notice shall be
  403. * included in all copies or substantial portions of the Software.
  404. *
  405. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  406. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  407. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  408. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  409. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  410. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  411. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  412. */
  413. (function (name, definition) {
  414. if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
  415. module.exports = definition();
  416. } else if (typeof define === 'function' && typeof define.amd === 'object') {
  417. define(definition);
  418. } else {
  419. this[name] = definition();
  420. }
  421. })('validator', function (validator) {
  422. 'use strict';
  423. validator = { version: '4.0.5' };
  424. var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
  425. var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
  426. var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
  427. var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
  428. var displayName = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i;
  429. var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/;
  430. var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;
  431. var isbn10Maybe = /^(?:[0-9]{9}X|[0-9]{10})$/
  432. , isbn13Maybe = /^(?:[0-9]{13})$/;
  433. var ipv4Maybe = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
  434. , ipv6Block = /^[0-9A-F]{1,4}$/i;
  435. var uuid = {
  436. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  437. , '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
  438. , '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
  439. , all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  440. };
  441. var alpha = /^[A-Z]+$/i
  442. , alphanumeric = /^[0-9A-Z]+$/i
  443. , numeric = /^[-+]?[0-9]+$/
  444. , int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/
  445. , float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/
  446. , hexadecimal = /^[0-9A-F]+$/i
  447. , decimal = /^[-+]?([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/
  448. , hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;
  449. var ascii = /^[\x00-\x7F]+$/
  450. , multibyte = /[^\x00-\x7F]/
  451. , fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/
  452. , halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  453. var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
  454. var base64 = /^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i;
  455. var phones = {
  456. 'zh-CN': /^(\+?0?86\-?)?1[345789]\d{9}$/,
  457. 'en-ZA': /^(\+?27|0)\d{9}$/,
  458. 'en-AU': /^(\+?61|0)4\d{8}$/,
  459. 'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,
  460. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  461. 'pt-PT': /^(\+351)?9[1236]\d{7}$/,
  462. 'el-GR': /^(\+30)?((2\d{9})|(69\d{8}))$/,
  463. 'en-GB': /^(\+?44|0)7\d{9}$/,
  464. 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
  465. 'en-ZM': /^(\+26)?09[567]\d{7}$/,
  466. 'ru-RU': /^(\+?7|8)?9\d{9}$/
  467. };
  468. // from http://goo.gl/0ejHHW
  469. var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
  470. validator.extend = function (name, fn) {
  471. validator[name] = function () {
  472. var args = Array.prototype.slice.call(arguments);
  473. args[0] = validator.toString(args[0]);
  474. return fn.apply(validator, args);
  475. };
  476. };
  477. //Right before exporting the validator object, pass each of the builtins
  478. //through extend() so that their first argument is coerced to a string
  479. validator.init = function () {
  480. for (var name in validator) {
  481. if (typeof validator[name] !== 'function' || name === 'toString' ||
  482. name === 'toDate' || name === 'extend' || name === 'init') {
  483. continue;
  484. }
  485. validator.extend(name, validator[name]);
  486. }
  487. };
  488. validator.toString = function (input) {
  489. if (typeof input === 'object' && input !== null && input.toString) {
  490. input = input.toString();
  491. } else if (input === null || typeof input === 'undefined' || (isNaN(input) && !input.length)) {
  492. input = '';
  493. } else if (typeof input !== 'string') {
  494. input += '';
  495. }
  496. return input;
  497. };
  498. validator.toDate = function (date) {
  499. if (Object.prototype.toString.call(date) === '[object Date]') {
  500. return date;
  501. }
  502. date = Date.parse(date);
  503. return !isNaN(date) ? new Date(date) : null;
  504. };
  505. validator.toFloat = function (str) {
  506. return parseFloat(str);
  507. };
  508. validator.toInt = function (str, radix) {
  509. return parseInt(str, radix || 10);
  510. };
  511. validator.toBoolean = function (str, strict) {
  512. if (strict) {
  513. return str === '1' || str === 'true';
  514. }
  515. return str !== '0' && str !== 'false' && str !== '';
  516. };
  517. validator.equals = function (str, comparison) {
  518. return str === validator.toString(comparison);
  519. };
  520. validator.contains = function (str, elem) {
  521. return str.indexOf(validator.toString(elem)) >= 0;
  522. };
  523. validator.matches = function (str, pattern, modifiers) {
  524. if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
  525. pattern = new RegExp(pattern, modifiers);
  526. }
  527. return pattern.test(str);
  528. };
  529. var default_email_options = {
  530. allow_display_name: false,
  531. allow_utf8_local_part: true,
  532. require_tld: true
  533. };
  534. validator.isEmail = function (str, options) {
  535. options = merge(options, default_email_options);
  536. if (options.allow_display_name) {
  537. var display_email = str.match(displayName);
  538. if (display_email) {
  539. str = display_email[1];
  540. }
  541. }
  542. var parts = str.split('@')
  543. , domain = parts.pop()
  544. , user = parts.join('@');
  545. var lower_domain = domain.toLowerCase();
  546. if (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com') {
  547. user = user.replace(/\./g, '').toLowerCase();
  548. }
  549. if (!validator.isByteLength(user, 0, 64) ||
  550. !validator.isByteLength(domain, 0, 256)) {
  551. return false;
  552. }
  553. if (!validator.isFQDN(domain, {require_tld: options.require_tld})) {
  554. return false;
  555. }
  556. if (user[0] === '"') {
  557. user = user.slice(1, user.length - 1);
  558. return options.allow_utf8_local_part ?
  559. quotedEmailUserUtf8.test(user) :
  560. quotedEmailUser.test(user);
  561. }
  562. var pattern = options.allow_utf8_local_part ?
  563. emailUserUtf8Part : emailUserPart;
  564. var user_parts = user.split('.');
  565. for (var i = 0; i < user_parts.length; i++) {
  566. if (!pattern.test(user_parts[i])) {
  567. return false;
  568. }
  569. }
  570. return true;
  571. };
  572. var default_url_options = {
  573. protocols: [ 'http', 'https', 'ftp' ]
  574. , require_tld: true
  575. , require_protocol: false
  576. , require_valid_protocol: true
  577. , allow_underscores: false
  578. , allow_trailing_dot: false
  579. , allow_protocol_relative_urls: false
  580. };
  581. validator.isURL = function (url, options) {
  582. if (!url || url.length >= 2083 || /\s/.test(url)) {
  583. return false;
  584. }
  585. if (url.indexOf('mailto:') === 0) {
  586. return false;
  587. }
  588. options = merge(options, default_url_options);
  589. var protocol, auth, host, hostname, port,
  590. port_str, split;
  591. split = url.split('://');
  592. if (split.length > 1) {
  593. protocol = split.shift();
  594. if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
  595. return false;
  596. }
  597. } else if (options.require_protocol) {
  598. return false;
  599. } else if (options.allow_protocol_relative_urls && url.substr(0, 2) === '//') {
  600. split[0] = url.substr(2);
  601. }
  602. url = split.join('://');
  603. split = url.split('#');
  604. url = split.shift();
  605. split = url.split('?');
  606. url = split.shift();
  607. split = url.split('/');
  608. url = split.shift();
  609. split = url.split('@');
  610. if (split.length > 1) {
  611. auth = split.shift();
  612. if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
  613. return false;
  614. }
  615. }
  616. hostname = split.join('@');
  617. split = hostname.split(':');
  618. host = split.shift();
  619. if (split.length) {
  620. port_str = split.join(':');
  621. port = parseInt(port_str, 10);
  622. if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
  623. return false;
  624. }
  625. }
  626. if (!validator.isIP(host) && !validator.isFQDN(host, options) &&
  627. host !== 'localhost') {
  628. return false;
  629. }
  630. if (options.host_whitelist &&
  631. options.host_whitelist.indexOf(host) === -1) {
  632. return false;
  633. }
  634. if (options.host_blacklist &&
  635. options.host_blacklist.indexOf(host) !== -1) {
  636. return false;
  637. }
  638. return true;
  639. };
  640. validator.isIP = function (str, version) {
  641. version = validator.toString(version);
  642. if (!version) {
  643. return validator.isIP(str, 4) || validator.isIP(str, 6);
  644. } else if (version === '4') {
  645. if (!ipv4Maybe.test(str)) {
  646. return false;
  647. }
  648. var parts = str.split('.').sort(function (a, b) {
  649. return a - b;
  650. });
  651. return parts[3] <= 255;
  652. } else if (version === '6') {
  653. var blocks = str.split(':');
  654. var foundOmissionBlock = false; // marker to indicate ::
  655. // At least some OS accept the last 32 bits of an IPv6 address
  656. // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
  657. // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
  658. // and '::a.b.c.d' is deprecated, but also valid.
  659. var foundIPv4TransitionBlock = validator.isIP(blocks[blocks.length - 1], 4);
  660. var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;
  661. if (blocks.length > expectedNumberOfBlocks)
  662. return false;
  663. // initial or final ::
  664. if (str === '::') {
  665. return true;
  666. } else if (str.substr(0, 2) === '::') {
  667. blocks.shift();
  668. blocks.shift();
  669. foundOmissionBlock = true;
  670. } else if (str.substr(str.length - 2) === '::') {
  671. blocks.pop();
  672. blocks.pop();
  673. foundOmissionBlock = true;
  674. }
  675. for (var i = 0; i < blocks.length; ++i) {
  676. // test for a :: which can not be at the string start/end
  677. // since those cases have been handled above
  678. if (blocks[i] === '' && i > 0 && i < blocks.length -1) {
  679. if (foundOmissionBlock)
  680. return false; // multiple :: in address
  681. foundOmissionBlock = true;
  682. } else if (foundIPv4TransitionBlock && i == blocks.length - 1) {
  683. // it has been checked before that the last
  684. // block is a valid IPv4 address
  685. } else if (!ipv6Block.test(blocks[i])) {
  686. return false;
  687. }
  688. }
  689. if (foundOmissionBlock) {
  690. return blocks.length >= 1;
  691. } else {
  692. return blocks.length === expectedNumberOfBlocks;
  693. }
  694. }
  695. return false;
  696. };
  697. var default_fqdn_options = {
  698. require_tld: true
  699. , allow_underscores: false
  700. , allow_trailing_dot: false
  701. };
  702. validator.isFQDN = function (str, options) {
  703. options = merge(options, default_fqdn_options);
  704. /* Remove the optional trailing dot before checking validity */
  705. if (options.allow_trailing_dot && str[str.length - 1] === '.') {
  706. str = str.substring(0, str.length - 1);
  707. }
  708. var parts = str.split('.');
  709. if (options.require_tld) {
  710. var tld = parts.pop();
  711. if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
  712. return false;
  713. }
  714. }
  715. for (var part, i = 0; i < parts.length; i++) {
  716. part = parts[i];
  717. if (options.allow_underscores) {
  718. if (part.indexOf('__') >= 0) {
  719. return false;
  720. }
  721. part = part.replace(/_/g, '');
  722. }
  723. if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
  724. return false;
  725. }
  726. if (/[\uff01-\uff5e]/.test(part)) {
  727. // disallow full-width chars
  728. return false;
  729. }
  730. if (part[0] === '-' || part[part.length - 1] === '-' ||
  731. part.indexOf('---') >= 0) {
  732. return false;
  733. }
  734. }
  735. return true;
  736. };
  737. validator.isBoolean = function(str) {
  738. return (['true', 'false', '1', '0'].indexOf(str) >= 0);
  739. };
  740. validator.isAlpha = function (str) {
  741. return alpha.test(str);
  742. };
  743. validator.isAlphanumeric = function (str) {
  744. return alphanumeric.test(str);
  745. };
  746. validator.isNumeric = function (str) {
  747. return numeric.test(str);
  748. };
  749. validator.isDecimal = function (str) {
  750. return str !== '' && decimal.test(str);
  751. };
  752. validator.isHexadecimal = function (str) {
  753. return hexadecimal.test(str);
  754. };
  755. validator.isHexColor = function (str) {
  756. return hexcolor.test(str);
  757. };
  758. validator.isLowercase = function (str) {
  759. return str === str.toLowerCase();
  760. };
  761. validator.isUppercase = function (str) {
  762. return str === str.toUpperCase();
  763. };
  764. validator.isInt = function (str, options) {
  765. options = options || {};
  766. return int.test(str) && (!options.hasOwnProperty('min') || str >= options.min) && (!options.hasOwnProperty('max') || str <= options.max);
  767. };
  768. validator.isFloat = function (str, options) {
  769. options = options || {};
  770. return str !== '' && float.test(str) && (!options.hasOwnProperty('min') || str >= options.min) && (!options.hasOwnProperty('max') || str <= options.max);
  771. };
  772. validator.isDivisibleBy = function (str, num) {
  773. return validator.toFloat(str) % validator.toInt(num) === 0;
  774. };
  775. validator.isNull = function (str) {
  776. return str.length === 0;
  777. };
  778. validator.isLength = function (str, min, max) {
  779. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  780. var len = str.length - surrogatePairs.length;
  781. return len >= min && (typeof max === 'undefined' || len <= max);
  782. };
  783. validator.isByteLength = function (str, min, max) {
  784. var len = encodeURI(str).split(/%..|./).length - 1;
  785. return len >= min && (typeof max === 'undefined' || len <= max);
  786. };
  787. validator.isUUID = function (str, version) {
  788. var pattern = uuid[version ? version : 'all'];
  789. return pattern && pattern.test(str);
  790. };
  791. validator.isDate = function (str) {
  792. return !isNaN(Date.parse(str));
  793. };
  794. validator.isAfter = function (str, date) {
  795. var comparison = validator.toDate(date || new Date())
  796. , original = validator.toDate(str);
  797. return !!(original && comparison && original > comparison);
  798. };
  799. validator.isBefore = function (str, date) {
  800. var comparison = validator.toDate(date || new Date())
  801. , original = validator.toDate(str);
  802. return original && comparison && original < comparison;
  803. };
  804. validator.isIn = function (str, options) {
  805. var i;
  806. if (Object.prototype.toString.call(options) === '[object Array]') {
  807. var array = [];
  808. for (i in options) {
  809. array[i] = validator.toString(options[i]);
  810. }
  811. return array.indexOf(str) >= 0;
  812. } else if (typeof options === 'object') {
  813. return options.hasOwnProperty(str);
  814. } else if (options && typeof options.indexOf === 'function') {
  815. return options.indexOf(str) >= 0;
  816. }
  817. return false;
  818. };
  819. validator.isCreditCard = function (str) {
  820. var sanitized = str.replace(/[^0-9]+/g, '');
  821. if (!creditCard.test(sanitized)) {
  822. return false;
  823. }
  824. var sum = 0, digit, tmpNum, shouldDouble;
  825. for (var i = sanitized.length - 1; i >= 0; i--) {
  826. digit = sanitized.substring(i, (i + 1));
  827. tmpNum = parseInt(digit, 10);
  828. if (shouldDouble) {
  829. tmpNum *= 2;
  830. if (tmpNum >= 10) {
  831. sum += ((tmpNum % 10) + 1);
  832. } else {
  833. sum += tmpNum;
  834. }
  835. } else {
  836. sum += tmpNum;
  837. }
  838. shouldDouble = !shouldDouble;
  839. }
  840. return !!((sum % 10) === 0 ? sanitized : false);
  841. };
  842. validator.isISIN = function (str) {
  843. if (!isin.test(str)) {
  844. return false;
  845. }
  846. var checksumStr = str.replace(/[A-Z]/g, function(character) {
  847. return parseInt(character, 36);
  848. });
  849. var sum = 0, digit, tmpNum, shouldDouble = true;
  850. for (var i = checksumStr.length - 2; i >= 0; i--) {
  851. digit = checksumStr.substring(i, (i + 1));
  852. tmpNum = parseInt(digit, 10);
  853. if (shouldDouble) {
  854. tmpNum *= 2;
  855. if (tmpNum >= 10) {
  856. sum += tmpNum + 1;
  857. } else {
  858. sum += tmpNum;
  859. }
  860. } else {
  861. sum += tmpNum;
  862. }
  863. shouldDouble = !shouldDouble;
  864. }
  865. return parseInt(str.substr(str.length - 1), 10) === (10000 - sum) % 10;
  866. };
  867. validator.isISBN = function (str, version) {
  868. version = validator.toString(version);
  869. if (!version) {
  870. return validator.isISBN(str, 10) || validator.isISBN(str, 13);
  871. }
  872. var sanitized = str.replace(/[\s-]+/g, '')
  873. , checksum = 0, i;
  874. if (version === '10') {
  875. if (!isbn10Maybe.test(sanitized)) {
  876. return false;
  877. }
  878. for (i = 0; i < 9; i++) {
  879. checksum += (i + 1) * sanitized.charAt(i);
  880. }
  881. if (sanitized.charAt(9) === 'X') {
  882. checksum += 10 * 10;
  883. } else {
  884. checksum += 10 * sanitized.charAt(9);
  885. }
  886. if ((checksum % 11) === 0) {
  887. return !!sanitized;
  888. }
  889. } else if (version === '13') {
  890. if (!isbn13Maybe.test(sanitized)) {
  891. return false;
  892. }
  893. var factor = [ 1, 3 ];
  894. for (i = 0; i < 12; i++) {
  895. checksum += factor[i % 2] * sanitized.charAt(i);
  896. }
  897. if (sanitized.charAt(12) - ((10 - (checksum % 10)) % 10) === 0) {
  898. return !!sanitized;
  899. }
  900. }
  901. return false;
  902. };
  903. validator.isMobilePhone = function(str, locale) {
  904. if (locale in phones) {
  905. return phones[locale].test(str);
  906. }
  907. return false;
  908. };
  909. var default_currency_options = {
  910. symbol: '$'
  911. , require_symbol: false
  912. , allow_space_after_symbol: false
  913. , symbol_after_digits: false
  914. , allow_negatives: true
  915. , parens_for_negatives: false
  916. , negative_sign_before_digits: false
  917. , negative_sign_after_digits: false
  918. , allow_negative_sign_placeholder: false
  919. , thousands_separator: ','
  920. , decimal_separator: '.'
  921. , allow_space_after_digits: false
  922. };
  923. validator.isCurrency = function (str, options) {
  924. options = merge(options, default_currency_options);
  925. return currencyRegex(options).test(str);
  926. };
  927. validator.isJSON = function (str) {
  928. try {
  929. var obj = JSON.parse(str);
  930. return !!obj && typeof obj === 'object';
  931. } catch (e) {}
  932. return false;
  933. };
  934. validator.isMultibyte = function (str) {
  935. return multibyte.test(str);
  936. };
  937. validator.isAscii = function (str) {
  938. return ascii.test(str);
  939. };
  940. validator.isFullWidth = function (str) {
  941. return fullWidth.test(str);
  942. };
  943. validator.isHalfWidth = function (str) {
  944. return halfWidth.test(str);
  945. };
  946. validator.isVariableWidth = function (str) {
  947. return fullWidth.test(str) && halfWidth.test(str);
  948. };
  949. validator.isSurrogatePair = function (str) {
  950. return surrogatePair.test(str);
  951. };
  952. validator.isBase64 = function (str) {
  953. return base64.test(str);
  954. };
  955. validator.isMongoId = function (str) {
  956. return validator.isHexadecimal(str) && str.length === 24;
  957. };
  958. validator.isISO8601 = function (str) {
  959. return iso8601.test(str);
  960. };
  961. validator.ltrim = function (str, chars) {
  962. var pattern = chars ? new RegExp('^[' + chars + ']+', 'g') : /^\s+/g;
  963. return str.replace(pattern, '');
  964. };
  965. validator.rtrim = function (str, chars) {
  966. var pattern = chars ? new RegExp('[' + chars + ']+$', 'g') : /\s+$/g;
  967. return str.replace(pattern, '');
  968. };
  969. validator.trim = function (str, chars) {
  970. var pattern = chars ? new RegExp('^[' + chars + ']+|[' + chars + ']+$', 'g') : /^\s+|\s+$/g;
  971. return str.replace(pattern, '');
  972. };
  973. validator.escape = function (str) {
  974. return (str.replace(/&/g, '&amp;')
  975. .replace(/"/g, '&quot;')
  976. .replace(/'/g, '&#x27;')
  977. .replace(/</g, '&lt;')
  978. .replace(/>/g, '&gt;')
  979. .replace(/\//g, '&#x2F;')
  980. .replace(/\`/g, '&#96;'));
  981. };
  982. validator.stripLow = function (str, keep_new_lines) {
  983. var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
  984. return validator.blacklist(str, chars);
  985. };
  986. validator.whitelist = function (str, chars) {
  987. return str.replace(new RegExp('[^' + chars + ']+', 'g'), '');
  988. };
  989. validator.blacklist = function (str, chars) {
  990. return str.replace(new RegExp('[' + chars + ']+', 'g'), '');
  991. };
  992. var default_normalize_email_options = {
  993. lowercase: true
  994. };
  995. validator.normalizeEmail = function (email, options) {
  996. options = merge(options, default_normalize_email_options);
  997. if (!validator.isEmail(email)) {
  998. return false;
  999. }
  1000. var parts = email.split('@', 2);
  1001. parts[1] = parts[1].toLowerCase();
  1002. if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
  1003. parts[0] = parts[0].toLowerCase().replace(/\./g, '');
  1004. if (parts[0][0] === '+') {
  1005. return false;
  1006. }
  1007. parts[0] = parts[0].split('+')[0];
  1008. parts[1] = 'gmail.com';
  1009. } else if (options.lowercase) {
  1010. parts[0] = parts[0].toLowerCase();
  1011. }
  1012. return parts.join('@');
  1013. };
  1014. function merge(obj, defaults) {
  1015. obj = obj || {};
  1016. for (var key in defaults) {
  1017. if (typeof obj[key] === 'undefined') {
  1018. obj[key] = defaults[key];
  1019. }
  1020. }
  1021. return obj;
  1022. }
  1023. function currencyRegex(options) {
  1024. var symbol = '(\\' + options.symbol.replace(/\./g, '\\.') + ')' + (options.require_symbol ? '' : '?')
  1025. , negative = '-?'
  1026. , whole_dollar_amount_without_sep = '[1-9]\\d*'
  1027. , whole_dollar_amount_with_sep = '[1-9]\\d{0,2}(\\' + options.thousands_separator + '\\d{3})*'
  1028. , valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep]
  1029. , whole_dollar_amount = '(' + valid_whole_dollar_amounts.join('|') + ')?'
  1030. , decimal_amount = '(\\' + options.decimal_separator + '\\d{2})?';
  1031. var pattern = whole_dollar_amount + decimal_amount;
  1032. // default is negative sign before symbol, but there are two other options (besides parens)
  1033. if (options.allow_negatives && !options.parens_for_negatives) {
  1034. if (options.negative_sign_after_digits) {
  1035. pattern += negative;
  1036. }
  1037. else if (options.negative_sign_before_digits) {
  1038. pattern = negative + pattern;
  1039. }
  1040. }
  1041. // South African Rand, for example, uses R 123 (space) and R-123 (no space)
  1042. if (options.allow_negative_sign_placeholder) {
  1043. pattern = '( (?!\\-))?' + pattern;
  1044. }
  1045. else if (options.allow_space_after_symbol) {
  1046. pattern = ' ?' + pattern;
  1047. }
  1048. else if (options.allow_space_after_digits) {
  1049. pattern += '( (?!$))?';
  1050. }
  1051. if (options.symbol_after_digits) {
  1052. pattern += symbol;
  1053. } else {
  1054. pattern = symbol + pattern;
  1055. }
  1056. if (options.allow_negatives) {
  1057. if (options.parens_for_negatives) {
  1058. pattern = '(\\(' + pattern + '\\)|' + pattern + ')';
  1059. }
  1060. else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
  1061. pattern = negative + pattern;
  1062. }
  1063. }
  1064. return new RegExp(
  1065. '^' +
  1066. // ensure there's a dollar and/or decimal amount, and that it doesn't start with a space or a negative sign followed by a space
  1067. '(?!-? )(?=.*\\d)' +
  1068. pattern +
  1069. '$'
  1070. );
  1071. }
  1072. validator.init();
  1073. return validator;
  1074. });
  1075. },{}],7:[function(require,module,exports){
  1076. "use strict";
  1077. module.exports = {
  1078. INVALID_TYPE: "Expected type {0} but found type {1}",
  1079. INVALID_FORMAT: "Object didn't pass validation for format {0}: {1}",
  1080. ENUM_MISMATCH: "No enum match for: {0}",
  1081. ANY_OF_MISSING: "Data does not match any schemas from 'anyOf'",
  1082. ONE_OF_MISSING: "Data does not match any schemas from 'oneOf'",
  1083. ONE_OF_MULTIPLE: "Data is valid against more than one schema from 'oneOf'",
  1084. NOT_PASSED: "Data matches schema from 'not'",
  1085. // Array errors
  1086. ARRAY_LENGTH_SHORT: "Array is too short ({0}), minimum {1}",
  1087. ARRAY_LENGTH_LONG: "Array is too long ({0}), maximum {1}",
  1088. ARRAY_UNIQUE: "Array items are not unique (indexes {0} and {1})",
  1089. ARRAY_ADDITIONAL_ITEMS: "Additional items not allowed",
  1090. // Numeric errors
  1091. MULTIPLE_OF: "Value {0} is not a multiple of {1}",
  1092. MINIMUM: "Value {0} is less than minimum {1}",
  1093. MINIMUM_EXCLUSIVE: "Value {0} is equal or less than exclusive minimum {1}",
  1094. MAXIMUM: "Value {0} is greater than maximum {1}",
  1095. MAXIMUM_EXCLUSIVE: "Value {0} is equal or greater than exclusive maximum {1}",
  1096. // Object errors
  1097. OBJECT_PROPERTIES_MINIMUM: "Too few properties defined ({0}), minimum {1}",
  1098. OBJECT_PROPERTIES_MAXIMUM: "Too many properties defined ({0}), maximum {1}",
  1099. OBJECT_MISSING_REQUIRED_PROPERTY: "Missing required property: {0}",
  1100. OBJECT_ADDITIONAL_PROPERTIES: "Additional properties not allowed: {0}",
  1101. OBJECT_DEPENDENCY_KEY: "Dependency failed - key must exist: {0} (due to key: {1})",
  1102. // String errors
  1103. MIN_LENGTH: "String is too short ({0} chars), minimum {1}",
  1104. MAX_LENGTH: "String is too long ({0} chars), maximum {1}",
  1105. PATTERN: "String does not match pattern {0}: {1}",
  1106. // Schema validation errors
  1107. KEYWORD_TYPE_EXPECTED: "Keyword '{0}' is expected to be of type '{1}'",
  1108. KEYWORD_UNDEFINED_STRICT: "Keyword '{0}' must be defined in strict mode",
  1109. KEYWORD_UNEXPECTED: "Keyword '{0}' is not expected to appear in the schema",
  1110. KEYWORD_MUST_BE: "Keyword '{0}' must be {1}",
  1111. KEYWORD_DEPENDENCY: "Keyword '{0}' requires keyword '{1}'",
  1112. KEYWORD_PATTERN: "Keyword '{0}' is not a valid RegExp pattern: {1}",
  1113. KEYWORD_VALUE_TYPE: "Each element of keyword '{0}' array must be a '{1}'",
  1114. UNKNOWN_FORMAT: "There is no validation function for format '{0}'",
  1115. CUSTOM_MODE_FORCE_PROPERTIES: "{0} must define at least one property if present",
  1116. // Remote errors
  1117. REF_UNRESOLVED: "Reference has not been resolved during compilation: {0}",
  1118. UNRESOLVABLE_REFERENCE: "Reference could not be resolved: {0}",
  1119. SCHEMA_NOT_REACHABLE: "Validator was not able to read schema with uri: {0}",
  1120. SCHEMA_TYPE_EXPECTED: "Schema is expected to be of type 'object'",
  1121. SCHEMA_NOT_AN_OBJECT: "Schema is not an object: {0}",
  1122. ASYNC_TIMEOUT: "{0} asynchronous task(s) have timed out after {1} ms",
  1123. PARENT_SCHEMA_VALIDATION_FAILED: "Schema failed to validate against its parent schema, see inner errors for details.",
  1124. REMOTE_NOT_VALID: "Remote reference didn't compile successfully: {0}"
  1125. };
  1126. },{}],8:[function(require,module,exports){
  1127. /*jshint maxlen: false*/
  1128. var validator = require("validator");
  1129. var FormatValidators = {
  1130. "date": function (date) {
  1131. if (typeof date !== "string") {
  1132. return true;
  1133. }
  1134. // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
  1135. var matches = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(date);
  1136. if (matches === null) {
  1137. return false;
  1138. }
  1139. // var year = matches[1];
  1140. // var month = matches[2];
  1141. // var day = matches[3];
  1142. if (matches[2] < "01" || matches[2] > "12" || matches[3] < "01" || matches[3] > "31") {
  1143. return false;
  1144. }
  1145. return true;
  1146. },
  1147. "date-time": function (dateTime) {
  1148. if (typeof dateTime !== "string") {
  1149. return true;
  1150. }
  1151. // date-time from http://tools.ietf.org/html/rfc3339#section-5.6
  1152. var s = dateTime.toLowerCase().split("t");
  1153. if (!FormatValidators.date(s[0])) {
  1154. return false;
  1155. }
  1156. var matches = /^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$/.exec(s[1]);
  1157. if (matches === null) {
  1158. return false;
  1159. }
  1160. // var hour = matches[1];
  1161. // var minute = matches[2];
  1162. // var second = matches[3];
  1163. // var fraction = matches[4];
  1164. // var timezone = matches[5];
  1165. if (matches[1] > "23" || matches[2] > "59" || matches[3] > "59") {
  1166. return false;
  1167. }
  1168. return true;
  1169. },
  1170. "email": function (email) {
  1171. if (typeof email !== "string") {
  1172. return true;
  1173. }
  1174. return validator.isEmail(email, { "require_tld": true });
  1175. },
  1176. "hostname": function (hostname) {
  1177. if (typeof hostname !== "string") {
  1178. return true;
  1179. }
  1180. /*
  1181. http://json-schema.org/latest/json-schema-validation.html#anchor114
  1182. A string instance is valid against this attribute if it is a valid
  1183. representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
  1184. http://tools.ietf.org/html/rfc1034#section-3.5
  1185. <digit> ::= any one of the ten digits 0 through 9
  1186. var digit = /[0-9]/;
  1187. <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
  1188. var letter = /[a-zA-Z]/;
  1189. <let-dig> ::= <letter> | <digit>
  1190. var letDig = /[0-9a-zA-Z]/;
  1191. <let-dig-hyp> ::= <let-dig> | "-"
  1192. var letDigHyp = /[-0-9a-zA-Z]/;
  1193. <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
  1194. var ldhStr = /[-0-9a-zA-Z]+/;
  1195. <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
  1196. var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
  1197. <subdomain> ::= <label> | <subdomain> "." <label>
  1198. var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
  1199. <domain> ::= <subdomain> | " "
  1200. var domain = null;
  1201. */
  1202. var valid = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/.test(hostname);
  1203. if (valid) {
  1204. // the sum of all label octets and label lengths is limited to 255.
  1205. if (hostname.length > 255) { return false; }
  1206. // Each node has a label, which is zero to 63 octets in length
  1207. var labels = hostname.split(".");
  1208. for (var i = 0; i < labels.length; i++) { if (labels[i].length > 63) { return false; } }
  1209. }
  1210. return valid;
  1211. },
  1212. "host-name": function (hostname) {
  1213. return FormatValidators.hostname.call(this, hostname);
  1214. },
  1215. "ipv4": function (ipv4) {
  1216. if (typeof ipv4 !== "string") { return true; }
  1217. return validator.isIP(ipv4, 4);
  1218. },
  1219. "ipv6": function (ipv6) {
  1220. if (typeof ipv6 !== "string") { return true; }
  1221. return validator.isIP(ipv6, 6);
  1222. },
  1223. "regex": function (str) {
  1224. try {
  1225. RegExp(str);
  1226. return true;
  1227. } catch (e) {
  1228. return false;
  1229. }
  1230. },
  1231. "uri": function (uri) {
  1232. if (this.options.strictUris) {
  1233. return FormatValidators["strict-uri"].apply(this, arguments);
  1234. }
  1235. // https://github.com/zaggino/z-schema/issues/18
  1236. // RegExp from http://tools.ietf.org/html/rfc3986#appendix-B
  1237. return typeof uri !== "string" || RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?").test(uri);
  1238. },
  1239. "strict-uri": function (uri) {
  1240. return typeof uri !== "string" || validator.isURL(uri);
  1241. }
  1242. };
  1243. module.exports = FormatValidators;
  1244. },{"validator":6}],9:[function(require,module,exports){
  1245. "use strict";
  1246. var FormatValidators = require("./FormatValidators"),
  1247. Report = require("./Report"),
  1248. Utils = require("./Utils");
  1249. var JsonValidators = {
  1250. multipleOf: function (report, schema, json) {
  1251. // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.1.2
  1252. if (typeof json !== "number") {
  1253. return;
  1254. }
  1255. if (Utils.whatIs(json / schema.multipleOf) !== "integer") {
  1256. rep