UNPKG

12.7 kBJavaScriptView Raw
1/*!
2 * async-af/esm/min v7.0.39
3 *
4 * AsyncAF (The asynciest of async libs there ever was or ever will be...AsyncAF!?)
5 * (https://async-af.js.org/AsyncAF)
6 *
7 * Copyright (c) 2017-present, Scott Rudiger (https://github.com/ScottRudiger)
8 *
9 * This source code is licensed under the MIT license found in this library's
10 * GitHub repository (https://github.com/AsyncAF/AsyncAF/blob/master/LICENSE).
11 */
12function t(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function e(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}const n=function(t,e){return Object.defineProperty(t,"name",{value:e,configurable:!0})},r=t=>{const{name:e}=t,r=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return new t(...n)};return r.prototype=t.prototype,Object.setPrototypeOf(r,t),r.prototype.constructor=r,n(r,e)},o=new WeakMap,i={inSeries:{get(){return o.get(this)}},series:{get(){return o.set(this,!this.inSeries),this}},io:{get(){return this.series}}},c=new WeakMap;class a{constructor(t){c.set(this,Promise.resolve(t))}then(t,e){return this.constructor(c.get(this).then(t,e))}catch(t){return this.then(null,t)}finally(t){return c.get(this).finally(t)}}function l(){const t=e(["/"]);return l=function(){return t},t}function s(){const t=e(["/"]);return s=function(){return t},t}function u(){const t=e(["/"]);return u=function(){return t},t}function f(){const t=e([":"]);return f=function(){return t},t}function h(){const t=e(["/"]);return h=function(){return t},t}function y(){const t=e(["/"]);return y=function(){return t},t}function p(){const t=e(["/"]);return p=function(){return t},t}function d(){const t=e(["\n"],["\\n"]);return d=function(){return t},t}a.use=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"!=typeof t)throw TypeError("prototypeMethods param accepts an Object containing the prototypeMethods you'd like to add to the AsyncAF prototype, or an empty Object");if("object"!=typeof e)throw TypeError("staticMethods param accepts an Object containing the staticMethods you'd like to add to AsyncAF");Object.assign(this.prototype,t),Object.assign(this,e)},Object.defineProperties(a.prototype,function(e){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.forEach(function(n){t(e,n,r[n])})}return e}({},i,{[Symbol.toStringTag]:{value:"AsyncAF"}})),r(class extends a{});const b=function t(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];t.label&&n.unshift(t.setFormat(t.labelFormat));const o=Date.now();return Promise.all(n).then(e=>{if(t.duration){const t=((Date.now()-o)/1e3).toFixed(3);e.push("\n in ".concat(t," secs"))}t.wrappedLog("",...e)})};Object.defineProperties(b,{wrappedLog:{value:function(){console&&console.log&&console.log(...arguments)},writable:!0},wrappedWarn:{value:function(){console&&console.warn&&console.warn(...arguments)},writable:!0},setFormat:{value:t=>{const e=Error();if(!e.stack)return"";const[n]=e.stack.split(d()).filter((t,e,n)=>/logAF(?:\s+|\s+\[.+\]\s+)\(/.test(n[e?e-1:e])||/logAfStub(?:\s+|\s+\[.+\]\s+)\(/.test(n[e])),r=n.slice(n.indexOf(p())).replace(")",""),o=r.lastIndexOf(y()),i={file:()=>"@".concat(r.slice(o+1),":\n"),path:()=>"@".concat(r,":\n"),parent(){const t=r.slice(0,o).lastIndexOf(h())+1;return"@".concat(r.slice(t),":\n")},arrow:()=>"========================>"};return i[t]?i[t]():((t,e,n)=>{if("string"==typeof t)return t;let[r,o,i]=e.split(f());const c=(r=r.split(u())).pop();r=r.join(s());const a="".concat(r.split(l()).pop(),"/");return t({path:r+="/",line:o,col:i,file:c,parent:a,arrow:n})})(t,r,i.arrow())},writable:!0},options:{value:function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{label:e,duration:n,labelFormat:r}=t;"boolean"==typeof e&&(g.label=e),"boolean"==typeof n&&(g.duration=n),r&&("string"==typeof r||"function"==typeof r?g.labelFormat=r:g.wrappedWarn("Warning: logAF labelFormat option must be set to 'file' (default), 'path', 'parent', 'arrow', or a custom string or function\n"))},writable:!0}}),(b.options.reset=function(){b.label=!0,b.labelFormat="file",b.duration=!0})();var g=n(b,"logAF");const m=function(t){return Array.isArray(t)||null!=t&&null!=t.length},A=t=>new Promise((e,n)=>{const r=t.length>>>0,o=Array(r);let i=r,c=r;if(!r)return e(o);const a=r=>Promise.resolve(t[r]).then(n=>{r in t&&(o[r]=n),--i||e(o)},n);for(;c--;)a(c)}),v=t=>(function e(n,r){const{length:o}=n;if(!o)return Promise.resolve(n);const i=!(r in t);return Promise.resolve(t[r]).then(t=>(i||(n[r]=t),r===o-1?n:e(n,r+1)))})(Array(t.length>>>0),0),w=function(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return A(t).then(e?t=>A(Array.prototype.map.call(t,e,n)):void 0)},O=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:",";return this.then(e=>{if(!m(e))throw TypeError("joinAF cannot be called on ".concat(e,", only on an Array or array-like Object"));return w(e).then(e=>e.join(t))})};Object.defineProperty(O,"length",{value:1});const F=t=>Promise[Array.isArray(t)?"all":"resolve"](t),j=t=>"@async-af/".concat(t.replace(/AsyncAf|AF/g,"").toLowerCase()),P=(j("AsyncAfWrapper"),[n(g,"logAF")].map(t=>[t,"".concat("./lib/","methods/other/").concat(t.name),j(t.name)])),E=[n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("mapAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));return this.inSeries?v(n).then(n=>n.reduce((n,r,o,i)=>n.then(n=>(n[o]=Promise.resolve(t.call(e,r,o,i)),A(n))),Promise.resolve(Array(n.length>>>0)))):w(n,t,e)})},"mapAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("forEachAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));return(this.inSeries?v(n).then(n=>n.reduce((n,r,o,i)=>n.then(()=>Promise.resolve(t.call(e,r,o,i))),Promise.resolve())):w(n,t,e)).then(()=>{})})},"forEachAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("filterAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));return(this.inSeries?v:w)(n).then(n=>(this.inSeries?n.reduce((n,r,o,i)=>n.then(n=>(n[o]=t.call(e,r,o,i),Promise.all(n))),Promise.all([])):w(n,t,e)).then(t=>n.filter((e,n)=>t[n])))})},"filterAF"),n(function(t){return this.then(e=>{if(!m(e))throw TypeError("reduceAF cannot be called on ".concat(e,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));const n=e.length>>>0;if(!n&&1===arguments.length)throw TypeError("reduceAF cannot be called on an empty array without an initial value");if(!n)return arguments[1];const r=t=>!(t in e);let o,i=0;if(2===arguments.length)[,o]=arguments;else{for(;r(i);)i++;o=e[i++]}return(this.inSeries?v:w)(e).then(e=>{const c=(o,i)=>Promise.resolve(o).then(o=>Promise.resolve(r(i)?o:t(o,e[i],i,e)).then(t=>i===n-1?t:c(t,i+1)));return c(o,i)})})},"reduceAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("everyAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));const r=n.length>>>0;return this.inSeries?!r||function n(o,i){const c=!(i in o);return Promise.resolve(o[i]).then(a=>(o[i]=a,Promise.resolve(!c&&t.call(e,a,i,o)).then(t=>!(!t&&!c)&&(i===r-1||n(o,i+1)))))}(Array.prototype.slice.call(n),0):w(n,t,e).then(t=>t.every(Boolean))})},"everyAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("someAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));const r=n.length>>>0;return this.inSeries?!!r&&function n(o,i){const c=!(i in o);return Promise.resolve(o[i]).then(a=>(o[i]=a,Promise.resolve(!c&&t.call(e,a,i,o)).then(t=>!(!t||c)||i!==r-1&&n(o,i+1))))}(Array.prototype.slice.call(n),0):w(n,t,e).then(t=>t.some(Boolean))})},"someAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.then(n=>{if(!m(n))throw TypeError("includesAF cannot be called on ".concat(n,", only on an Array, String, or array-like Object"));const r=n.length>>>0,o=0|e;return"string"==typeof n?n.includes(t,o):this.inSeries?!!r&&function e(o){return Promise.resolve(n[o]).then(n=>!!((t,e)=>t===e||Number.isNaN(t)&&Number.isNaN(e))(n,t)||!(o>=r-1)&&e(o+1))}(Math.max(o>=0?o:r-Math.abs(o),0)):w(n).then(e=>e.includes(t,o))})},"includesAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("findAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));const r=Array.from(n),o=r.length>>>0;return this.inSeries?o?function n(r,i){return Promise.resolve(r[i]).then(c=>(r[i]=c,Promise.resolve(t.call(e,c,i,r)).then(t=>t?c:i!==o-1?n(r,i+1):void 0)))}(r,0):void 0:w(r,t,e).then(t=>n[t.indexOf(!0)])})},"findAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("findIndexAF cannot be called on ".concat(n,", only on an Array or array-like Object"));if("function"!=typeof t)throw TypeError("".concat(t," is not a function"));const r=Array.from(n),o=r.length>>>0;return this.inSeries?o?function n(r,i){return Promise.resolve(r[i]).then(c=>(r[i]=c,Promise.resolve(t.call(e,c,i,r)).then(t=>t?i:i===o-1?-1:n(r,i+1))))}(r,0):-1:w(r,t,e).then(t=>t.indexOf(!0))})},"findIndexAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.then(n=>{if(!m(n))throw TypeError("indexOfAF cannot be called on ".concat(n,", only on an Array, String, or array-like Object"));const r=n.length>>>0,o=0|e;return"string"==typeof n?n.indexOf(t,o):this.inSeries?function e(o){return Promise.resolve(n[o]).then(i=>o in n&&i===t?o:o>=r-1?-1:e(o+1))}(Math.max(o>=0?o:r-Math.abs(o),0)):w(n).then(e=>e.indexOf(t,o))})},"indexOfAF"),n(function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if(!m(n))throw TypeError("lastIndexOfAF cannot be called on ".concat(n,", only on an Array, String, or array-like Object"));const r=n.length>>>0;let o=+e;return Number.isNaN(o)&&(o=r-1),"string"==typeof n?n.lastIndexOf(t,o):this.inSeries?function e(r){return Promise.resolve(n[r]).then(o=>r in n&&o===t?r:r<=0?-1:e(r-1))}(Math.min(o>=0?o:Math.max(r-Math.abs(o),0),r-1)):w(n).then(e=>e.lastIndexOf(t,o))})},"lastIndexOfAF"),n(O,"joinAF"),n(function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];const r=t=>[Promise,this.constructor].some(e=>t instanceof e),o=(t,e)=>r(e)&&e.then(F).then(e=>t.concat(e))||t.concat(e);return this.then(t=>{if("string"!=typeof t&&!Array.isArray(t))throw TypeError("concatAF cannot be called on ".concat(t,", only on an Array or String"));return F(t).then(t=>e.reduce((t,e)=>r(t)?t.then(t=>o(t,e)):o(t,e),t))})},"concatAF")].map(t=>[t,"".concat("./lib/","methods/arrays/").concat(t.name),j(t.name)]),T=[n(function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;return this.then(n=>{if("string"!=typeof n||Array.isArray(n))throw TypeError("splitAF may be called on a string but was called on ".concat(n));return String.prototype.split.call(n,t,e)})},"splitAF")].map(t=>[t,"".concat("./lib/","methods/strings/").concat(t.name),j(t.name)]),S=[...E,...T],x=t=>t.map(t=>{let[e]=t;return e}),k=x(P),M=x(S);function N(){const t=e(["AF"]);return N=function(){return t},t}const I=r(class extends a{}),W=t=>t.reduce((t,e)=>{const[n]=e.name.split(N())||[e.name];return Object.assign(t,{[e.name]:{value:e}},{[n]:{value:e}})},{});Object.defineProperties(a,W(k)),Object.defineProperties(a.prototype,W(M));export default I;
13//# sourceMappingURL=min.js.map