var fetch=fetch||require('node-fetch');function jsref(a,b={}){function c(n){var[n,o]=n.split('#');o=o&&o.length?o:b.frag;var p=(b.find||m)(n).then(()=>o?d('#'+o,p):p);return b.deep?p.then(e):p}function d(n,o=a){if('#'!=n[0])return b.lazy?c(n):l.push(c(n));var p=n.substr(1).split(/[\.\/]/);for(p[0].length||p.shift();o&&p.length;)o=o[p.shift()];return o}function e(n={},o){if(n[g]&&(!b.keys||b.keys.includes(o))&&(!b.path||RegExp(b.path).test(n[g])))if(!h[n[g]])h[n[g]]=d(n[g]);else for(var p in n)'object'==typeof n[p]&&e(n[p],isNaN(p)?p:o);return n}function f(n={}){if(n[g])return f(h[n[g]])||n;for(var o in n)'object'==typeof n[o]&&(n[o]=f(n[o]));return n}if('object'!=typeof a)return a;var g=b.$ref||'$ref',h=b.refs||{},j=b.root||'http://localhost/',l=[],m=n=>fetch(n.indexOf('http')?j+n:n,b.http).then(o=>o.json());return e(a),b.lazy?f(a):Promise.all(l).then(n=>{for(var o in h)isNaN(h[o])||(h[o]=n[h[o]-1]);return f(a)})}'object'==typeof module&&(module.exports=jsref);