Skip to content
Snippets Groups Projects
index.umd.min.js 28.26 KiB
/*!
 * json-schema-faker v0.5.0-rc21
 * (c) Alvaro Cabrera <pateketrueke@gmail.com> (https://soypache.co)
 * Released under the MIT License.
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("json-schema-ref-parser"),require("jsonpath-plus")):"function"==typeof define&&define.amd?define(["json-schema-ref-parser","jsonpath-plus"],t):(e=e||self).JSONSchemaFaker=t(e.$RefParser,e.jsonpathPlus)}(this,function(e,t){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var r=function(){this.data={}};r.prototype.unregister=function(e){e?delete this.data[e]:this.data={}},r.prototype.register=function(e,t){this.data[e]=t},r.prototype.registerMany=function(e){var t=this;Object.keys(e).forEach(function(r){t.data[r]=e[r]})},r.prototype.get=function(e){return this.data[e]},r.prototype.list=function(){return this.data};var n={defaultInvalidTypeProduct:null,defaultRandExpMax:10,ignoreProperties:[],ignoreMissingRefs:!1,failOnInvalidTypes:!0,failOnInvalidFormat:!0,alwaysFakeOptionals:!1,optionalsProbability:!1,fixedProbabilities:!1,useExamplesValue:!1,useDefaultValue:!1,requiredOnly:!1,minItems:0,maxItems:null,minLength:0,maxLength:null,resolveJsonPath:!1,reuseProperties:!1,fillProperties:!0};n.random=Math.random;var i=new(function(e){function t(){e.call(this),this.data=Object.assign({},n),this._defaults=n}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var r={defaults:{configurable:!0}};return r.defaults.get=function(){return Object.assign({},this._defaults)},Object.defineProperties(t.prototype,r),t}(r));function a(e,t){return"string"==typeof e?void 0!==t?i.register(e,t):i.get(e):i.registerMany(e)}a.getDefaults=function(){return i.defaults};var o={ALL_TYPES:["array","object","integer","number","string","boolean","null"],MIN_NUMBER:-100,MAX_NUMBER:100,MIN_INTEGER:-1e8,MAX_INTEGER:1e8,MOST_NEAR_DATETIME:2524608e6};var s={ROOT:0,GROUP:1,POSITION:2,SET:3,RANGE:4,REPETITION:5,REFERENCE:6,CHAR:7};const u=()=>[{type:s.RANGE,from:48,to:57}],c=()=>[{type:s.CHAR,value:95},{type:s.RANGE,from:97,to:122},{type:s.RANGE,from:65,to:90}].concat(u()),l=()=>[{type:s.CHAR,value:9},{type:s.CHAR,value:10},{type:s.CHAR,value:11},{type:s.CHAR,value:12},{type:s.CHAR,value:13},{type:s.CHAR,value:32},{type:s.CHAR,value:160},{type:s.CHAR,value:5760},{type:s.RANGE,from:8192,to:8202},{type:s.CHAR,value:8232},{type:s.CHAR,value:8233},{type:s.CHAR,value:8239},{type:s.CHAR,value:8287},{type:s.CHAR,value:12288},{type:s.CHAR,value:65279}],f=()=>[{type:s.CHAR,value:10},{type:s.CHAR,value:13},{type:s.CHAR,value:8232},{type:s.CHAR,value:8233}];var h,p=()=>({type:s.SET,set:c(),not:!1}),m=()=>({type:s.SET,set:c(),not:!0}),d=()=>({type:s.SET,set:u(),not:!1}),g=()=>({type:s.SET,set:u(),not:!0}),y=()=>({type:s.SET,set:l(),not:!1}),v=()=>({type:s.SET,set:l(),not:!0}),x=()=>({type:s.SET,set:f(),not:!0}),b=(function(e,t){const r={0:0,t:9,n:10,v:11,f:12,r:13};t.strToChars=function(e){return e=e.replace(/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g,function(e,t,n,i,a,o,s,u){if(n)return e;var c=t?8:i?parseInt(i,16):a?parseInt(a,16):o?parseInt(o,8):s?"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?".indexOf(s):r[u],l=String.fromCharCode(c);return/[[\]{}^$.|?*+()]/.test(l)&&(l="\\"+l),l})},t.tokenizeClass=((e,r)=>{for(var n,i,a=[],o=/\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g;null!=(n=o.exec(e));)if(n[1])a.push(p());else if(n[2])a.push(d());else if(n[3])a.push(y());else if(n[4])a.push(m());else if(n[5])a.push(g());else if(n[6])a.push(v());else if(n[7])a.push({type:s.RANGE,from:(n[8]||n[9]).charCodeAt(0),to:n[10].charCodeAt(0)});else{if(!(i=n[12]))return[a,o.lastIndex];a.push({type:s.CHAR,value:i.charCodeAt(0)})}t.error(r,"Unterminated character class")}),t.error=((e,t)=>{throw new SyntaxError("Invalid regular expression: /"+e+"/: "+t)})}(h={exports:{}},h.exports),h.exports),O=(b.strToChars,b.tokenizeClass,b.error,()=>({type:s.POSITION,value:"b"})),w=()=>({type:s.POSITION,value:"B"}),E=()=>({type:s.POSITION,value:"^"}),A=()=>({type:s.POSITION,value:"$"}),k=e=>{var t,r,n=0,i={type:s.ROOT,stack:[]},a=i,o=i.stack,u=[],c=t=>{b.error(e,`Nothing to repeat at column ${t-1}`)},l=b.strToChars(e);for(t=l.length;n<t;)switch(r=l[n++]){case"\\":switch(r=l[n++]){case"b":o.push(O());break;case"B":o.push(w());break;case"w":o.push(p());break;case"W":o.push(m());break;case"d":o.push(d());break;case"D":o.push(g());break;case"s":o.push(y());break;case"S":o.push(v());break;default:/\d/.test(r)?o.push({type:s.REFERENCE,value:parseInt(r,10)}):o.push({type:s.CHAR,value:r.charCodeAt(0)})}break;case"^":o.push(E());break;case"$":o.push(A());break;case"[":var f;"^"===l[n]?(f=!0,n++):f=!1;var h=b.tokenizeClass(l.slice(n),e);n+=h[1],o.push({type:s.SET,set:h[0],not:f});break;case".":o.push(x());break;case"(":var k={type:s.GROUP,stack:[],remember:!0};"?"===(r=l[n])&&(r=l[n+1],n+=2,"="===r?k.followedBy=!0:"!"===r?k.notFollowedBy=!0:":"!==r&&b.error(e,`Invalid group, character '${r}'`+` after '?' at column ${n-1}`),k.remember=!1),o.push(k),u.push(a),a=k,o=k.stack;break;case")":0===u.length&&b.error(e,`Unmatched ) at column ${n-1}`),o=(a=u.pop()).options?a.options[a.options.length-1]:a.stack;break;case"|":a.options||(a.options=[a.stack],delete a.stack);var I=[];a.options.push(I),o=I;break;case"{":var R,P,M=/^(\d+)(,(\d+)?)?\}/.exec(l.slice(n));null!==M?(0===o.length&&c(n),R=parseInt(M[1],10),P=M[2]?M[3]?parseInt(M[3],10):1/0:R,n+=M[0].length,o.push({type:s.REPETITION,min:R,max:P,value:o.pop()})):o.push({type:s.CHAR,value:123});break;case"?":0===o.length&&c(n),o.push({type:s.REPETITION,min:0,max:1,value:o.pop()});break;case"+":0===o.length&&c(n),o.push({type:s.REPETITION,min:1,max:1/0,value:o.pop()});break;case"*":0===o.length&&c(n),o.push({type:s.REPETITION,min:0,max:1/0,value:o.pop()});break;default:o.push({type:s.CHAR,value:r.charCodeAt(0)})}return 0!==u.length&&b.error(e,"Unterminated group"),i};class I{constructor(e,t){this.low=e,this.high=t,this.length=1+t-e}overlaps(e){return!(this.high<e.low||this.low>e.high)}touches(e){return!(this.high+1<e.low||this.low-1>e.high)}add(e){return new I(Math.min(this.low,e.low),Math.max(this.high,e.high))}subtract(e){return e.low<=this.low&&e.high>=this.high?[]:e.low>this.low&&e.high<this.high?[new I(this.low,e.low-1),new I(e.high+1,this.high)]:e.low<=this.low?[new I(e.high+1,this.high)]:[new I(this.low,e.low-1)]}toString(){return this.low==this.high?this.low.toString():this.low+"-"+this.high}}class R{constructor(e,t){this.ranges=[],this.length=0,null!=e&&this.add(e,t)}_update_length(){this.length=this.ranges.reduce((e,t)=>e+t.length,0)}add(e,t){var r=e=>{for(var t=0;t<this.ranges.length&&!e.touches(this.ranges[t]);)t++;for(var r=this.ranges.slice(0,t);t<this.ranges.length&&e.touches(this.ranges[t]);)e=e.add(this.ranges[t]),t++;r.push(e),this.ranges=r.concat(this.ranges.slice(t)),this._update_length()};return e instanceof R?e.ranges.forEach(r):(null==t&&(t=e),r(new I(e,t))),this}subtract(e,t){var r=e=>{for(var t=0;t<this.ranges.length&&!e.overlaps(this.ranges[t]);)t++;for(var r=this.ranges.slice(0,t);t<this.ranges.length&&e.overlaps(this.ranges[t]);)r=r.concat(this.ranges[t].subtract(e)),t++;this.ranges=r.concat(this.ranges.slice(t)),this._update_length()};return e instanceof R?e.ranges.forEach(r):(null==t&&(t=e),r(new I(e,t))),this}intersect(e,t){var r=[],n=e=>{for(var t=0;t<this.ranges.length&&!e.overlaps(this.ranges[t]);)t++;for(;t<this.ranges.length&&e.overlaps(this.ranges[t]);){var n=Math.max(this.ranges[t].low,e.low),i=Math.min(this.ranges[t].high,e.high);r.push(new I(n,i)),t++}};return e instanceof R?e.ranges.forEach(n):(null==t&&(t=e),n(new I(e,t))),this.ranges=r,this._update_length(),this}index(e){for(var t=0;t<this.ranges.length&&this.ranges[t].length<=e;)e-=this.ranges[t].length,t++;return this.ranges[t].low+e}toString(){return"[ "+this.ranges.join(", ")+" ]"}clone(){return new R(this)}}var P=R;const M=k.types=s;var _=class e{constructor(e,t){if(this._setDefaults(e),e instanceof RegExp)this.ignoreCase=e.ignoreCase,this.multiline=e.multiline,e=e.source;else{if("string"!=typeof e)throw new Error("Expected a regexp or string");this.ignoreCase=t&&-1!==t.indexOf("i"),this.multiline=t&&-1!==t.indexOf("m")}this.tokens=k(e)}_setDefaults(t){this.max=null!=t.max?t.max:null!=e.prototype.max?e.prototype.max:100,this.defaultRange=t.defaultRange?t.defaultRange:this.defaultRange.clone(),t.randInt&&(this.randInt=t.randInt)}gen(){return this._gen(this.tokens,[])}_gen(e,t){var r,n,i,a,o;switch(e.type){case M.ROOT:case M.GROUP:if(e.followedBy||e.notFollowedBy)return"";for(e.remember&&void 0===e.groupNumber&&(e.groupNumber=t.push(null)-1),n="",a=0,o=(r=e.options?this._randSelect(e.options):e.stack).length;a<o;a++)n+=this._gen(r[a],t);return e.remember&&(t[e.groupNumber]=n),n;case M.POSITION:return"";case M.SET:var s=this._expand(e);return s.length?String.fromCharCode(this._randSelect(s)):"";case M.REPETITION:for(i=this.randInt(e.min,e.max===1/0?e.min+this.max:e.max),n="",a=0;a<i;a++)n+=this._gen(e.value,t);return n;case M.REFERENCE:return t[e.value-1]||"";case M.CHAR:var u=this.ignoreCase&&this._randBool()?this._toOtherCase(e.value):e.value;return String.fromCharCode(u)}}_toOtherCase(e){return e+(97<=e&&e<=122?-32:65<=e&&e<=90?32:0)}_randBool(){return!this.randInt(0,1)}_randSelect(e){return e instanceof P?e.index(this.randInt(0,e.length-1)):e[this.randInt(0,e.length-1)]}_expand(e){if(e.type===k.types.CHAR)return new P(e.value);if(e.type===k.types.RANGE)return new P(e.from,e.to);{let t=new P;for(let r=0;r<e.set.length;r++){let n=this._expand(e.set[r]);if(t.add(n),this.ignoreCase)for(let e=0;e<n.length;e++){let r=n.index(e),i=this._toOtherCase(r);r!==i&&t.add(i)}}return e.not?this.defaultRange.clone().subtract(t):this.defaultRange.clone().intersect(t)}}randInt(e,t){return e+Math.floor(Math.random()*(1+t-e))}get defaultRange(){return this._range=this._range||new P(32,126)}set defaultRange(e){this._range=e}static randexp(t,r){var n;return"string"==typeof t&&(t=new RegExp(t,r)),void 0===t._randexp?(n=new e(t,r),t._randexp=n):(n=t._randexp)._setDefaults(t),n.gen()}static sugar(){RegExp.prototype.gen=function(){return e.randexp(this)}}};function j(e,t,r,n,i){return void 0===i&&(i=!1),r=void 0===r?o.MIN_NUMBER:r,n=void 0===n?o.MAX_NUMBER:n,(t=void 0===t?n:t)<(e=void 0===e?r:e)&&(t+=e),i?function(e,t){return a("random")()*(t-e)+e}(e,t):function(e,t){return e=void 0===e?o.MIN_INTEGER:e,t=void 0===t?o.MAX_INTEGER:t,Math.floor(a("random")()*(t-e+1))+e}(e,t)}var T={pick:function(e){return e[Math.floor(a("random")()*e.length)]},date:function(e){if(e)return function(e){switch(e){case"seconds":return 60*j(0,60);case"minutes":return 612*j(15,50);case"hours":return 36123*j(12,72);case"days":return 86412345*j(7,30);case"weeks":return 604812345*j(4,52);case"months":return 2592012345*j(2,13);case"years":return 31104012345*j(1,20)}}(e);var t=new Date,r=j(-1e3,o.MOST_NEAR_DATETIME);return t.setTime(t.getTime()-r),t},shuffle:function(e){for(var t,r,n=e.length,i=e.slice();n>0;)r=Math.floor(a("random")()*n),t=i[n-=1],i[n]=i[r],i[r]=t;return i},number:j,randexp:function(e){return _.prototype.max=a("defaultRandExpMax"),_.prototype.randInt=function(e,t){return e+Math.floor(a("random")()*(t-e+1))},new _(e).gen()}};function S(e,t){return Object.keys(t).forEach(function(r){"object"!=typeof t[r]||null===t[r]?e[r]=t[r]:Array.isArray(t[r])?(e[r]=e[r]||[],t[r].forEach(function(t){-1===e[r].indexOf(t)&&e[r].push(t)})):"object"!=typeof e[r]||null===e[r]||Array.isArray(e[r])?e[r]=S({},t[r]):e[r]=S(e[r],t[r])}),e}function C(){return T.pick([!1,!0,null,-1,NaN,Math.PI,1/0,void 0,[],{},Math.random(),Math.random().toString(36).substr(2)])}var N={getSubAttribute:function(e,t){for(var r=t.split(".");r.length;){var n=r.shift();if(!e[n])break;e=e[n]}return e},hasProperties:function(e){for(var t=[],r=arguments.length-1;r-- >0;)t[r]=arguments[r+1];return t.filter(function(t){return void 0!==e[t]}).length>0},omitProps:function(e,t){var r={};return Object.keys(e).forEach(function(n){-1===t.indexOf(n)&&(Array.isArray(e[n])?r[n]=e[n].slice():r[n]=e[n]instanceof Object?S({},e[n]):e[n])}),r},typecast:function(e,t,r){var n={};switch(e||t.type){case"integer":case"number":if(void 0!==t.minimum&&(n.minimum=t.minimum),void 0!==t.maximum&&(n.maximum=t.maximum),t.enum){var i=Math.max(n.minimum||0,0),o=Math.min(n.maximum||1/0,1/0);t.exclusiveMinimum&&i===t.minimum&&(i+=t.multipleOf||1),t.exclusiveMaximum&&o===t.maximum&&(o-=t.multipleOf||1),(i||o!==1/0)&&(t.enum=t.enum.filter(function(e){return e>=i&&e<=o}))}break;case"string":void 0!==t.minLength&&(n.minLength=t.minLength),void 0!==t.maxLength&&(n.maxLength=t.maxLength);var s=a("maxLength"),u=a("minLength");s&&n.maxLength>s&&(n.maxLength=s),u&&n.minLength<u&&(n.minLength=u)}var c=r(n);switch(e||t.type){case"number":c=parseFloat(c);break;case"integer":c=parseInt(c,10);break;case"boolean":c=!!c;break;case"string":c=String(c);for(var l=Math.max(n.minLength||0,0),f=Math.min(n.maxLength||1/0,1/0);c.length<l;)t.pattern?c+=T.randexp(t.pattern):c+=""+T.pick([" ","/","_","-","+","=","@","^"])+c;switch(c.length>f&&(c=c.substr(0,f)),t.format){case"date-time":case"datetime":c=new Date(c).toISOString().replace(/([0-9])0+Z$/,"$1Z");break;case"date":c=new Date(c).toISOString().substr(0,10);break;case"time":c=new Date("1969-01-01 "+c).toISOString().substr(11)}}return c},merge:S,clone:function e(t){return t&&"object"==typeof t?Array.isArray(t)?t.map(function(t){return e(t)}):Object.keys(t).reduce(function(r,n){return r[n]=e(t[n]),r},{}):t},short:function(e){var t=JSON.stringify(e),r=JSON.stringify(e,null,2);return t.length>400?r.substr(0,400)+"...":r},notValue:function(e,t){var r=S({},t);if(void 0!==e.minimum&&(r.maximum=e.minimum,r.exclusiveMaximum=!0),void 0!==e.maximum&&(r.minimum=e.maximum>r.maximum?0:e.maximum,r.exclusiveMinimum=!0),void 0!==e.minLength&&(r.maxLength=e.minLength),void 0!==e.maxLength&&(r.minLength=e.maxLength>r.maxLength?0:e.maxLength),e.type)r.type=T.pick(o.ALL_TYPES.filter(function(t){return(Array.isArray(e.type)?e.type:[e.type]).every(function(e){return"number"===t||"integer"===t?"number"!==e&&"integer"!==e:t!==e})}));else if(e.enum){var n;do{n=C()}while(-1!==e.enum.indexOf(n));r.enum=[n]}return e.required&&r.properties&&e.required.forEach(function(e){delete r.properties[e]}),r},anyValue:C,validate:function(e,t){return!t.every(function(t){return void 0!==t.minimum&&e>=t.minimum||void 0!==t.maximum&&e<=t.maximum})},isKey:function(e){return-1!==["enum","const","default","examples","required","definitions"].indexOf(e)},template:function e(t,r){return Array.isArray(t)?t.map(function(t){return e(t,r)}):("string"==typeof t&&(t=t.replace(/#\{([\w.-]+)\}/g,function(e,t){return r[t]})),t)}};var L=function(){this.registry={},this.support={}};L.prototype.reset=function(e){e?(delete this.registry[e],delete this.support[e]):(this.registry={},this.support={})},L.prototype.extend=function(e,t){var r,n=this;this.registry[e]=t(this.registry[e]),this.support[e]||(this.support[e]=(r=function(){return n.registry[e]},function(e,t,n,i){var a=e,o=[];"object"==typeof e&&(a=Object.keys(e)[0],Array.isArray(e[a])?o=e[a]:o.push(e[a]));for(var s=a.split("."),u=r();s.length>1;)u=u[s.shift()];return"function"==typeof(e="object"==typeof u?u[s[0]]:u)&&(e=e.apply(u,o.map(function(e){return N.template(e,i)}))),"[object Object]"===Object.prototype.toString.call(e)&&Object.keys(e).forEach(function(t){if("function"==typeof e[t])throw new Error("Cannot resolve value for '"+n+": "+a+"', given: "+e)}),e}))},L.prototype.define=function(e,t){this.support[e]=t},L.prototype.get=function(e){if(void 0===this.registry[e])throw new ReferenceError("'"+e+"' dependency doesn't exist.");return this.registry[e]},L.prototype.wrap=function(e){for(var t=this,r=Object.keys(e),n={},i=r.length,a=function(){var a=r[i].replace(/^x-/,""),o=t.support[a];if("function"==typeof o)return Object.defineProperty(e,"generate",{configurable:!1,enumerable:!1,writable:!1,value:function(t){return o.call(n,e[r[i]],e,r[i],t)}}),"break"};i--;){if("break"===a())break}return e};var H=new r;function $(e,t){if(void 0===e)return H.list();if("string"==typeof e)if("function"==typeof t)H.register(e,t);else{if(null!==t&&!1!==t)return H.get(e);H.unregister(e)}else H.registerMany(e)}var q=function(e){function t(t,r){e.call(this),e.captureStackTrace&&e.captureStackTrace(this,this.constructor),this.name="ParseError",this.message=t,this.path=r}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t}(Error),F={array:["additionalItems","items","maxItems","minItems","uniqueItems"],integer:["exclusiveMaximum","exclusiveMinimum","maximum","minimum","multipleOf"],object:["additionalProperties","dependencies","maxProperties","minProperties","patternProperties","properties","required"],string:["maxLength","minLength","pattern","format"]};F.number=F.integer;var D=["additionalItems","items","additionalProperties","dependencies","patternProperties","properties"];function G(e,t,r){return Object.keys(e).filter(function(e){var n=D.indexOf(t)>-1;return!(!(r.indexOf(e)>-1)||n)}).length>0}var z=function(){return a("random")()>.5};var B=function(){return null};function U(e){var t=void 0===e.minimum?o.MIN_INTEGER:e.minimum,r=void 0===e.maximum?o.MAX_INTEGER:e.maximum,n=e.multipleOf;if(n&&(r=Math.floor(r/n)*n,t=Math.ceil(t/n)*n),e.exclusiveMinimum&&t===e.minimum&&(t+=n||1),e.exclusiveMaximum&&r===e.maximum&&(r-=n||1),t>r)return NaN;if(n){if(-1===String(n).indexOf(".")){for(var i=T.number(Math.floor(t/n),Math.floor(r/n))*n;i<t;)i+=e.multipleOf;return i}var a,s,u=(r-t)/n;do{s=(a=T.number(0,u)*n)/n%1}while(0!==s);return a}return T.number(t,r,void 0,void 0,!0)}var Z="Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore\net dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea\ncommodo consequat Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\npariatur Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est\nlaborum".split(/\W/);function J(e){return T.shuffle(Z).slice(0,e)}var V={type:["string","number","integer","boolean"]};function X(){return J(T.number(1,5)).join(" ")}function W(e,t){void 0===e&&(e=0),void 0===t&&(t=140);for(var r=Math.max(0,e),n=T.number(r,t),i=X();i.length<r;)i+=X();return i.length>n&&(i=i.substr(0,n)),i}function K(){return T.date().toISOString()}var Y="https?://{hostname}(?:[a-zA-Z][a-zA-Z0-9+-.]*)+",Q={email:"[a-zA-Z\\d][a-zA-Z\\d-]{1,13}[a-zA-Z\\d]@{hostname}",hostname:"[a-zA-Z]{1,33}\\.[a-z]{2,4}",ipv6:"[a-f\\d]{4}(:[a-f\\d]{4}){7}",uri:Y,slug:"[a-zA-Z\\d_-]+","uri-reference":Y+"(?:\\?([a-z]{1,7}(=\\w{1,5})?&){0,3})?","uri-template":Y.replace("(?:","(?:/\\{[a-z][:a-zA-Z0-9-]*\\}|"),"json-pointer":"(/(?:"+"[a-zA-Z][a-zA-Z0-9+-.]*".replace("]*","/]*")+"|~[01]))+",uuid:"[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$"};Q.iri=Q["uri-reference"],Q["iri-reference"]=Q["uri-reference"],Q["idn-email"]=Q.email,Q["idn-hostname"]=Q.hostname;var ee=new RegExp("\\{("+Object.keys(Q).join("|")+")\\}");function te(e,t){var r,n=$(e.format);if("function"==typeof n)return n(e);switch(e.format){case"date-time":case"datetime":return K();case"date":return K().slice(0,10);case"time":return K().slice(11);case"ipv4":return[0,0,0,0].map(function(){return T.number(0,255)}).join(".");case"regex":return".+?";case"email":case"hostname":case"ipv6":case"uri":case"uri-reference":case"iri":case"iri-reference":case"idn-email":case"idn-hostname":case"json-pointer":case"slug":case"uri-template":case"uuid":return r=e.format,T.randexp(Q[r]).replace(ee,function(e,t){return T.randexp(Q[t])});default:if(void 0===n){if(a("failOnInvalidFormat"))throw new Error("unknown registry key "+N.short(e.format));return t()}throw new Error("unsupported format '"+e.format+"'")}}var re={boolean:z,null:B,array:function(e,t,r,n){var i=[];if(!e.items&&!e.additionalItems){if(N.hasProperties(e,"minItems","maxItems","uniqueItems"))throw new q("missing items for "+N.short(e),t);return i}if(Array.isArray(e.items))return e.items.map(function(e,i){var a=t.concat(["items",i]);return n(e,a,r)});var o=e.minItems,s=e.maxItems;a("minItems")&&(o=s?Math.min(a("minItems"),s):a("minItems")),a("maxItems")&&(s&&s>a("maxItems")&&(s=a("maxItems")),o&&o>a("maxItems")&&(o=s));var u=!0===a("alwaysFakeOptionals")?1:a("optionalsProbability"),c=a("alwaysFakeOptionals")||a("fixedProbabilities")||!1,l=T.number(o,s,1,5);!1!==u&&(l=Math.max(c?Math.round((s||l)*u):Math.abs(T.number(o,s)*u),o||0));for(var f="object"==typeof e.additionalItems?e.additionalItems:{},h=i.length;h<l;h+=1){var p=t.concat(["items",h]),m=n(e.items||f,p,r);i.push(m)}return e.uniqueItems?function(e,t,r,n,i,a){var o=[],s=[];function u(e){var t=JSON.stringify(e);return-1===s.indexOf(t)&&(s.push(t),o.push(e),!0)}t.forEach(u);for(var c=100;o.length!==t.length&&(u(a(r.items||n,e,i))||(c-=1),c););return o}(t.concat(["items"]),i,e,f,r,n):i},integer:function(e){return U(Object.assign({multipleOf:1},e))},number:U,object:function(e,t,r,n){var i={},o=e.properties||{},s=e.patternProperties||{},u="boolean"==typeof e.required?[]:(e.required||[]).slice(),c=!1!==e.additionalProperties,l=Object.keys(o),f=Object.keys(s),h=l.concat(f).reduce(function(e,t){return-1===u.indexOf(t)&&e.push(t),e},[]),p=u.concat(h),m=c&&!0===e.additionalProperties?V:e.additionalProperties;if(!c&&0===l.length&&0===f.length&&N.hasProperties(e,"minProperties","maxProperties","dependencies","required"))return{};if(!0===a("requiredOnly"))return u.forEach(function(e){o[e]&&(i[e]=o[e])}),n(i,t.concat(["properties"]),r);var d=!0===a("alwaysFakeOptionals")?1:a("optionalsProbability"),g=a("alwaysFakeOptionals")||a("fixedProbabilities")||!1,y=a("ignoreProperties")||[],v=Math.max(e.minProperties||0,u.length),x=e.maxProperties||p.length+T.number(1,5),b=Math.max(0,v-u.length);1!==p.length||u.length||(b=T.number(b,p.length+(p.length-v))),!1!==d&&(b=!0===g?Math.round(v-u.length+d*(p.length-v)):T.number(v-u.length,d*(p.length-v)));var O=T.shuffle(h).slice(0,b),w=h.filter(function(e){return-1!==O.indexOf(e)}),E=u.concat(w).slice(0,x),A=[];if(e.dependencies&&(Object.keys(e.dependencies).forEach(function(t){var r=e.dependencies[t];-1!==E.indexOf(t)&&(Array.isArray(r)?r.forEach(function(e){-1===E.indexOf(e)&&E.push(e)}):A.push(r))}),A.length))return delete e.dependencies,n({allOf:A.concat(e)},t.concat(["properties"]),r);var k=[];E.forEach(function(e){for(var t=0;t<y.length;t+=1)if(y[t]instanceof RegExp&&y[t].test(e)||"string"==typeof y[t]&&y[t]===e||"function"==typeof y[t]&&y[t](o[e],e))return void k.push(e);var r;if(!1===m?-1!==u.indexOf(e)&&(i[e]=o[e]):o[e]&&(i[e]=o[e]),f.forEach(function(t){e.match(new RegExp(t))&&(r=!0,i[e]?N.merge(i[e],s[t]):i[T.randexp(e)]=s[t])}),!r){var n=s[e]||m;n&&!1!==m&&(i[s[e]?T.randexp(e):e]=o[e]||n)}});var I=a("fillProperties"),R=a("reuseProperties"),P=Object.keys(i).length+(I?0:k.length),M=function(e){return T.randexp("_?[_a-f\\d]{1,3}"+(e?"\\$?":""))};function _(){var e;do{e=u.shift()}while(i[e]);return e}for(;I&&(f.length||c)&&!(P>=v);){if(c)if(R&&l.length-P>v){var j=0,S=void 0;do{if((j+=1)>1e3)break;S=_()||T.pick(l)}while(void 0!==i[S]);void 0===i[S]&&(i[S]=o[S],P+=1)}else if(f.length&&!m){var C=T.pick(f),L=T.randexp(C);i[L]||(i[L]=s[C],P+=1)}else{var H=_()||J(1)+M();i[H]||(i[H]=m||V,P+=1)}for(var $=0;P<v&&$<f.length;$+=1){var q=f[$],F=T.randexp(q);i[F]||(i[F]=s[q],P+=1)}}for(var D=T.number(v,x);P<D&&m;){var G=J(1)+M(!0);i[G]||(i[G]=m,P+=1)}return n(i,t.concat(["properties"]),r)},string:function(e){return N.typecast("string",e,function(t){return e.format?te(e,function(){return W(t.minLength,t.maxLength)}):e.pattern?T.randexp(e.pattern):W(t.minLength,t.maxLength)})}};function ne(e,t,r,n){if(e=r(e,void 0,t)){if("properties"!==t[t.length-1]){if(a("useExamplesValue")&&Array.isArray(e.examples)){var i=e.examples.concat("default"in e?[e.default]:[]);return N.typecast(null,e,function(){return T.pick(i)})}if(a("useDefaultValue")&&"default"in e)return e.default;if("template"in e)return N.template(e.template,n)}if(e.not&&"object"==typeof e.not&&(e=N.notValue(e.not,N.omitProps(e,["not"]))),"const"in e)return e.const;if(Array.isArray(e.enum))return N.typecast(null,e,function(){return T.pick(e.enum)});if("function"==typeof e.thunk)return ne(e.thunk(),t,r);if("function"==typeof e.generate)return N.typecast(null,e,function(){return e.generate(n)});var o=e.type;if(Array.isArray(o)?o=T.pick(o):void 0===o&&(o=function(e,t){for(var r=Object.keys(F),n=0;n<r.length;n+=1){var i=r[n];if(G(e,t[t.length-1],F[i]))return i}}(e,t)||o)&&(e.type=o),"string"==typeof o){if(!re[o]){if(a("failOnInvalidTypes"))throw new q("unknown primitive "+N.short(o),t.concat(["type"]));return a("defaultInvalidTypeProduct")}try{return re[o](e,t,r,ne)}catch(e){if(void 0===e.path)throw new q(e.stack,t);throw e}}var s={};return Array.isArray(e)&&(s=[]),Object.keys(e).forEach(function(n){"object"==typeof e[n]&&"definitions"!==n?s[n]=ne(e[n],t.concat([n]),r,s):s[n]=e[n]}),s}}function ie(e,r,n,i){if(!e||"object"!=typeof e)return e;if(n||(n={}),r||(r=e),Array.isArray(e))return e.map(function(e){return ie(e,r,n,i)});if(e.jsonPath){var a="object"!=typeof e.jsonPath?{path:e.jsonPath}:e.jsonPath;a.group=e.group||a.group||i,a.cycle=e.cycle||a.cycle||!1,a.reverse=e.reverse||a.reverse||!1,a.count=e.count||a.count||1;var o=a.group+"__"+a.path;return n[o]||(a.count>1?n[o]=t.JSONPath(a.path,r).slice(0,a.count):n[o]=t.JSONPath(a.path,r)),a.cycle||a.reverse?function(e,t){if(!Array.isArray(e))return e;var r=t?e.pop():e.shift();return t?e.unshift(r):e.push(r),r}(n[o],a.reverse):function(e){return Array.isArray(e)?T.pick(e):e}(n[o])}return Object.keys(e).forEach(function(t){e[t]=ie(e[t],r,n,t)}),e}function ae(e,t,r){try{var n=ne(N.clone(t),[],function n(i,o,s){if(void 0===o&&(o=T.number(1,3)),!i)return null;if("function"==typeof i.generate)return i;if("string"==typeof(i.$id||i.id)&&(delete i.id,delete i.$id,delete i.$schema),"string"==typeof i.$ref){if("#"===i.$ref)return delete i.$ref,i;var u;if(-1===i.$ref.indexOf("#/")&&(u=e[i.$ref]||null),0===i.$ref.indexOf("#/definitions/")&&(u=t.definitions[i.$ref.split("#/definitions/")[1]]||null),void 0!==u){if(!u&&!0!==a("ignoreMissingRefs"))throw new Error("Reference not found: "+i.$ref);N.merge(i,u||{})}return delete i.$ref,i}if(Array.isArray(i.allOf)){var c=i.allOf;delete i.allOf,c.forEach(function(e){var t=n(e,o+1,s);N.merge(i,"function"==typeof t.thunk?t.thunk():t)})}if(Array.isArray(i.oneOf||i.anyOf)){var l=i.oneOf||i.anyOf;return i.enum&&i.oneOf&&(i.enum=i.enum.filter(function(e){return N.validate(e,l)})),{thunk:function(){var e=N.omitProps(i,["anyOf","oneOf"]),t=T.pick(l);return N.merge(e,t),i.oneOf&&l.forEach(function(r){r!==t&&r.required&&r.required.filter(function(e){return!t.required.includes(e)}).forEach(function(t){delete e.properties[t]})}),e}}}if(Object.keys(i).forEach(function(e){!Array.isArray(i[e])&&"object"!=typeof i[e]||N.isKey(e)||(i[e]=n(i[e],o,s.concat(e)))}),s){var f=s[s.length-1];if("properties"===f||"items"===f)return i}return r.wrap(i)});return a("resolveJsonPath")?ie(n):n}catch(e){throw e.path?new Error(e.message+" in /"+e.path.join("/")):e}}var oe=new L;function se(){oe.define("pattern",T.randexp),oe.define("autoIncrement",function(e,t){if(!this.offset){var r=t.minimum||1,n=r+o.MAX_NUMBER,i=e.initialOffset||t.initialOffset;this.offset=i||T.number(r,n)}return!0===e?this.offset++:t}),oe.define("sequentialDate",function(e,t){if(this.now||(this.now=T.date()),e){if(t=this.now.toISOString(),-1===["seconds","minutes","hours","days","weeks","months","years"].indexOf(e=!0===e?"days":e))throw new Error("Unsupported increment by "+N.short(e));this.now.setTime(this.now.getTime()+T.date(e))}return t})}function ue(e){var t={};return Array.isArray(e)?e.forEach(function(e){t[e.$id||e.id]=e}):t=e||{},t}var ce=function(e,t,r){return console.log("[json-schema-faker] calling JsonSchemaFaker() is deprecated, call either .generate() or .resolve()"),r&&console.log("[json-schema-faker] references are only supported by calling .resolve()"),ce.generate(e,t)};return ce.generate=function(e,t){return ae(ue(t),e,oe)},ce.resolve=function(t,r,n){"string"==typeof r&&(n=r,r={}),n=(n=n||("undefined"!=typeof process?process.cwd():"")).replace(/\/+$/,"")+"/";var i=ue(r),a={order:300,canRead:!0,read:function(e,t){try{t(null,i[e.url]||i[e.url.split("/").pop()])}catch(e){t(e)}}};return e.dereference(n,t,{resolve:{file:{order:100},http:{order:200},fixedRefs:a},dereference:{circular:"ignore"}}).then(function(e){return ae(i,e,oe)})},se(),ce.format=$,ce.option=a,ce.random=T,ce.extend=function(e,t){return oe.extend(e,t),ce},ce.define=function(e,t){return oe.define(e,t),ce},ce.reset=function(e){return oe.reset(e),se(),ce},ce.locate=function(e){return oe.get(e)},ce.version="0.5.0-rc21",ce});
//# sourceMappingURL=index.umd.min.js.map