diff --git a/config/tusupload.php b/config/tusupload.php index 946735a..c528eac 100644 --- a/config/tusupload.php +++ b/config/tusupload.php @@ -22,7 +22,7 @@ | */ - 'hooks' => env('TUSUPLOAD_HOOKS_DIRECTORY') ?: __DIR__ . '/../hooks', + 'hooks_path' => env('TUSUPLOAD_HOOKS_DIRECTORY') ?: __DIR__ . '/../hooks', /* |-------------------------------------------------------------------------- diff --git a/package.json b/package.json index 56c15ea..7bce7f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "main": "public/js/tusuploader.js", + "main": "public/js/tusuploader.cjs.js", "browser": "public/js/tusuploader.js", "scripts": { "dev": "yarn development", @@ -22,7 +22,8 @@ "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-eslint": "^7.0.0", "rollup-plugin-filesize": "^6.2.0", - "rollup-plugin-node-resolve": "^5.2.0" + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-terser": "^5.1.3" }, "dependencies": { "cuid": "^2.1.6", diff --git a/public/js/tusuploader.cjs.js b/public/js/tusuploader.cjs.js new file mode 100644 index 0000000..2c4cce4 --- /dev/null +++ b/public/js/tusuploader.cjs.js @@ -0,0 +1 @@ +"use strict";var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var tus=createCommonjsModule((function(module,exports){var f;f=function(){return function e(t,r,n){function o(a,u){if(!r[a]){if(!t[a]){var s="function"==typeof commonjsRequire&&commonjsRequire;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[a]={exports:{}};t[a][0].call(f.exports,(function(e){var r=t[a][1][e];return o(r||e)}),f,f.exports,e,t,r,n)}return r[a].exports}for(var i="function"==typeof commonjsRequire&&commonjsRequire,a=0;athis._bufferOffset&&(this._buffer=this._buffer.slice(e-this._bufferOffset),this._bufferOffset=e);var r=0===p(this._buffer);return this._done&&r?null:this._buffer.slice(0,t-e)}},{key:"close",value:function(){this._reader.cancel&&this._reader.cancel()}}]),e}();function p(e){return void 0===e?0:void 0!==e.size?e.size:e.length}},{"./isCordova":2,"./isReactNative":3,"./readAsByteArray":4,"./uriToBlob":8}],7:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;n(this,t);var a=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e.message));a.originalRequest=i,a.causingError=r;var u=e.message;return null!=r&&(u+=", caused by "+r.toString()),null!=i&&(u+=", originated from request (response code: "+i.status+", response text: "+i.responseText+")"),a.message=u,a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,Error),t}();r.default=i},{}],10:[function(e,t,r){var n,o=e("./upload"),i=(n=o)&&n.__esModule?n:{default:n},a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(e("./node/storage")),u=i.default.defaultOptions,s={Upload:i.default,canStoreURLs:a.canStoreURLs,defaultOptions:u};if("undefined"!=typeof window){var c=window,f=c.XMLHttpRequest,l=c.Blob;s.isSupported=f&&l&&"function"==typeof l.prototype.slice}else s.isSupported=!0,s.FileStorage=a.FileStorage;t.exports=s},{"./node/storage":7,"./upload":11}],11:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;rt._offsetBeforeRetry&&(t._retryAttempt=0);var r=!0;"undefined"!=typeof window&&"navigator"in window&&!1===window.navigator.onLine&&(r=!1);var i=e.originalRequest?e.originalRequest.status:0,a=!d(i,400)||409===i||423===i;if(t._retryAttemptthis._size)&&!this.options.uploadLengthDeferred&&(n=this._size),this._source.slice(r,n,(function(r,n,o){r?t._emitError(r):(t.options.uploadLengthDeferred&&o&&(t._size=t._offset+(n&&n.size?n.size:0),e.setRequestHeader("Upload-Length",t._size)),null===n?e.send():(e.send(n),t._emitProgress(t._offset,t._size)))}))}},{key:"_handleUploadResponse",value:function(e){var t=this,r=parseInt(e.getResponseHeader("Upload-Offset"),10);if(isNaN(r))this._emitXhrError(e,new Error("tus: invalid or missing offset value"));else{if(this._emitProgress(r,this._size),this._emitChunkComplete(r-this._offset,r,this._size),this._offset=r,r==this._size)return this.options.removeFingerprintOnSuccess&&this.options.resume&&this._storage.removeItem(this._fingerprint,(function(e){e&&t._emitError(e)})),this._emitSuccess(),void this._source.close();this._startUpload()}}}],[{key:"terminate",value:function(e,t,r){if("function"!=typeof t&&"function"!=typeof r)throw new Error("tus: a callback function must be specified");"function"==typeof t&&(r=t,t={});var n=(0,u.newRequest)();n.open("DELETE",e,!0),n.onload=function(){204===n.status?r():r(new o.default(new Error("tus: unexpected response while terminating upload"),null,n))},n.onerror=function(e){r(new o.default(e,new Error("tus: failed to terminate upload"),n))},h(n,t),n.send(null)}}]),e}();function d(e,t){return e>=t&&e>>6)+fromCharCode(128|63&t):fromCharCode(224|t>>>12&15)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return fromCharCode(240|t>>>18&7)+fromCharCode(128|t>>>12&63)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t)},re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=function(e){return e.replace(re_utob,cb_utob)},cb_encode=function(e){var t=[0,2,1][e.length%3],r=e.charCodeAt(0)<<16|(e.length>1?e.charCodeAt(1):0)<<8|(e.length>2?e.charCodeAt(2):0);return[b64chars.charAt(r>>>18),b64chars.charAt(r>>>12&63),t>=2?"=":b64chars.charAt(r>>>6&63),t>=1?"=":b64chars.charAt(63&r)].join("")},btoa=global.btoa?function(e){return global.btoa(e)}:function(e){return e.replace(/[\s\S]{1,3}/g,cb_encode)},_encode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(e){return(e.constructor===buffer.constructor?e:buffer.from(e)).toString("base64")}:function(e){return(e.constructor===buffer.constructor?e:new buffer(e)).toString("base64")}:function(e){return btoa(utob(e))},encode=function(e,t){return t?_encode(String(e)).replace(/[+\/]/g,(function(e){return"+"==e?"-":"_"})).replace(/=/g,""):_encode(String(e))},encodeURI=function(e){return encode(e,!0)},re_btou=new RegExp(["[À-ß][€-¿]","[à-ï][€-¿]{2}","[ð-÷][€-¿]{3}"].join("|"),"g"),cb_btou=function(e){switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return fromCharCode(55296+(t>>>10))+fromCharCode(56320+(1023&t));case 3:return fromCharCode((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return fromCharCode((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},btou=function(e){return e.replace(re_btou,cb_btou)},cb_decode=function(e){var t=e.length,r=t%4,n=(t>0?b64tab[e.charAt(0)]<<18:0)|(t>1?b64tab[e.charAt(1)]<<12:0)|(t>2?b64tab[e.charAt(2)]<<6:0)|(t>3?b64tab[e.charAt(3)]:0),o=[fromCharCode(n>>>16),fromCharCode(n>>>8&255),fromCharCode(255&n)];return o.length-=[0,0,2,1][r],o.join("")},atob=global.atob?function(e){return global.atob(e)}:function(e){return e.replace(/[\s\S]{1,4}/g,cb_decode)},_decode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(e){return(e.constructor===buffer.constructor?e:buffer.from(e,"base64")).toString()}:function(e){return(e.constructor===buffer.constructor?e:new buffer(e,"base64")).toString()}:function(e){return btou(atob(e))},decode=function(e){return _decode(String(e).replace(/[-_]/g,(function(e){return"-"==e?"+":"/"})).replace(/[^A-Za-z0-9\+\/]/g,""))},noConflict=function(){var e=global.Base64;return global.Base64=_Base64,e};if(global.Base64={VERSION:version,atob:atob,btoa:btoa,fromBase64:decode,toBase64:encode,utob:utob,encode:encode,encodeURI:encodeURI,btou:btou,decode:decode,noConflict:noConflict,__buffer__:buffer},"function"==typeof Object.defineProperty){var noEnum=function(e){return{value:e,enumerable:!1,writable:!0,configurable:!0}};global.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",noEnum((function(){return decode(this)}))),Object.defineProperty(String.prototype,"toBase64",noEnum((function(e){return encode(this,e)}))),Object.defineProperty(String.prototype,"toBase64URI",noEnum((function(){return encode(this,!0)})))}}return global.Meteor&&(Base64=global.Base64),void 0!==module&&module.exports&&(module.exports.Base64=global.Base64),{Base64:global.Base64}}))}).call(this,void 0!==commonjsGlobal?commonjsGlobal:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(e,t,r){var n=Object.prototype.hasOwnProperty;function o(e){return decodeURIComponent(e.replace(/\+/g," "))}r.stringify=function(e,t){t=t||"";var r=[];for(var o in"string"!=typeof t&&(t="?"),e)n.call(e,o)&&r.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));return r.length?t+r.join("&"):""},r.parse=function(e){for(var t,r=/([^=?&]+)=?([^&]*)/g,n={};t=r.exec(e);){var i=o(t[1]),a=o(t[2]);i in n||(n[i]=a)}return n}},{}],15:[function(e,t,r){t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}],16:[function(e,t,r){(function(r){var n=e("requires-port"),o=e("querystringify"),i=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,a=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,u=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],s={hash:1,query:1};function c(e){var t,n=r&&r.location||{},o={},i=typeof(e=e||n);if("blob:"===e.protocol)o=new l(unescape(e.pathname),{});else if("string"===i)for(t in o=new l(e,{}),s)delete o[t];else if("object"===i){for(t in e)t in s||(o[t]=e[t]);void 0===o.slashes&&(o.slashes=a.test(e.href))}return o}function f(e){var t=i.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function l(e,t,r){if(!(this instanceof l))return new l(e,t,r);var i,a,s,p,d,h,_=u.slice(),v=typeof t,b=this,y=0;for("object"!==v&&"string"!==v&&(r=t,t=null),r&&"function"!=typeof r&&(r=o.parse),t=c(t),i=!(a=f(e||"")).protocol&&!a.slashes,b.slashes=a.slashes||i&&t.slashes,b.protocol=a.protocol||t.protocol||"",e=a.rest,a.slashes||(_[3]=[/(.*)/,"pathname"]);y<_.length;y++)"function"!=typeof(p=_[y])?(s=p[0],h=p[1],s!=s?b[h]=e:"string"==typeof s?~(d=e.indexOf(s))&&("number"==typeof p[2]?(b[h]=e.slice(0,d),e=e.slice(d+p[2])):(b[h]=e.slice(d),e=e.slice(0,d))):(d=s.exec(e))&&(b[h]=d[1],e=e.slice(0,d.index)),b[h]=b[h]||i&&p[3]&&t[h]||"",p[4]&&(b[h]=b[h].toLowerCase())):e=p(e);r&&(b.query=r(b.query)),i&&t.slashes&&"/"!==b.pathname.charAt(0)&&(""!==b.pathname||""!==t.pathname)&&(b.pathname=function(e,t){for(var r=(t||"/").split("/").slice(0,-1).concat(e.split("/")),n=r.length,o=r[n-1],i=!1,a=0;n--;)"."===r[n]?r.splice(n,1):".."===r[n]?(r.splice(n,1),a++):a&&(0===n&&(i=!0),r.splice(n,1),a--);return i&&r.unshift(""),"."!==o&&".."!==o||r.push(""),r.join("/")}(b.pathname,t.pathname)),n(b.port,b.protocol)||(b.host=b.hostname,b.port=""),b.username=b.password="",b.auth&&(p=b.auth.split(":"),b.username=p[0]||"",b.password=p[1]||""),b.origin=b.protocol&&b.host&&"file:"!==b.protocol?b.protocol+"//"+b.host:"null",b.href=b.toString()}l.prototype={set:function(e,t,r){var i=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(r||o.parse)(t)),i[e]=t;break;case"port":i[e]=t,n(t,i.protocol)?t&&(i.host=i.hostname+":"+t):(i.host=i.hostname,i[e]="");break;case"hostname":i[e]=t,i.port&&(t+=":"+i.port),i.host=t;break;case"host":i[e]=t,/:\d+$/.test(t)?(t=t.split(":"),i.port=t.pop(),i.hostname=t.join(":")):(i.hostname=t,i.port="");break;case"protocol":i.protocol=t.toLowerCase(),i.slashes=!r;break;case"pathname":case"hash":if(t){var a="pathname"===e?"/":"#";i[e]=t.charAt(0)!==a?a+t:t}else i[e]=t;break;default:i[e]=t}for(var s=0;s>>0,1)},emit:function(t,r){(e[t]||[]).slice().map((function(e){e(r)})),(e["*"]||[]).slice().map((function(e){e(t,r)}))}}}unwrapExports(tus);var pad=function(e,t){var r="000000000"+e;return r.substr(r.length-t)},env="object"==typeof window?window:self,globalCount=Object.keys(env).length,mimeTypesLength=navigator.mimeTypes?navigator.mimeTypes.length:0,clientId=pad((mimeTypesLength+navigator.userAgent.length).toString(36)+globalCount.toString(36),4),fingerprint_browser=function(){return clientId},getRandomValue,crypto="undefined"!=typeof window&&(window.crypto||window.msCrypto)||"undefined"!=typeof self&&self.crypto;if(crypto){var lim=Math.pow(2,32)-1;getRandomValue=function(){return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0]/lim)}}else getRandomValue=Math.random;var getRandomValue_browser=getRandomValue,c=0,blockSize=4,base=36,discreteValues=Math.pow(base,blockSize);function randomBlock(){return pad((getRandomValue_browser()*discreteValues<<0).toString(base),blockSize)}function safeCounter(){return c=c=7&&t<=10},cuid.fingerprint=fingerprint_browser;var cuid_1=cuid,MAX_SAFE_INTEGER=9007199254740991,argsTag="[object Arguments]",funcTag="[object Function]",genTag="[object GeneratorFunction]",reIsUint=/^(?:0|[1-9]\d*)$/;function apply(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}function baseTimes(e,t){for(var r=-1,n=Array(e);++r1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=e.length>3&&"function"==typeof i?(o--,i):void 0,a&&isIterateeCall(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),t=Object(t);++n-1&&e%1==0&&e-1&&e%1==0&&e<=MAX_SAFE_INTEGER}function isObject(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function isObjectLike(e){return!!e&&"object"==typeof e}var assignIn=createAssigner((function(e,t){copyObject(t,keysIn(t),e)}));function keysIn(e){return isArrayLike(e)?arrayLikeKeys(e,!0):baseKeysIn(e)}var lodash_assignin=assignIn,lodash_remove=createCommonjsModule((function(e,t){var r="[object Arguments]",n="[object Map]",o="[object Object]",i="[object Set]",a=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,u=/^\w*$/,s=/^\./,c=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,f=/\\(\\)?/g,l=/^\[object .+?Constructor\]$/,p=/^(?:0|[1-9]\d*)$/,d={};d["[object Float32Array]"]=d["[object Float64Array]"]=d["[object Int8Array]"]=d["[object Int16Array]"]=d["[object Int32Array]"]=d["[object Uint8Array]"]=d["[object Uint8ClampedArray]"]=d["[object Uint16Array]"]=d["[object Uint32Array]"]=!0,d[r]=d["[object Array]"]=d["[object ArrayBuffer]"]=d["[object Boolean]"]=d["[object DataView]"]=d["[object Date]"]=d["[object Error]"]=d["[object Function]"]=d[n]=d["[object Number]"]=d[o]=d["[object RegExp]"]=d[i]=d["[object String]"]=d["[object WeakMap]"]=!1;var h="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_="object"==typeof self&&self&&self.Object===Object&&self,v=h||_||Function("return this")(),b=t&&!t.nodeType&&t,y=b&&e&&!e.nodeType&&e,g=y&&y.exports===b&&h.process,m=function(){try{return g&&g.binding("util")}catch(e){}}(),w=m&&m.isTypedArray;function j(e,t){for(var r=-1,n=e?e.length:0;++ru))return!1;var c=i.get(e);if(c&&i.get(t))return c==t;var f=-1,l=!0,p=1&o?new ae:void 0;for(i.set(e,t),i.set(t,e);++f-1},oe.prototype.set=function(e,t){var r=this.__data__,n=ce(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},ie.prototype.clear=function(){this.__data__={hash:new ne,map:new(G||oe),string:new ne}},ie.prototype.delete=function(e){return ye(this,e).delete(e)},ie.prototype.get=function(e){return ye(this,e).get(e)},ie.prototype.has=function(e){return ye(this,e).has(e)},ie.prototype.set=function(e,t){return ye(this,e).set(e,t),this},ae.prototype.add=ae.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},ae.prototype.has=function(e){return this.__data__.has(e)},ue.prototype.clear=function(){this.__data__=new oe},ue.prototype.delete=function(e){return this.__data__.delete(e)},ue.prototype.get=function(e){return this.__data__.get(e)},ue.prototype.has=function(e){return this.__data__.has(e)},ue.prototype.set=function(e,t){var r=this.__data__;if(r instanceof oe){var n=r.__data__;if(!G||n.length<199)return n.push([e,t]),this;r=this.__data__=new ie(n)}return r.set(e,t),this};var me=function(e){return z.call(e)};function we(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||p.test(e))&&e>-1&&e%1==0&&eo?0:o+t),(r=r>o?o:r)<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n-1&&e%1==0&&e<=9007199254740991}function Le(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function qe(e){return!!e&&"object"==typeof e}function Me(e){return"symbol"==typeof e||qe(e)&&"[object Symbol]"==z.call(e)}var Be=w?function(e){return function(t){return e(t)}}(w):function(e){return qe(e)&&ze(e.length)&&!!d[z.call(e)]};function Fe(e){return De(e)?se(e):_e(e)}function Ne(e){return e}e.exports=function(e,t){var r=[];if(!e||!e.length)return r;var n=-1,o=[],i=e.length;for(t=he(t);++n-1},ie.prototype.set=function(e,t){var r=this.__data__,n=fe(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},ae.prototype.clear=function(){this.__data__={hash:new oe,map:new(H||ie),string:new oe}},ae.prototype.delete=function(e){return Ae(this,e).delete(e)},ae.prototype.get=function(e){return Ae(this,e).get(e)},ae.prototype.has=function(e){return Ae(this,e).has(e)},ae.prototype.set=function(e,t){return Ae(this,e).set(e,t),this},ue.prototype.add=ue.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},ue.prototype.has=function(e){return this.__data__.has(e)},se.prototype.clear=function(){this.__data__=new ie},se.prototype.delete=function(e){return this.__data__.delete(e)},se.prototype.get=function(e){return this.__data__.get(e)},se.prototype.has=function(e){return this.__data__.has(e)},se.prototype.set=function(e,t){var r=this.__data__;if(r instanceof ie){var n=r.__data__;if(!H||n.length<199)return n.push([e,t]),this;r=this.__data__=new ae(n)}return r.set(e,t),this};var le,pe,de=(le=function(e,t){return e&&_e(e,t,He)},function(e,t){if(null==e)return e;if(!qe(e))return le(e,t);for(var r=e.length,n=pe?r:-1,o=Object(e);(pe?n--:++nu))return!1;var c=i.get(e);if(c&&i.get(t))return c==t;var f=-1,l=!0,p=1&o?new ue:void 0;for(i.set(e,t),i.set(t,e);++f-1&&e%1==0&&e-1&&e%1==0&&e<=9007199254740991}function Fe(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Ne(e){return!!e&&"object"==typeof e}function Ve(e){return"symbol"==typeof e||Ne(e)&&"[object Symbol]"==L.call(e)}var Ge=w?function(e){return function(t){return e(t)}}(w):function(e){return Ne(e)&&Be(e.length)&&!!d[L.call(e)]};function He(e){return qe(e)?ce(e):we(e)}function Xe(e){return e}e.exports=function(e,t){return(Le(e)?j:he)(e,me(t))}})),_={assignIn:lodash_assignin,remove:lodash_remove,filter:lodash_filter},tusuploader=function(e){var t={QUEUED:1,STARTED:2,UPLOADING:3,COMPLETED:4,CANCELLED:5,FAILED:6},r=mitt(),n=[],o=_.assignIn({endpoint:"/uploadjobs/",retryDelays:[0,1e3,3e3,5e3],autoUpload:!1,chunkSize:5e3},e||{});if(void 0===typeof document.querySelector)throw new Error("TusUpload: Browser not supported.");if(!o.endpoint)throw new Error("TusUpload: Url not specified.");if(!tus.isSupported)throw new Error("TusUpload: Tus upload protocol not supported.");function i(e){this.status=t.FAILED,r.emit("upload.failed",{upload:this,type:"upload.failed",error:e})}function a(e,n,o){var i=(n/o*100).toFixed(2);this.status=t.UPLOADING,this.uploadPercentage=i,this.uploadTransferredSize=n,r.emit("upload.progress",{upload:this,type:"upload.progress",percentage:i,total:o,transferred:n})}function u(){this.status=t.COMPLETED,r.emit("upload.completed",{upload:this,type:"upload.completed"})}function s(e,r){return this.id=cuid_1(),this.metadata=_.assignIn({filename:e.name,upload_request_id:this.id},r||{}),this.transport=new tus.Upload(e,{endpoint:o.tus_endpoint,retryDelays:o.retryDelays,chunkSize:o.chunkSize,metadata:this.metadata,onError:i.bind(this),onChunkComplete:a.bind(this),onSuccess:u.bind(this)}),this.status=t.QUEUED,this.uploadToken=null,this.uploadPercentage=0,this.uploadSize=e.size,this.uploadTransferredSize=0,this.uploadRemainingTime=null,this.file=e,this}s.prototype.stop=function(){return this.transport.abort(),this.status=t.CANCELLED,window.axios.delete(o.endpoint+""+this.id).then(function(){r.emit("upload.cancelled",{upload:this,type:"upload.cancelled"})}.bind(this)).catch((function(){})),this},s.prototype.start=function(){return this.status=t.STARTED,r.emit("upload.started",{upload:this,type:"upload.started"}),window.axios.post(o.endpoint,lodash_assignin({id:this.id,filename:this.metadata.filename,filesize:this.file.size||"",filetype:this.file.type||""},this.metadata)).then(function(e){this.uploadToken=e.data.upload_token,this.transport.options.metadata.token=this.uploadToken,this.transport.options.endpoint=e.data.location,this.status=t.UPLOADING,this.transport.start()}.bind(this)).catch((function(e){i(e)})),this};var c={upload:function(e,t){var i=new s(e,t||{});return n.push(i),r.emit("upload.queued",{upload:i,type:"upload.queued"}),o.autoUpload&&i.start(),i}};return c.add=c.upload,c.remove=function(e){var o=_.remove(n,(function(t){return t.id===e}));return o&&o.length>=1?(o.forEach((function(e){e.status===t.UPLOADING&&e.stop()}),this),r.emit("upload.removed",{upload:o,type:"upload.removed"}),o):null},c.cancel=function(e){var r=_.remove(n,(function(t){return t.id===e}));return r&&r.length>=1?(r.forEach((function(e){e.status===t.UPLOADING&&e.stop()}),this),1==r.length?r[0]:r):null},c.uploads=function(e){return _.filter(n,e)},c.on=function(e,t){return r.on(e,t),c},c.off=function(e,t){return r.removeListener(e,t),c},c.Status=t,c.Upload=s,c};module.exports=tusuploader; diff --git a/public/js/tusuploader.js b/public/js/tusuploader.js index faa3014..605966f 100644 --- a/public/js/tusuploader.js +++ b/public/js/tusuploader.js @@ -1,8039 +1 @@ -var TusUploader = (function () { - 'use strict'; - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function commonjsRequire () { - throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); - } - - function unwrapExports (x) { - return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; - } - - function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; - } - - var tus = createCommonjsModule(function (module, exports) { - (function(f){{module.exports=f();}})(function(){return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof commonjsRequire=="function"&&commonjsRequire;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 commonjsRequire=="function"&&commonjsRequire;for(var o=0;o this._bufferOffset) { - this._buffer = this._buffer.slice(start - this._bufferOffset); - this._bufferOffset = start; - } - // If the buffer is empty after removing old data, all data has been read. - var hasAllDataBeenRead = len(this._buffer) === 0; - if (this._done && hasAllDataBeenRead) { - return null; - } - // We already removed data before `start`, so we just return the first - // chunk from the buffer. - return this._buffer.slice(0, end - start); - } - }, { - key: "close", - value: function close() { - if (this._reader.cancel) { - this._reader.cancel(); - } - } - }]); - - return StreamSource; - }(); - - function len(blobOrArray) { - if (blobOrArray === undefined) return 0; - if (blobOrArray.size !== undefined) return blobOrArray.size; - return blobOrArray.length; - } - - /* - Typed arrays and blobs don't have a concat method. - This function helps StreamSource accumulate data to reach chunkSize. - */ - function concat(a, b) { - if (a.concat) { - // Is `a` an Array? - return a.concat(b); - } - if (a instanceof Blob) { - return new Blob([a, b], { type: a.type }); - } - if (a.set) { - // Is `a` a typed array? - var c = new a.constructor(a.length + b.length); - c.set(a); - c.set(b, a.length); - return c; - } - throw new Error("Unknown data type"); - } - - function getSource(input, chunkSize, callback) { - // In React Native, when user selects a file, instead of a File or Blob, - // you usually get a file object {} with a uri property that contains - // a local path to the file. We use XMLHttpRequest to fetch - // the file blob, before uploading with tus. - if ((0, _isReactNative2.default)() && input && typeof input.uri !== "undefined") { - (0, _uriToBlob2.default)(input.uri, function (err, blob) { - if (err) { - return callback(new Error("tus: cannot fetch `file.uri` as Blob, make sure the uri is correct and accessible. " + err)); - } - callback(null, new FileSource(blob)); - }); - return; - } - - // Since we emulate the Blob type in our tests (not all target browsers - // support it), we cannot use `instanceof` for testing whether the input value - // can be handled. Instead, we simply check is the slice() function and the - // size property are available. - if (typeof input.slice === "function" && typeof input.size !== "undefined") { - callback(null, new FileSource(input)); - return; - } - - if (typeof input.read === "function") { - chunkSize = +chunkSize; - if (!isFinite(chunkSize)) { - callback(new Error("cannot create source for stream without a finite value for the `chunkSize` option")); - return; - } - callback(null, new StreamSource(input, chunkSize)); - return; - } - - callback(new Error("source object may only be an instance of File, Blob, or Reader in this environment")); - } - - },{"./isCordova":2,"./isReactNative":3,"./readAsByteArray":4,"./uriToBlob":8}],7:[function(_dereq_,module,exports){ - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - - exports.getStorage = getStorage; - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - /* global window, localStorage */ - - var hasStorage = false; - try { - hasStorage = "localStorage" in window; - - // Attempt to store and read entries from the local storage to detect Private - // Mode on Safari on iOS (see #49) - var key = "tusSupport"; - localStorage.setItem(key, localStorage.getItem(key)); - } catch (e) { - // If we try to access localStorage inside a sandboxed iframe, a SecurityError - // is thrown. When in private mode on iOS Safari, a QuotaExceededError is - // thrown (see #49) - if (e.code === e.SECURITY_ERR || e.code === e.QUOTA_EXCEEDED_ERR) { - hasStorage = false; - } else { - throw e; - } - } - - var canStoreURLs = exports.canStoreURLs = hasStorage; - - var LocalStorage = function () { - function LocalStorage() { - _classCallCheck(this, LocalStorage); - } - - _createClass(LocalStorage, [{ - key: "setItem", - value: function setItem(key, value, cb) { - cb(null, localStorage.setItem(key, value)); - } - }, { - key: "getItem", - value: function getItem(key, cb) { - cb(null, localStorage.getItem(key)); - } - }, { - key: "removeItem", - value: function removeItem(key, cb) { - cb(null, localStorage.removeItem(key)); - } - }]); - - return LocalStorage; - }(); - - function getStorage() { - return hasStorage ? new LocalStorage() : null; - } - - },{}],8:[function(_dereq_,module,exports){ - - Object.defineProperty(exports, "__esModule", { - value: true - }); - /** - * uriToBlob resolves a URI to a Blob object. This is used for - * React Native to retrieve a file (identified by a file:// - * URI) as a blob. - */ - function uriToBlob(uri, done) { - var xhr = new XMLHttpRequest(); - xhr.responseType = "blob"; - xhr.onload = function () { - var blob = xhr.response; - done(null, blob); - }; - xhr.onerror = function (err) { - done(err); - }; - xhr.open("GET", uri); - xhr.send(); - } - - exports.default = uriToBlob; - - },{}],9:[function(_dereq_,module,exports){ - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - - var DetailedError = function (_Error) { - _inherits(DetailedError, _Error); - - function DetailedError(error) { - var causingErr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var xhr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; - - _classCallCheck(this, DetailedError); - - var _this = _possibleConstructorReturn(this, (DetailedError.__proto__ || Object.getPrototypeOf(DetailedError)).call(this, error.message)); - - _this.originalRequest = xhr; - _this.causingError = causingErr; - - var message = error.message; - if (causingErr != null) { - message += ", caused by " + causingErr.toString(); - } - if (xhr != null) { - message += ", originated from request (response code: " + xhr.status + ", response text: " + xhr.responseText + ")"; - } - _this.message = message; - return _this; - } - - return DetailedError; - }(Error); - - exports.default = DetailedError; - - },{}],10:[function(_dereq_,module,exports){ - - var _upload = _dereq_("./upload"); - - var _upload2 = _interopRequireDefault(_upload); - - var _storage = _dereq_("./node/storage"); - - var storage = _interopRequireWildcard(_storage); - - function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - - /* global window */ - var defaultOptions = _upload2.default.defaultOptions; - - - var moduleExport = { - Upload: _upload2.default, - canStoreURLs: storage.canStoreURLs, - defaultOptions: defaultOptions - }; - - if (typeof window !== "undefined") { - // Browser environment using XMLHttpRequest - var _window = window, - XMLHttpRequest = _window.XMLHttpRequest, - Blob = _window.Blob; - - - moduleExport.isSupported = XMLHttpRequest && Blob && typeof Blob.prototype.slice === "function"; - } else { - // Node.js environment using http module - moduleExport.isSupported = true; - // make FileStorage module available as it will not be set by default. - moduleExport.FileStorage = storage.FileStorage; - } - - // The usage of the commonjs exporting syntax instead of the new ECMAScript - // one is actually inteded and prevents weird behaviour if we are trying to - // import this module in another module using Babel. - module.exports = moduleExport; - - },{"./node/storage":7,"./upload":11}],11:[function(_dereq_,module,exports){ - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global window */ - - - // We import the files used inside the Node environment which are rewritten - // for browsers using the rules defined in the package.json - - - var _error = _dereq_("./error"); - - var _error2 = _interopRequireDefault(_error); - - var _extend = _dereq_("extend"); - - var _extend2 = _interopRequireDefault(_extend); - - var _jsBase = _dereq_("js-base64"); - - var _request = _dereq_("./node/request"); - - var _source = _dereq_("./node/source"); - - var _storage = _dereq_("./node/storage"); - - var _fingerprint = _dereq_("./node/fingerprint"); - - var _fingerprint2 = _interopRequireDefault(_fingerprint); - - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - var defaultOptions = { - endpoint: null, - fingerprint: _fingerprint2.default, - resume: true, - onProgress: null, - onChunkComplete: null, - onSuccess: null, - onError: null, - headers: {}, - chunkSize: Infinity, - withCredentials: false, - uploadUrl: null, - uploadSize: null, - overridePatchMethod: false, - retryDelays: null, - removeFingerprintOnSuccess: false, - uploadLengthDeferred: false, - urlStorage: null, - fileReader: null, - uploadDataDuringCreation: false - }; - - var Upload = function () { - function Upload(file, options) { - _classCallCheck(this, Upload); - - this.options = (0, _extend2.default)(true, {}, defaultOptions, options); - - // The storage module used to store URLs - this._storage = this.options.urlStorage; - - // The underlying File/Blob object - this.file = file; - - // The URL against which the file will be uploaded - this.url = null; - - // The underlying XHR object for the current PATCH request - this._xhr = null; - - // The fingerpinrt for the current file (set after start()) - this._fingerprint = null; - - // The offset used in the current PATCH request - this._offset = null; - - // True if the current PATCH request has been aborted - this._aborted = false; - - // The file's size in bytes - this._size = null; - - // The Source object which will wrap around the given file and provides us - // with a unified interface for getting its size and slice chunks from its - // content allowing us to easily handle Files, Blobs, Buffers and Streams. - this._source = null; - - // The current count of attempts which have been made. Null indicates none. - this._retryAttempt = 0; - - // The timeout's ID which is used to delay the next retry - this._retryTimeout = null; - - // The offset of the remote upload before the latest attempt was started. - this._offsetBeforeRetry = 0; - } - - _createClass(Upload, [{ - key: "start", - value: function start() { - var _this = this; - - var file = this.file; - - if (!file) { - this._emitError(new Error("tus: no file or stream to upload provided")); - return; - } - - if (!this.options.endpoint && !this.options.uploadUrl) { - this._emitError(new Error("tus: neither an endpoint or an upload URL is provided")); - return; - } - - if (this.options.resume && this._storage == null) { - this._storage = (0, _storage.getStorage)(); - } - - if (this._source) { - this._start(this._source); - } else { - var fileReader = this.options.fileReader || _source.getSource; - fileReader(file, this.options.chunkSize, function (err, source) { - if (err) { - _this._emitError(err); - return; - } - - _this._source = source; - _this._start(source); - }); - } - } - }, { - key: "_start", - value: function _start(source) { - var _this2 = this; - - var file = this.file; - - // First, we look at the uploadLengthDeferred option. - // Next, we check if the caller has supplied a manual upload size. - // Finally, we try to use the calculated size from the source object. - if (this.options.uploadLengthDeferred) { - this._size = null; - } else if (this.options.uploadSize != null) { - this._size = +this.options.uploadSize; - if (isNaN(this._size)) { - this._emitError(new Error("tus: cannot convert `uploadSize` option into a number")); - return; - } - } else { - this._size = source.size; - if (this._size == null) { - this._emitError(new Error("tus: cannot automatically derive upload's size from input and must be specified manually using the `uploadSize` option")); - return; - } - } - - var retryDelays = this.options.retryDelays; - if (retryDelays != null) { - if (Object.prototype.toString.call(retryDelays) !== "[object Array]") { - this._emitError(new Error("tus: the `retryDelays` option must either be an array or null")); - return; - } else { - var errorCallback = this.options.onError; - this.options.onError = function (err) { - // Restore the original error callback which may have been set. - _this2.options.onError = errorCallback; - - // We will reset the attempt counter if - // - we were already able to connect to the server (offset != null) and - // - we were able to upload a small chunk of data to the server - var shouldResetDelays = _this2._offset != null && _this2._offset > _this2._offsetBeforeRetry; - if (shouldResetDelays) { - _this2._retryAttempt = 0; - } - - var isOnline = true; - if (typeof window !== "undefined" && "navigator" in window && window.navigator.onLine === false) { - isOnline = false; - } - - // We only attempt a retry if - // - we didn't exceed the maxium number of retries, yet, and - // - this error was caused by a request or it's response and - // - the error is server error (i.e. no a status 4xx or a 409 or 423) and - // - the browser does not indicate that we are offline - var status = err.originalRequest ? err.originalRequest.status : 0; - var isServerError = !inStatusCategory(status, 400) || status === 409 || status === 423; - var shouldRetry = _this2._retryAttempt < retryDelays.length && err.originalRequest != null && isServerError && isOnline; - - if (!shouldRetry) { - _this2._emitError(err); - return; - } - - var delay = retryDelays[_this2._retryAttempt++]; - - _this2._offsetBeforeRetry = _this2._offset; - _this2.options.uploadUrl = _this2.url; - - _this2._retryTimeout = setTimeout(function () { - _this2.start(); - }, delay); - }; - } - } - - // Reset the aborted flag when the upload is started or else the - // _startUpload will stop before sending a request if the upload has been - // aborted previously. - this._aborted = false; - - // The upload had been started previously and we should reuse this URL. - if (this.url != null) { - this._resumeUpload(); - return; - } - - // A URL has manually been specified, so we try to resume - if (this.options.uploadUrl != null) { - this.url = this.options.uploadUrl; - this._resumeUpload(); - return; - } - - // Try to find the endpoint for the file in the storage - if (this._hasStorage()) { - this.options.fingerprint(file, this.options, function (err, fingerprintValue) { - if (err) { - _this2._emitError(err); - return; - } - - _this2._fingerprint = fingerprintValue; - _this2._storage.getItem(_this2._fingerprint, function (err, resumedUrl) { - if (err) { - _this2._emitError(err); - return; - } - - if (resumedUrl != null) { - _this2.url = resumedUrl; - _this2._resumeUpload(); - } else { - _this2._createUpload(); - } - }); - }); - } else { - // An upload has not started for the file yet, so we start a new one - this._createUpload(); - } - } - }, { - key: "abort", - value: function abort(shouldTerminate, cb) { - var _this3 = this; - - if (this._xhr !== null) { - this._xhr.abort(); - this._source.close(); - } - this._aborted = true; - - if (this._retryTimeout != null) { - clearTimeout(this._retryTimeout); - this._retryTimeout = null; - } - - cb = cb || function () {}; - if (shouldTerminate) { - Upload.terminate(this.url, this.options, function (err, xhr) { - if (err) { - return cb(err, xhr); - } - - _this3._hasStorage() ? _this3._storage.removeItem(_this3._fingerprint, cb) : cb(); - }); - } else { - cb(); - } - } - }, { - key: "_hasStorage", - value: function _hasStorage() { - return this.options.resume && this._storage; - } - }, { - key: "_emitXhrError", - value: function _emitXhrError(xhr, err, causingErr) { - this._emitError(new _error2.default(err, causingErr, xhr)); - } - }, { - key: "_emitError", - value: function _emitError(err) { - if (typeof this.options.onError === "function") { - this.options.onError(err); - } else { - throw err; - } - } - }, { - key: "_emitSuccess", - value: function _emitSuccess() { - if (typeof this.options.onSuccess === "function") { - this.options.onSuccess(); - } - } - - /** - * Publishes notification when data has been sent to the server. This - * data may not have been accepted by the server yet. - * @param {number} bytesSent Number of bytes sent to the server. - * @param {number} bytesTotal Total number of bytes to be sent to the server. - */ - - }, { - key: "_emitProgress", - value: function _emitProgress(bytesSent, bytesTotal) { - if (typeof this.options.onProgress === "function") { - this.options.onProgress(bytesSent, bytesTotal); - } - } - - /** - * Publishes notification when a chunk of data has been sent to the server - * and accepted by the server. - * @param {number} chunkSize Size of the chunk that was accepted by the - * server. - * @param {number} bytesAccepted Total number of bytes that have been - * accepted by the server. - * @param {number} bytesTotal Total number of bytes to be sent to the server. - */ - - }, { - key: "_emitChunkComplete", - value: function _emitChunkComplete(chunkSize, bytesAccepted, bytesTotal) { - if (typeof this.options.onChunkComplete === "function") { - this.options.onChunkComplete(chunkSize, bytesAccepted, bytesTotal); - } - } - - /** - * Set the headers used in the request and the withCredentials property - * as defined in the options - * - * @param {XMLHttpRequest} xhr - */ - - }, { - key: "_setupXHR", - value: function _setupXHR(xhr) { - this._xhr = xhr; - setupXHR(xhr, this.options); - } - - /** - * Create a new upload using the creation extension by sending a POST - * request to the endpoint. After successful creation the file will be - * uploaded - * - * @api private - */ - - }, { - key: "_createUpload", - value: function _createUpload() { - var _this4 = this; - - if (!this.options.endpoint) { - this._emitError(new Error("tus: unable to create upload because no endpoint is provided")); - return; - } - - var xhr = (0, _request.newRequest)(); - xhr.open("POST", this.options.endpoint, true); - - xhr.onload = function () { - if (!inStatusCategory(xhr.status, 200)) { - _this4._emitXhrError(xhr, new Error("tus: unexpected response while creating upload")); - return; - } - - var location = xhr.getResponseHeader("Location"); - if (location == null) { - _this4._emitXhrError(xhr, new Error("tus: invalid or missing Location header")); - return; - } - - _this4.url = (0, _request.resolveUrl)(_this4.options.endpoint, location); - - if (_this4._size === 0) { - // Nothing to upload and file was successfully created - _this4._emitSuccess(); - _this4._source.close(); - return; - } - - if (_this4._hasStorage()) { - _this4._storage.setItem(_this4._fingerprint, _this4.url, function (err) { - if (err) { - _this4._emitError(err); - } - }); - } - - if (_this4.options.uploadDataDuringCreation) { - _this4._handleUploadResponse(xhr); - } else { - _this4._offset = 0; - _this4._startUpload(); - } - }; - - xhr.onerror = function (err) { - _this4._emitXhrError(xhr, new Error("tus: failed to create upload"), err); - }; - - this._setupXHR(xhr); - if (this.options.uploadLengthDeferred) { - xhr.setRequestHeader("Upload-Defer-Length", 1); - } else { - xhr.setRequestHeader("Upload-Length", this._size); - } - - // Add metadata if values have been added - var metadata = encodeMetadata(this.options.metadata); - if (metadata !== "") { - xhr.setRequestHeader("Upload-Metadata", metadata); - } - - if (this.options.uploadDataDuringCreation && !this.options.uploadLengthDeferred) { - this._offset = 0; - this._addChunkToRequest(xhr); - } else { - xhr.send(null); - } - } - - /* - * Try to resume an existing upload. First a HEAD request will be sent - * to retrieve the offset. If the request fails a new upload will be - * created. In the case of a successful response the file will be uploaded. - * - * @api private - */ - - }, { - key: "_resumeUpload", - value: function _resumeUpload() { - var _this5 = this; - - var xhr = (0, _request.newRequest)(); - xhr.open("HEAD", this.url, true); - - xhr.onload = function () { - if (!inStatusCategory(xhr.status, 200)) { - if (_this5._hasStorage() && inStatusCategory(xhr.status, 400)) { - // Remove stored fingerprint and corresponding endpoint, - // on client errors since the file can not be found - _this5._storage.removeItem(_this5._fingerprint, function (err) { - if (err) { - _this5._emitError(err); - } - }); - } - - // If the upload is locked (indicated by the 423 Locked status code), we - // emit an error instead of directly starting a new upload. This way the - // retry logic can catch the error and will retry the upload. An upload - // is usually locked for a short period of time and will be available - // afterwards. - if (xhr.status === 423) { - _this5._emitXhrError(xhr, new Error("tus: upload is currently locked; retry later")); - return; - } - - if (!_this5.options.endpoint) { - // Don't attempt to create a new upload if no endpoint is provided. - _this5._emitXhrError(xhr, new Error("tus: unable to resume upload (new upload cannot be created without an endpoint)")); - return; - } - - // Try to create a new upload - _this5.url = null; - _this5._createUpload(); - return; - } - - var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10); - if (isNaN(offset)) { - _this5._emitXhrError(xhr, new Error("tus: invalid or missing offset value")); - return; - } - - var length = parseInt(xhr.getResponseHeader("Upload-Length"), 10); - if (isNaN(length) && !_this5.options.uploadLengthDeferred) { - _this5._emitXhrError(xhr, new Error("tus: invalid or missing length value")); - return; - } - - // Upload has already been completed and we do not need to send additional - // data to the server - if (offset === length) { - _this5._emitProgress(length, length); - _this5._emitSuccess(); - return; - } - - _this5._offset = offset; - _this5._startUpload(); - }; - - xhr.onerror = function (err) { - _this5._emitXhrError(xhr, new Error("tus: failed to resume upload"), err); - }; - - this._setupXHR(xhr); - xhr.send(null); - } - - /** - * Start uploading the file using PATCH requests. The file will be divided - * into chunks as specified in the chunkSize option. During the upload - * the onProgress event handler may be invoked multiple times. - * - * @api private - */ - - }, { - key: "_startUpload", - value: function _startUpload() { - var _this6 = this; - - // If the upload has been aborted, we will not send the next PATCH request. - // This is important if the abort method was called during a callback, such - // as onChunkComplete or onProgress. - if (this._aborted) { - return; - } - - var xhr = (0, _request.newRequest)(); - - // Some browser and servers may not support the PATCH method. For those - // cases, you can tell tus-js-client to use a POST request with the - // X-HTTP-Method-Override header for simulating a PATCH request. - if (this.options.overridePatchMethod) { - xhr.open("POST", this.url, true); - xhr.setRequestHeader("X-HTTP-Method-Override", "PATCH"); - } else { - xhr.open("PATCH", this.url, true); - } - - xhr.onload = function () { - if (!inStatusCategory(xhr.status, 200)) { - _this6._emitXhrError(xhr, new Error("tus: unexpected response while uploading chunk")); - return; - } - - _this6._handleUploadResponse(xhr); - }; - - xhr.onerror = function (err) { - // Don't emit an error if the upload was aborted manually - if (_this6._aborted) { - return; - } - - _this6._emitXhrError(xhr, new Error("tus: failed to upload chunk at offset " + _this6._offset), err); - }; - - this._setupXHR(xhr); - - xhr.setRequestHeader("Upload-Offset", this._offset); - this._addChunkToRequest(xhr); - } - - /** - * _addChunktoRequest reads a chunk from the source and sends it using the - * supplied XHR object. It will not handle the response. - */ - - }, { - key: "_addChunkToRequest", - value: function _addChunkToRequest(xhr) { - var _this7 = this; - - // Test support for progress events before attaching an event listener - if ("upload" in xhr) { - xhr.upload.onprogress = function (e) { - if (!e.lengthComputable) { - return; - } - - _this7._emitProgress(start + e.loaded, _this7._size); - }; - } - - xhr.setRequestHeader("Content-Type", "application/offset+octet-stream"); - - var start = this._offset; - var end = this._offset + this.options.chunkSize; - - // The specified chunkSize may be Infinity or the calcluated end position - // may exceed the file's size. In both cases, we limit the end position to - // the input's total size for simpler calculations and correctness. - if ((end === Infinity || end > this._size) && !this.options.uploadLengthDeferred) { - end = this._size; - } - - this._source.slice(start, end, function (err, value, complete) { - if (err) { - _this7._emitError(err); - return; - } - - if (_this7.options.uploadLengthDeferred) { - if (complete) { - _this7._size = _this7._offset + (value && value.size ? value.size : 0); - xhr.setRequestHeader("Upload-Length", _this7._size); - } - } - - if (value === null) { - xhr.send(); - } else { - xhr.send(value); - _this7._emitProgress(_this7._offset, _this7._size); - } - }); - } - - /** - * _handleUploadResponse is used by requests that haven been sent using _addChunkToRequest - * and already have received a response. - */ - - }, { - key: "_handleUploadResponse", - value: function _handleUploadResponse(xhr) { - var _this8 = this; - - var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10); - if (isNaN(offset)) { - this._emitXhrError(xhr, new Error("tus: invalid or missing offset value")); - return; - } - - this._emitProgress(offset, this._size); - this._emitChunkComplete(offset - this._offset, offset, this._size); - - this._offset = offset; - - if (offset == this._size) { - if (this.options.removeFingerprintOnSuccess && this.options.resume) { - // Remove stored fingerprint and corresponding endpoint. This causes - // new upload of the same file must be treated as a different file. - this._storage.removeItem(this._fingerprint, function (err) { - if (err) { - _this8._emitError(err); - } - }); - } - - // Yay, finally done :) - this._emitSuccess(); - this._source.close(); - return; - } - - this._startUpload(); - } - }], [{ - key: "terminate", - value: function terminate(url, options, cb) { - if (typeof options !== "function" && typeof cb !== "function") { - throw new Error("tus: a callback function must be specified"); - } - - if (typeof options === "function") { - cb = options; - options = {}; - } - - var xhr = (0, _request.newRequest)(); - xhr.open("DELETE", url, true); - - xhr.onload = function () { - if (xhr.status !== 204) { - cb(new _error2.default(new Error("tus: unexpected response while terminating upload"), null, xhr)); - return; - } - - cb(); - }; - - xhr.onerror = function (err) { - cb(new _error2.default(err, new Error("tus: failed to terminate upload"), xhr)); - }; - - setupXHR(xhr, options); - xhr.send(null); - } - }]); - - return Upload; - }(); - - function encodeMetadata(metadata) { - var encoded = []; - - for (var key in metadata) { - encoded.push(key + " " + _jsBase.Base64.encode(metadata[key])); - } - - return encoded.join(","); - } - - /** - * Checks whether a given status is in the range of the expected category. - * For example, only a status between 200 and 299 will satisfy the category 200. - * - * @api private - */ - function inStatusCategory(status, category) { - return status >= category && status < category + 100; - } - - function setupXHR(xhr, options) { - xhr.setRequestHeader("Tus-Resumable", "1.0.0"); - var headers = options.headers || {}; - - for (var name in headers) { - xhr.setRequestHeader(name, headers[name]); - } - - xhr.withCredentials = options.withCredentials; - } - - Upload.defaultOptions = defaultOptions; - - exports.default = Upload; - - },{"./error":9,"./node/fingerprint":1,"./node/request":5,"./node/source":6,"./node/storage":7,"extend":12,"js-base64":13}],12:[function(_dereq_,module,exports){ - - var hasOwn = Object.prototype.hasOwnProperty; - var toStr = Object.prototype.toString; - var defineProperty = Object.defineProperty; - var gOPD = Object.getOwnPropertyDescriptor; - - var isArray = function isArray(arr) { - if (typeof Array.isArray === 'function') { - return Array.isArray(arr); - } - - return toStr.call(arr) === '[object Array]'; - }; - - var isPlainObject = function isPlainObject(obj) { - if (!obj || toStr.call(obj) !== '[object Object]') { - return false; - } - - var hasOwnConstructor = hasOwn.call(obj, 'constructor'); - var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf'); - // Not own constructor property must be Object - if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) { - return false; - } - - // Own properties are enumerated firstly, so to speed up, - // if last one is own, then all properties are own. - var key; - for (key in obj) { /**/ } - - return typeof key === 'undefined' || hasOwn.call(obj, key); - }; - - // If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target - var setProperty = function setProperty(target, options) { - if (defineProperty && options.name === '__proto__') { - defineProperty(target, options.name, { - enumerable: true, - configurable: true, - value: options.newValue, - writable: true - }); - } else { - target[options.name] = options.newValue; - } - }; - - // Return undefined instead of __proto__ if '__proto__' is not an own property - var getProperty = function getProperty(obj, name) { - if (name === '__proto__') { - if (!hasOwn.call(obj, name)) { - return void 0; - } else if (gOPD) { - // In early versions of node, obj['__proto__'] is buggy when obj has - // __proto__ as an own property. Object.getOwnPropertyDescriptor() works. - return gOPD(obj, name).value; - } - } - - return obj[name]; - }; - - module.exports = function extend() { - var options, name, src, copy, copyIsArray, clone; - var target = arguments[0]; - var i = 1; - var length = arguments.length; - var deep = false; - - // Handle a deep copy situation - if (typeof target === 'boolean') { - deep = target; - target = arguments[1] || {}; - // skip the boolean and the target - i = 2; - } - if (target == null || (typeof target !== 'object' && typeof target !== 'function')) { - target = {}; - } - - for (; i < length; ++i) { - options = arguments[i]; - // Only deal with non-null/undefined values - if (options != null) { - // Extend the base object - for (name in options) { - src = getProperty(target, name); - copy = getProperty(options, name); - - // Prevent never-ending loop - if (target !== copy) { - // Recurse if we're merging plain objects or arrays - if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) { - if (copyIsArray) { - copyIsArray = false; - clone = src && isArray(src) ? src : []; - } else { - clone = src && isPlainObject(src) ? src : {}; - } - - // Never move original objects, clone them - setProperty(target, { name: name, newValue: extend(deep, clone, copy) }); - - // Don't bring in undefined values - } else if (typeof copy !== 'undefined') { - setProperty(target, { name: name, newValue: copy }); - } - } - } - } - } - - // Return the modified object - return target; - }; - - },{}],13:[function(_dereq_,module,exports){ - (function (global){ - (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' - ? module.exports = factory(global) - : factory(global); - }(( - typeof self !== 'undefined' ? self - : typeof window !== 'undefined' ? window - : typeof global !== 'undefined' ? global - : this - ), function(global) { - // existing version for noConflict() - var _Base64 = global.Base64; - var version = "2.4.9"; - // if node.js and NOT React Native, we use Buffer - var buffer; - if (typeof module !== 'undefined' && module.exports) { - try { - buffer = eval("require('buffer').Buffer"); - } catch (err) { - buffer = undefined; - } - } - // constants - var b64chars - = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - var b64tab = function(bin) { - var t = {}; - for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i; - return t; - }(b64chars); - var fromCharCode = String.fromCharCode; - // encoder stuff - var cb_utob = function(c) { - if (c.length < 2) { - var cc = c.charCodeAt(0); - return cc < 0x80 ? c - : cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6)) - + fromCharCode(0x80 | (cc & 0x3f))) - : (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) - + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) - + fromCharCode(0x80 | ( cc & 0x3f))); - } else { - var cc = 0x10000 - + (c.charCodeAt(0) - 0xD800) * 0x400 - + (c.charCodeAt(1) - 0xDC00); - return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07)) - + fromCharCode(0x80 | ((cc >>> 12) & 0x3f)) - + fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) - + fromCharCode(0x80 | ( cc & 0x3f))); - } - }; - var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g; - var utob = function(u) { - return u.replace(re_utob, cb_utob); - }; - var cb_encode = function(ccc) { - var padlen = [0, 2, 1][ccc.length % 3], - ord = ccc.charCodeAt(0) << 16 - | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8) - | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)), - chars = [ - b64chars.charAt( ord >>> 18), - b64chars.charAt((ord >>> 12) & 63), - padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63), - padlen >= 1 ? '=' : b64chars.charAt(ord & 63) - ]; - return chars.join(''); - }; - var btoa = global.btoa ? function(b) { - return global.btoa(b); - } : function(b) { - return b.replace(/[\s\S]{1,3}/g, cb_encode); - }; - var _encode = buffer ? - buffer.from && Uint8Array && buffer.from !== Uint8Array.from - ? function (u) { - return (u.constructor === buffer.constructor ? u : buffer.from(u)) - .toString('base64') - } - : function (u) { - return (u.constructor === buffer.constructor ? u : new buffer(u)) - .toString('base64') - } - : function (u) { return btoa(utob(u)) } - ; - var encode = function(u, urisafe) { - return !urisafe - ? _encode(String(u)) - : _encode(String(u)).replace(/[+\/]/g, function(m0) { - return m0 == '+' ? '-' : '_'; - }).replace(/=/g, ''); - }; - var encodeURI = function(u) { return encode(u, true) }; - // decoder stuff - var re_btou = new RegExp([ - '[\xC0-\xDF][\x80-\xBF]', - '[\xE0-\xEF][\x80-\xBF]{2}', - '[\xF0-\xF7][\x80-\xBF]{3}' - ].join('|'), 'g'); - var cb_btou = function(cccc) { - switch(cccc.length) { - case 4: - var cp = ((0x07 & cccc.charCodeAt(0)) << 18) - | ((0x3f & cccc.charCodeAt(1)) << 12) - | ((0x3f & cccc.charCodeAt(2)) << 6) - | (0x3f & cccc.charCodeAt(3)), - offset = cp - 0x10000; - return (fromCharCode((offset >>> 10) + 0xD800) - + fromCharCode((offset & 0x3FF) + 0xDC00)); - case 3: - return fromCharCode( - ((0x0f & cccc.charCodeAt(0)) << 12) - | ((0x3f & cccc.charCodeAt(1)) << 6) - | (0x3f & cccc.charCodeAt(2)) - ); - default: - return fromCharCode( - ((0x1f & cccc.charCodeAt(0)) << 6) - | (0x3f & cccc.charCodeAt(1)) - ); - } - }; - var btou = function(b) { - return b.replace(re_btou, cb_btou); - }; - var cb_decode = function(cccc) { - var len = cccc.length, - padlen = len % 4, - n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0) - | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0) - | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0) - | (len > 3 ? b64tab[cccc.charAt(3)] : 0), - chars = [ - fromCharCode( n >>> 16), - fromCharCode((n >>> 8) & 0xff), - fromCharCode( n & 0xff) - ]; - chars.length -= [0, 0, 2, 1][padlen]; - return chars.join(''); - }; - var atob = global.atob ? function(a) { - return global.atob(a); - } : function(a){ - return a.replace(/[\s\S]{1,4}/g, cb_decode); - }; - var _decode = buffer ? - buffer.from && Uint8Array && buffer.from !== Uint8Array.from - ? function(a) { - return (a.constructor === buffer.constructor - ? a : buffer.from(a, 'base64')).toString(); - } - : function(a) { - return (a.constructor === buffer.constructor - ? a : new buffer(a, 'base64')).toString(); - } - : function(a) { return btou(atob(a)) }; - var decode = function(a){ - return _decode( - String(a).replace(/[-_]/g, function(m0) { return m0 == '-' ? '+' : '/' }) - .replace(/[^A-Za-z0-9\+\/]/g, '') - ); - }; - var noConflict = function() { - var Base64 = global.Base64; - global.Base64 = _Base64; - return Base64; - }; - // export Base64 - global.Base64 = { - VERSION: version, - atob: atob, - btoa: btoa, - fromBase64: decode, - toBase64: encode, - utob: utob, - encode: encode, - encodeURI: encodeURI, - btou: btou, - decode: decode, - noConflict: noConflict, - __buffer__: buffer - }; - // if ES5 is available, make Base64.extendString() available - if (typeof Object.defineProperty === 'function') { - var noEnum = function(v){ - return {value:v,enumerable:false,writable:true,configurable:true}; - }; - global.Base64.extendString = function () { - Object.defineProperty( - String.prototype, 'fromBase64', noEnum(function () { - return decode(this) - })); - Object.defineProperty( - String.prototype, 'toBase64', noEnum(function (urisafe) { - return encode(this, urisafe) - })); - Object.defineProperty( - String.prototype, 'toBase64URI', noEnum(function () { - return encode(this, true) - })); - }; - } - // - // export Base64 to the namespace - // - if (global['Meteor']) { // Meteor.js - Base64 = global.Base64; - } - // module.exports and AMD are mutually exclusive. - // module.exports has precedence. - if (typeof module !== 'undefined' && module.exports) { - module.exports.Base64 = global.Base64; - } - // that's it! - return {Base64: global.Base64} - })); - - }).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); - - },{}],14:[function(_dereq_,module,exports){ - - var has = Object.prototype.hasOwnProperty; - - /** - * Decode a URI encoded string. - * - * @param {String} input The URI encoded string. - * @returns {String} The decoded string. - * @api private - */ - function decode(input) { - return decodeURIComponent(input.replace(/\+/g, ' ')); - } - - /** - * Simple query string parser. - * - * @param {String} query The query string that needs to be parsed. - * @returns {Object} - * @api public - */ - function querystring(query) { - var parser = /([^=?&]+)=?([^&]*)/g - , result = {} - , part; - - while (part = parser.exec(query)) { - var key = decode(part[1]) - , value = decode(part[2]); - - // - // Prevent overriding of existing properties. This ensures that build-in - // methods like `toString` or __proto__ are not overriden by malicious - // querystrings. - // - if (key in result) continue; - result[key] = value; - } - - return result; - } - - /** - * Transform a query string to an object. - * - * @param {Object} obj Object that should be transformed. - * @param {String} prefix Optional prefix. - * @returns {String} - * @api public - */ - function querystringify(obj, prefix) { - prefix = prefix || ''; - - var pairs = []; - - // - // Optionally prefix with a '?' if needed - // - if ('string' !== typeof prefix) prefix = '?'; - - for (var key in obj) { - if (has.call(obj, key)) { - pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key])); - } - } - - return pairs.length ? prefix + pairs.join('&') : ''; - } - - // - // Expose the module. - // - exports.stringify = querystringify; - exports.parse = querystring; - - },{}],15:[function(_dereq_,module,exports){ - - /** - * Check if we're required to add a port number. - * - * @see https://url.spec.whatwg.org/#default-port - * @param {Number|String} port Port number we need to check - * @param {String} protocol Protocol we need to check against. - * @returns {Boolean} Is it a default port for the given protocol - * @api private - */ - module.exports = function required(port, protocol) { - protocol = protocol.split(':')[0]; - port = +port; - - if (!port) return false; - - switch (protocol) { - case 'http': - case 'ws': - return port !== 80; - - case 'https': - case 'wss': - return port !== 443; - - case 'ftp': - return port !== 21; - - case 'gopher': - return port !== 70; - - case 'file': - return false; - } - - return port !== 0; - }; - - },{}],16:[function(_dereq_,module,exports){ - (function (global){ - - var required = _dereq_('requires-port') - , qs = _dereq_('querystringify') - , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i - , slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//; - - /** - * These are the parse rules for the URL parser, it informs the parser - * about: - * - * 0. The char it Needs to parse, if it's a string it should be done using - * indexOf, RegExp using exec and NaN means set as current value. - * 1. The property we should set when parsing this value. - * 2. Indication if it's backwards or forward parsing, when set as number it's - * the value of extra chars that should be split off. - * 3. Inherit from location if non existing in the parser. - * 4. `toLowerCase` the resulting value. - */ - var rules = [ - ['#', 'hash'], // Extract from the back. - ['?', 'query'], // Extract from the back. - function sanitize(address) { // Sanitize what is left of the address - return address.replace('\\', '/'); - }, - ['/', 'pathname'], // Extract from the back. - ['@', 'auth', 1], // Extract from the front. - [NaN, 'host', undefined, 1, 1], // Set left over value. - [/:(\d+)$/, 'port', undefined, 1], // RegExp the back. - [NaN, 'hostname', undefined, 1, 1] // Set left over. - ]; - - /** - * These properties should not be copied or inherited from. This is only needed - * for all non blob URL's as a blob URL does not include a hash, only the - * origin. - * - * @type {Object} - * @private - */ - var ignore = { hash: 1, query: 1 }; - - /** - * The location object differs when your code is loaded through a normal page, - * Worker or through a worker using a blob. And with the blobble begins the - * trouble as the location object will contain the URL of the blob, not the - * location of the page where our code is loaded in. The actual origin is - * encoded in the `pathname` so we can thankfully generate a good "default" - * location from it so we can generate proper relative URL's again. - * - * @param {Object|String} loc Optional default location object. - * @returns {Object} lolcation object. - * @public - */ - function lolcation(loc) { - var location = global && global.location || {}; - loc = loc || location; - - var finaldestination = {} - , type = typeof loc - , key; - - if ('blob:' === loc.protocol) { - finaldestination = new Url(unescape(loc.pathname), {}); - } else if ('string' === type) { - finaldestination = new Url(loc, {}); - for (key in ignore) delete finaldestination[key]; - } else if ('object' === type) { - for (key in loc) { - if (key in ignore) continue; - finaldestination[key] = loc[key]; - } - - if (finaldestination.slashes === undefined) { - finaldestination.slashes = slashes.test(loc.href); - } - } - - return finaldestination; - } - - /** - * @typedef ProtocolExtract - * @type Object - * @property {String} protocol Protocol matched in the URL, in lowercase. - * @property {Boolean} slashes `true` if protocol is followed by "//", else `false`. - * @property {String} rest Rest of the URL that is not part of the protocol. - */ - - /** - * Extract protocol information from a URL with/without double slash ("//"). - * - * @param {String} address URL we want to extract from. - * @return {ProtocolExtract} Extracted information. - * @private - */ - function extractProtocol(address) { - var match = protocolre.exec(address); - - return { - protocol: match[1] ? match[1].toLowerCase() : '', - slashes: !!match[2], - rest: match[3] - }; - } - - /** - * Resolve a relative URL pathname against a base URL pathname. - * - * @param {String} relative Pathname of the relative URL. - * @param {String} base Pathname of the base URL. - * @return {String} Resolved pathname. - * @private - */ - function resolve(relative, base) { - var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/')) - , i = path.length - , last = path[i - 1] - , unshift = false - , up = 0; - - while (i--) { - if (path[i] === '.') { - path.splice(i, 1); - } else if (path[i] === '..') { - path.splice(i, 1); - up++; - } else if (up) { - if (i === 0) unshift = true; - path.splice(i, 1); - up--; - } - } - - if (unshift) path.unshift(''); - if (last === '.' || last === '..') path.push(''); - - return path.join('/'); - } - - /** - * The actual URL instance. Instead of returning an object we've opted-in to - * create an actual constructor as it's much more memory efficient and - * faster and it pleases my OCD. - * - * It is worth noting that we should not use `URL` as class name to prevent - * clashes with the global URL instance that got introduced in browsers. - * - * @constructor - * @param {String} address URL we want to parse. - * @param {Object|String} location Location defaults for relative paths. - * @param {Boolean|Function} parser Parser for the query string. - * @private - */ - function Url(address, location, parser) { - if (!(this instanceof Url)) { - return new Url(address, location, parser); - } - - var relative, extracted, parse, instruction, index, key - , instructions = rules.slice() - , type = typeof location - , url = this - , i = 0; - - // - // The following if statements allows this module two have compatibility with - // 2 different API: - // - // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments - // where the boolean indicates that the query string should also be parsed. - // - // 2. The `URL` interface of the browser which accepts a URL, object as - // arguments. The supplied object will be used as default values / fall-back - // for relative paths. - // - if ('object' !== type && 'string' !== type) { - parser = location; - location = null; - } - - if (parser && 'function' !== typeof parser) parser = qs.parse; - - location = lolcation(location); - - // - // Extract protocol information before running the instructions. - // - extracted = extractProtocol(address || ''); - relative = !extracted.protocol && !extracted.slashes; - url.slashes = extracted.slashes || relative && location.slashes; - url.protocol = extracted.protocol || location.protocol || ''; - address = extracted.rest; - - // - // When the authority component is absent the URL starts with a path - // component. - // - if (!extracted.slashes) instructions[3] = [/(.*)/, 'pathname']; - - for (; i < instructions.length; i++) { - instruction = instructions[i]; - - if (typeof instruction === 'function') { - address = instruction(address); - continue; - } - - parse = instruction[0]; - key = instruction[1]; - - if (parse !== parse) { - url[key] = address; - } else if ('string' === typeof parse) { - if (~(index = address.indexOf(parse))) { - if ('number' === typeof instruction[2]) { - url[key] = address.slice(0, index); - address = address.slice(index + instruction[2]); - } else { - url[key] = address.slice(index); - address = address.slice(0, index); - } - } - } else if ((index = parse.exec(address))) { - url[key] = index[1]; - address = address.slice(0, index.index); - } - - url[key] = url[key] || ( - relative && instruction[3] ? location[key] || '' : '' - ); - - // - // Hostname, host and protocol should be lowercased so they can be used to - // create a proper `origin`. - // - if (instruction[4]) url[key] = url[key].toLowerCase(); - } - - // - // Also parse the supplied query string in to an object. If we're supplied - // with a custom parser as function use that instead of the default build-in - // parser. - // - if (parser) url.query = parser(url.query); - - // - // If the URL is relative, resolve the pathname against the base URL. - // - if ( - relative - && location.slashes - && url.pathname.charAt(0) !== '/' - && (url.pathname !== '' || location.pathname !== '') - ) { - url.pathname = resolve(url.pathname, location.pathname); - } - - // - // We should not add port numbers if they are already the default port number - // for a given protocol. As the host also contains the port number we're going - // override it with the hostname which contains no port number. - // - if (!required(url.port, url.protocol)) { - url.host = url.hostname; - url.port = ''; - } - - // - // Parse down the `auth` for the username and password. - // - url.username = url.password = ''; - if (url.auth) { - instruction = url.auth.split(':'); - url.username = instruction[0] || ''; - url.password = instruction[1] || ''; - } - - url.origin = url.protocol && url.host && url.protocol !== 'file:' - ? url.protocol +'//'+ url.host - : 'null'; - - // - // The href is just the compiled result. - // - url.href = url.toString(); - } - - /** - * This is convenience method for changing properties in the URL instance to - * insure that they all propagate correctly. - * - * @param {String} part Property we need to adjust. - * @param {Mixed} value The newly assigned value. - * @param {Boolean|Function} fn When setting the query, it will be the function - * used to parse the query. - * When setting the protocol, double slash will be - * removed from the final url if it is true. - * @returns {URL} URL instance for chaining. - * @public - */ - function set(part, value, fn) { - var url = this; - - switch (part) { - case 'query': - if ('string' === typeof value && value.length) { - value = (fn || qs.parse)(value); - } - - url[part] = value; - break; - - case 'port': - url[part] = value; - - if (!required(value, url.protocol)) { - url.host = url.hostname; - url[part] = ''; - } else if (value) { - url.host = url.hostname +':'+ value; - } - - break; - - case 'hostname': - url[part] = value; - - if (url.port) value += ':'+ url.port; - url.host = value; - break; - - case 'host': - url[part] = value; - - if (/:\d+$/.test(value)) { - value = value.split(':'); - url.port = value.pop(); - url.hostname = value.join(':'); - } else { - url.hostname = value; - url.port = ''; - } - - break; - - case 'protocol': - url.protocol = value.toLowerCase(); - url.slashes = !fn; - break; - - case 'pathname': - case 'hash': - if (value) { - var char = part === 'pathname' ? '/' : '#'; - url[part] = value.charAt(0) !== char ? char + value : value; - } else { - url[part] = value; - } - break; - - default: - url[part] = value; - } - - for (var i = 0; i < rules.length; i++) { - var ins = rules[i]; - - if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase(); - } - - url.origin = url.protocol && url.host && url.protocol !== 'file:' - ? url.protocol +'//'+ url.host - : 'null'; - - url.href = url.toString(); - - return url; - } - - /** - * Transform the properties back in to a valid and full URL string. - * - * @param {Function} stringify Optional query stringify function. - * @returns {String} Compiled version of the URL. - * @public - */ - function toString(stringify) { - if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify; - - var query - , url = this - , protocol = url.protocol; - - if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':'; - - var result = protocol + (url.slashes ? '//' : ''); - - if (url.username) { - result += url.username; - if (url.password) result += ':'+ url.password; - result += '@'; - } - - result += url.host + url.pathname; - - query = 'object' === typeof url.query ? stringify(url.query) : url.query; - if (query) result += '?' !== query.charAt(0) ? '?'+ query : query; - - if (url.hash) result += url.hash; - - return result; - } - - Url.prototype = { set: set, toString: toString }; - - // - // Expose the URL parser and some additional properties that might be useful for - // others or testing. - // - Url.extractProtocol = extractProtocol; - Url.location = lolcation; - Url.qs = qs; - - module.exports = Url; - - }).call(this,typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}); - - },{"querystringify":14,"requires-port":15}]},{},[10])(10) - }); - - }); - - unwrapExports(tus); - - // - // An event handler can take an optional event argument - // and should not return a value - - - - // An array of all currently registered event handlers for a type - - - // A map of event types and their corresponding event handlers. - - - - - - /** Mitt: Tiny (~200b) functional event emitter / pubsub. - * @name mitt - * @returns {Mitt} - */ - function mitt(all ) { - all = all || Object.create(null); - - return { - /** - * Register an event handler for the given type. - * - * @param {String} type Type of event to listen for, or `"*"` for all events - * @param {Function} handler Function to call in response to given event - * @memberOf mitt - */ - on: function on(type , handler ) { - (all[type] || (all[type] = [])).push(handler); - }, - - /** - * Remove an event handler for the given type. - * - * @param {String} type Type of event to unregister `handler` from, or `"*"` - * @param {Function} handler Handler function to remove - * @memberOf mitt - */ - off: function off(type , handler ) { - if (all[type]) { - all[type].splice(all[type].indexOf(handler) >>> 0, 1); - } - }, - - /** - * Invoke all handlers for the given type. - * If present, `"*"` handlers are invoked after type-matched handlers. - * - * @param {String} type The event type to invoke - * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler - * @memberOf mitt - */ - emit: function emit(type , evt ) { - (all[type] || []).slice().map(function (handler) { handler(evt); }); - (all['*'] || []).slice().map(function (handler) { handler(type, evt); }); - } - }; - } - - var pad = function pad (num, size) { - var s = '000000000' + num; - return s.substr(s.length - size); - }; - - var env = typeof window === 'object' ? window : self; - var globalCount = Object.keys(env).length; - var mimeTypesLength = navigator.mimeTypes ? navigator.mimeTypes.length : 0; - var clientId = pad((mimeTypesLength + - navigator.userAgent.length).toString(36) + - globalCount.toString(36), 4); - - var fingerprint_browser = function fingerprint () { - return clientId; - }; - - var getRandomValue; - - var crypto = typeof window !== 'undefined' && - (window.crypto || window.msCrypto) || - typeof self !== 'undefined' && - self.crypto; - - if (crypto) { - var lim = Math.pow(2, 32) - 1; - getRandomValue = function () { - return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0] / lim); - }; - } else { - getRandomValue = Math.random; - } - - var getRandomValue_browser = getRandomValue; - - /** - * cuid.js - * Collision-resistant UID generator for browsers and node. - * Sequential for fast db lookups and recency sorting. - * Safe for element IDs and server-side lookups. - * - * Extracted from CLCTR - * - * Copyright (c) Eric Elliott 2012 - * MIT License - */ - - - - - - var c = 0, - blockSize = 4, - base = 36, - discreteValues = Math.pow(base, blockSize); - - function randomBlock () { - return pad((getRandomValue_browser() * - discreteValues << 0) - .toString(base), blockSize); - } - - function safeCounter () { - c = c < discreteValues ? c : 0; - c++; // this is not subliminal - return c - 1; - } - - function cuid () { - // Starting with a lowercase letter makes - // it HTML element ID friendly. - var letter = 'c', // hard-coded allows for sequential access - - // timestamp - // warning: this exposes the exact date and time - // that the uid was created. - timestamp = (new Date().getTime()).toString(base), - - // Prevent same-machine collisions. - counter = pad(safeCounter().toString(base), blockSize), - - // A few chars to generate distinct ids for different - // clients (so different computers are far less - // likely to generate the same id) - print = fingerprint_browser(), - - // Grab some more chars from Math.random() - random = randomBlock() + randomBlock(); - - return letter + timestamp + counter + print + random; - } - - cuid.slug = function slug () { - var date = new Date().getTime().toString(36), - counter = safeCounter().toString(36).slice(-4), - print = fingerprint_browser().slice(0, 1) + - fingerprint_browser().slice(-1), - random = randomBlock().slice(-2); - - return date.slice(-2) + - counter + print + random; - }; - - cuid.isCuid = function isCuid (stringToCheck) { - if (typeof stringToCheck !== 'string') return false; - if (stringToCheck.startsWith('c')) return true; - return false; - }; - - cuid.isSlug = function isSlug (stringToCheck) { - if (typeof stringToCheck !== 'string') return false; - var stringLength = stringToCheck.length; - if (stringLength >= 7 && stringLength <= 10) return true; - return false; - }; - - cuid.fingerprint = fingerprint_browser; - - var cuid_1 = cuid; - - /** - * lodash (Custom Build) - * Build: `lodash modularize exports="npm" -o ./` - * Copyright jQuery Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ - - /** Used as references for various `Number` constants. */ - var MAX_SAFE_INTEGER = 9007199254740991; - - /** `Object#toString` result references. */ - var argsTag = '[object Arguments]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]'; - - /** Used to detect unsigned integer values. */ - var reIsUint = /^(?:0|[1-9]\d*)$/; - - /** - * A faster alternative to `Function#apply`, this function invokes `func` - * with the `this` binding of `thisArg` and the arguments of `args`. - * - * @private - * @param {Function} func The function to invoke. - * @param {*} thisArg The `this` binding of `func`. - * @param {Array} args The arguments to invoke `func` with. - * @returns {*} Returns the result of `func`. - */ - function apply(func, thisArg, args) { - switch (args.length) { - case 0: return func.call(thisArg); - case 1: return func.call(thisArg, args[0]); - case 2: return func.call(thisArg, args[0], args[1]); - case 3: return func.call(thisArg, args[0], args[1], args[2]); - } - return func.apply(thisArg, args); - } - - /** - * The base implementation of `_.times` without support for iteratee shorthands - * or max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ - function baseTimes(n, iteratee) { - var index = -1, - result = Array(n); - - while (++index < n) { - result[index] = iteratee(index); - } - return result; - } - - /** Used for built-in method references. */ - var objectProto = Object.prototype; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - - /** Built-in value references. */ - var propertyIsEnumerable = objectProto.propertyIsEnumerable; - - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeMax = Math.max; - - /** - * Creates an array of the enumerable property names of the array-like `value`. - * - * @private - * @param {*} value The value to query. - * @param {boolean} inherited Specify returning inherited property names. - * @returns {Array} Returns the array of property names. - */ - function arrayLikeKeys(value, inherited) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - // Safari 9 makes `arguments.length` enumerable in strict mode. - var result = (isArray(value) || isArguments(value)) - ? baseTimes(value.length, String) - : []; - - var length = result.length, - skipIndexes = !!length; - - for (var key in value) { - if ((inherited || hasOwnProperty.call(value, key)) && - !(skipIndexes && (key == 'length' || isIndex(key, length)))) { - result.push(key); - } - } - return result; - } - - /** - * Assigns `value` to `key` of `object` if the existing value is not equivalent - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * @private - * @param {Object} object The object to modify. - * @param {string} key The key of the property to assign. - * @param {*} value The value to assign. - */ - function assignValue(object, key, value) { - var objValue = object[key]; - if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || - (value === undefined && !(key in object))) { - object[key] = value; - } - } - - /** - * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function baseKeysIn(object) { - if (!isObject(object)) { - return nativeKeysIn(object); - } - var isProto = isPrototype(object), - result = []; - - for (var key in object) { - if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { - result.push(key); - } - } - return result; - } - - /** - * The base implementation of `_.rest` which doesn't validate or coerce arguments. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - */ - function baseRest(func, start) { - start = nativeMax(start === undefined ? (func.length - 1) : start, 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); - - while (++index < length) { - array[index] = args[start + index]; - } - index = -1; - var otherArgs = Array(start + 1); - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = array; - return apply(func, this, otherArgs); - }; - } - - /** - * Copies properties of `source` to `object`. - * - * @private - * @param {Object} source The object to copy properties from. - * @param {Array} props The property identifiers to copy. - * @param {Object} [object={}] The object to copy properties to. - * @param {Function} [customizer] The function to customize copied values. - * @returns {Object} Returns `object`. - */ - function copyObject(source, props, object, customizer) { - object || (object = {}); - - var index = -1, - length = props.length; - - while (++index < length) { - var key = props[index]; - - var newValue = customizer - ? customizer(object[key], source[key], key, object, source) - : undefined; - - assignValue(object, key, newValue === undefined ? source[key] : newValue); - } - return object; - } - - /** - * Creates a function like `_.assign`. - * - * @private - * @param {Function} assigner The function to assign values. - * @returns {Function} Returns the new assigner function. - */ - function createAssigner(assigner) { - return baseRest(function(object, sources) { - var index = -1, - length = sources.length, - customizer = length > 1 ? sources[length - 1] : undefined, - guard = length > 2 ? sources[2] : undefined; - - customizer = (assigner.length > 3 && typeof customizer == 'function') - ? (length--, customizer) - : undefined; - - if (guard && isIterateeCall(sources[0], sources[1], guard)) { - customizer = length < 3 ? undefined : customizer; - length = 1; - } - object = Object(object); - while (++index < length) { - var source = sources[index]; - if (source) { - assigner(object, source, index, customizer); - } - } - return object; - }); - } - - /** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ - function isIndex(value, length) { - length = length == null ? MAX_SAFE_INTEGER : length; - return !!length && - (typeof value == 'number' || reIsUint.test(value)) && - (value > -1 && value % 1 == 0 && value < length); - } - - /** - * Checks if the given arguments are from an iteratee call. - * - * @private - * @param {*} value The potential iteratee value argument. - * @param {*} index The potential iteratee index or key argument. - * @param {*} object The potential iteratee object argument. - * @returns {boolean} Returns `true` if the arguments are from an iteratee call, - * else `false`. - */ - function isIterateeCall(value, index, object) { - if (!isObject(object)) { - return false; - } - var type = typeof index; - if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object) - ) { - return eq(object[index], value); - } - return false; - } - - /** - * Checks if `value` is likely a prototype object. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. - */ - function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; - - return value === proto; - } - - /** - * This function is like - * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * except that it includes inherited enumerable properties. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function nativeKeysIn(object) { - var result = []; - if (object != null) { - for (var key in Object(object)) { - result.push(key); - } - } - return result; - } - - /** - * Performs a - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * comparison between two values to determine if they are equivalent. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.eq(object, object); - * // => true - * - * _.eq(object, other); - * // => false - * - * _.eq('a', 'a'); - * // => true - * - * _.eq('a', Object('a')); - * // => false - * - * _.eq(NaN, NaN); - * // => true - */ - function eq(value, other) { - return value === other || (value !== value && other !== other); - } - - /** - * Checks if `value` is likely an `arguments` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. - * @example - * - * _.isArguments(function() { return arguments; }()); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ - function isArguments(value) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && - (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); - } - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; - - /** - * Checks if `value` is array-like. A value is considered array-like if it's - * not a function and has a `value.length` that's an integer greater than or - * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. - * @example - * - * _.isArrayLike([1, 2, 3]); - * // => true - * - * _.isArrayLike(document.body.children); - * // => true - * - * _.isArrayLike('abc'); - * // => true - * - * _.isArrayLike(_.noop); - * // => false - */ - function isArrayLike(value) { - return value != null && isLength(value.length) && !isFunction(value); - } - - /** - * This method is like `_.isArrayLike` except that it also checks if `value` - * is an object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, - * else `false`. - * @example - * - * _.isArrayLikeObject([1, 2, 3]); - * // => true - * - * _.isArrayLikeObject(document.body.children); - * // => true - * - * _.isArrayLikeObject('abc'); - * // => false - * - * _.isArrayLikeObject(_.noop); - * // => false - */ - function isArrayLikeObject(value) { - return isObjectLike(value) && isArrayLike(value); - } - - /** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a function, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ - function isFunction(value) { - // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8-9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag; - } - - /** - * Checks if `value` is a valid array-like length. - * - * **Note:** This method is loosely based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. - * @example - * - * _.isLength(3); - * // => true - * - * _.isLength(Number.MIN_VALUE); - * // => false - * - * _.isLength(Infinity); - * // => false - * - * _.isLength('3'); - * // => false - */ - function isLength(value) { - return typeof value == 'number' && - value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; - } - - /** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ - function isObject(value) { - var type = typeof value; - return !!value && (type == 'object' || type == 'function'); - } - - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return !!value && typeof value == 'object'; - } - - /** - * This method is like `_.assign` except that it iterates over own and - * inherited source properties. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias extend - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.assign - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * function Bar() { - * this.c = 3; - * } - * - * Foo.prototype.b = 2; - * Bar.prototype.d = 4; - * - * _.assignIn({ 'a': 0 }, new Foo, new Bar); - * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } - */ - var assignIn = createAssigner(function(object, source) { - copyObject(source, keysIn(source), object); - }); - - /** - * Creates an array of the own and inherited enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keysIn(new Foo); - * // => ['a', 'b', 'c'] (iteration order is not guaranteed) - */ - function keysIn(object) { - return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); - } - - var lodash_assignin = assignIn; - - var lodash_remove = createCommonjsModule(function (module, exports) { - /** - * lodash (Custom Build) - * Build: `lodash modularize exports="npm" -o ./` - * Copyright jQuery Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ - - /** Used as the size to enable large array optimizations. */ - var LARGE_ARRAY_SIZE = 200; - - /** Used as the `TypeError` message for "Functions" methods. */ - var FUNC_ERROR_TEXT = 'Expected a function'; - - /** Used to stand-in for `undefined` hash values. */ - var HASH_UNDEFINED = '__lodash_hash_undefined__'; - - /** Used to compose bitmasks for comparison styles. */ - var UNORDERED_COMPARE_FLAG = 1, - PARTIAL_COMPARE_FLAG = 2; - - /** Used as references for various `Number` constants. */ - var INFINITY = 1 / 0, - MAX_SAFE_INTEGER = 9007199254740991; - - /** `Object#toString` result references. */ - var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]', - mapTag = '[object Map]', - numberTag = '[object Number]', - objectTag = '[object Object]', - promiseTag = '[object Promise]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - symbolTag = '[object Symbol]', - weakMapTag = '[object WeakMap]'; - - var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; - - /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, - reIsPlainProp = /^\w*$/, - reLeadingDot = /^\./, - rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; - - /** - * Used to match `RegExp` - * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). - */ - var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; - - /** Used to match backslashes in property paths. */ - var reEscapeChar = /\\(\\)?/g; - - /** Used to detect host constructors (Safari). */ - var reIsHostCtor = /^\[object .+?Constructor\]$/; - - /** Used to detect unsigned integer values. */ - var reIsUint = /^(?:0|[1-9]\d*)$/; - - /** Used to identify `toStringTag` values of typed arrays. */ - var typedArrayTags = {}; - typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = - typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = - typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = - typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = - typedArrayTags[uint32Tag] = true; - typedArrayTags[argsTag] = typedArrayTags[arrayTag] = - typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = - typedArrayTags[errorTag] = typedArrayTags[funcTag] = - typedArrayTags[mapTag] = typedArrayTags[numberTag] = - typedArrayTags[objectTag] = typedArrayTags[regexpTag] = - typedArrayTags[setTag] = typedArrayTags[stringTag] = - typedArrayTags[weakMapTag] = false; - - /** Detect free variable `global` from Node.js. */ - var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; - - /** Detect free variable `self`. */ - var freeSelf = typeof self == 'object' && self && self.Object === Object && self; - - /** Used as a reference to the global object. */ - var root = freeGlobal || freeSelf || Function('return this')(); - - /** Detect free variable `exports`. */ - var freeExports = exports && !exports.nodeType && exports; - - /** Detect free variable `module`. */ - var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; - - /** Detect the popular CommonJS extension `module.exports`. */ - var moduleExports = freeModule && freeModule.exports === freeExports; - - /** Detect free variable `process` from Node.js. */ - var freeProcess = moduleExports && freeGlobal.process; - - /** Used to access faster Node.js helpers. */ - var nodeUtil = (function() { - try { - return freeProcess && freeProcess.binding('util'); - } catch (e) {} - }()); - - /* Node.js helper references. */ - var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; - - /** - * A specialized version of `_.some` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - */ - function arraySome(array, predicate) { - var index = -1, - length = array ? array.length : 0; - - while (++index < length) { - if (predicate(array[index], index, array)) { - return true; - } - } - return false; - } - - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } - - /** - * The base implementation of `_.times` without support for iteratee shorthands - * or max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ - function baseTimes(n, iteratee) { - var index = -1, - result = Array(n); - - while (++index < n) { - result[index] = iteratee(index); - } - return result; - } - - /** - * The base implementation of `_.unary` without support for storing metadata. - * - * @private - * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new capped function. - */ - function baseUnary(func) { - return function(value) { - return func(value); - }; - } - - /** - * Gets the value at `key` of `object`. - * - * @private - * @param {Object} [object] The object to query. - * @param {string} key The key of the property to get. - * @returns {*} Returns the property value. - */ - function getValue(object, key) { - return object == null ? undefined : object[key]; - } - - /** - * Checks if `value` is a host object in IE < 9. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a host object, else `false`. - */ - function isHostObject(value) { - // Many host objects are `Object` objects that can coerce to strings - // despite having improperly defined `toString` methods. - var result = false; - if (value != null && typeof value.toString != 'function') { - try { - result = !!(value + ''); - } catch (e) {} - } - return result; - } - - /** - * Converts `map` to its key-value pairs. - * - * @private - * @param {Object} map The map to convert. - * @returns {Array} Returns the key-value pairs. - */ - function mapToArray(map) { - var index = -1, - result = Array(map.size); - - map.forEach(function(value, key) { - result[++index] = [key, value]; - }); - return result; - } - - /** - * Creates a unary function that invokes `func` with its argument transformed. - * - * @private - * @param {Function} func The function to wrap. - * @param {Function} transform The argument transform. - * @returns {Function} Returns the new function. - */ - function overArg(func, transform) { - return function(arg) { - return func(transform(arg)); - }; - } - - /** - * Converts `set` to an array of its values. - * - * @private - * @param {Object} set The set to convert. - * @returns {Array} Returns the values. - */ - function setToArray(set) { - var index = -1, - result = Array(set.size); - - set.forEach(function(value) { - result[++index] = value; - }); - return result; - } - - /** Used for built-in method references. */ - var arrayProto = Array.prototype, - funcProto = Function.prototype, - objectProto = Object.prototype; - - /** Used to detect overreaching core-js shims. */ - var coreJsData = root['__core-js_shared__']; - - /** Used to detect methods masquerading as native. */ - var maskSrcKey = (function() { - var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); - return uid ? ('Symbol(src)_1.' + uid) : ''; - }()); - - /** Used to resolve the decompiled source of functions. */ - var funcToString = funcProto.toString; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - - /** Used to detect if a method is native. */ - var reIsNative = RegExp('^' + - funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') - .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' - ); - - /** Built-in value references. */ - var Symbol = root.Symbol, - Uint8Array = root.Uint8Array, - propertyIsEnumerable = objectProto.propertyIsEnumerable, - splice = arrayProto.splice; - - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeKeys = overArg(Object.keys, Object); - - /* Built-in method references that are verified to be native. */ - var DataView = getNative(root, 'DataView'), - Map = getNative(root, 'Map'), - Promise = getNative(root, 'Promise'), - Set = getNative(root, 'Set'), - WeakMap = getNative(root, 'WeakMap'), - nativeCreate = getNative(Object, 'create'); - - /** Used to detect maps, sets, and weakmaps. */ - var dataViewCtorString = toSource(DataView), - mapCtorString = toSource(Map), - promiseCtorString = toSource(Promise), - setCtorString = toSource(Set), - weakMapCtorString = toSource(WeakMap); - - /** Used to convert symbols to primitives and strings. */ - var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolValueOf = symbolProto ? symbolProto.valueOf : undefined, - symbolToString = symbolProto ? symbolProto.toString : undefined; - - /** - * Creates a hash object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Hash(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the hash. - * - * @private - * @name clear - * @memberOf Hash - */ - function hashClear() { - this.__data__ = nativeCreate ? nativeCreate(null) : {}; - } - - /** - * Removes `key` and its value from the hash. - * - * @private - * @name delete - * @memberOf Hash - * @param {Object} hash The hash to modify. - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function hashDelete(key) { - return this.has(key) && delete this.__data__[key]; - } - - /** - * Gets the hash value for `key`. - * - * @private - * @name get - * @memberOf Hash - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function hashGet(key) { - var data = this.__data__; - if (nativeCreate) { - var result = data[key]; - return result === HASH_UNDEFINED ? undefined : result; - } - return hasOwnProperty.call(data, key) ? data[key] : undefined; - } - - /** - * Checks if a hash value for `key` exists. - * - * @private - * @name has - * @memberOf Hash - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function hashHas(key) { - var data = this.__data__; - return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key); - } - - /** - * Sets the hash `key` to `value`. - * - * @private - * @name set - * @memberOf Hash - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the hash instance. - */ - function hashSet(key, value) { - var data = this.__data__; - data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; - return this; - } - - // Add methods to `Hash`. - Hash.prototype.clear = hashClear; - Hash.prototype['delete'] = hashDelete; - Hash.prototype.get = hashGet; - Hash.prototype.has = hashHas; - Hash.prototype.set = hashSet; - - /** - * Creates an list cache object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function ListCache(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the list cache. - * - * @private - * @name clear - * @memberOf ListCache - */ - function listCacheClear() { - this.__data__ = []; - } - - /** - * Removes `key` and its value from the list cache. - * - * @private - * @name delete - * @memberOf ListCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function listCacheDelete(key) { - var data = this.__data__, - index = assocIndexOf(data, key); - - if (index < 0) { - return false; - } - var lastIndex = data.length - 1; - if (index == lastIndex) { - data.pop(); - } else { - splice.call(data, index, 1); - } - return true; - } - - /** - * Gets the list cache value for `key`. - * - * @private - * @name get - * @memberOf ListCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function listCacheGet(key) { - var data = this.__data__, - index = assocIndexOf(data, key); - - return index < 0 ? undefined : data[index][1]; - } - - /** - * Checks if a list cache value for `key` exists. - * - * @private - * @name has - * @memberOf ListCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function listCacheHas(key) { - return assocIndexOf(this.__data__, key) > -1; - } - - /** - * Sets the list cache `key` to `value`. - * - * @private - * @name set - * @memberOf ListCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the list cache instance. - */ - function listCacheSet(key, value) { - var data = this.__data__, - index = assocIndexOf(data, key); - - if (index < 0) { - data.push([key, value]); - } else { - data[index][1] = value; - } - return this; - } - - // Add methods to `ListCache`. - ListCache.prototype.clear = listCacheClear; - ListCache.prototype['delete'] = listCacheDelete; - ListCache.prototype.get = listCacheGet; - ListCache.prototype.has = listCacheHas; - ListCache.prototype.set = listCacheSet; - - /** - * Creates a map cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function MapCache(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the map. - * - * @private - * @name clear - * @memberOf MapCache - */ - function mapCacheClear() { - this.__data__ = { - 'hash': new Hash, - 'map': new (Map || ListCache), - 'string': new Hash - }; - } - - /** - * Removes `key` and its value from the map. - * - * @private - * @name delete - * @memberOf MapCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function mapCacheDelete(key) { - return getMapData(this, key)['delete'](key); - } - - /** - * Gets the map value for `key`. - * - * @private - * @name get - * @memberOf MapCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function mapCacheGet(key) { - return getMapData(this, key).get(key); - } - - /** - * Checks if a map value for `key` exists. - * - * @private - * @name has - * @memberOf MapCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function mapCacheHas(key) { - return getMapData(this, key).has(key); - } - - /** - * Sets the map `key` to `value`. - * - * @private - * @name set - * @memberOf MapCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the map cache instance. - */ - function mapCacheSet(key, value) { - getMapData(this, key).set(key, value); - return this; - } - - // Add methods to `MapCache`. - MapCache.prototype.clear = mapCacheClear; - MapCache.prototype['delete'] = mapCacheDelete; - MapCache.prototype.get = mapCacheGet; - MapCache.prototype.has = mapCacheHas; - MapCache.prototype.set = mapCacheSet; - - /** - * - * Creates an array cache object to store unique values. - * - * @private - * @constructor - * @param {Array} [values] The values to cache. - */ - function SetCache(values) { - var index = -1, - length = values ? values.length : 0; - - this.__data__ = new MapCache; - while (++index < length) { - this.add(values[index]); - } - } - - /** - * Adds `value` to the array cache. - * - * @private - * @name add - * @memberOf SetCache - * @alias push - * @param {*} value The value to cache. - * @returns {Object} Returns the cache instance. - */ - function setCacheAdd(value) { - this.__data__.set(value, HASH_UNDEFINED); - return this; - } - - /** - * Checks if `value` is in the array cache. - * - * @private - * @name has - * @memberOf SetCache - * @param {*} value The value to search for. - * @returns {number} Returns `true` if `value` is found, else `false`. - */ - function setCacheHas(value) { - return this.__data__.has(value); - } - - // Add methods to `SetCache`. - SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; - SetCache.prototype.has = setCacheHas; - - /** - * Creates a stack cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Stack(entries) { - this.__data__ = new ListCache(entries); - } - - /** - * Removes all key-value entries from the stack. - * - * @private - * @name clear - * @memberOf Stack - */ - function stackClear() { - this.__data__ = new ListCache; - } - - /** - * Removes `key` and its value from the stack. - * - * @private - * @name delete - * @memberOf Stack - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function stackDelete(key) { - return this.__data__['delete'](key); - } - - /** - * Gets the stack value for `key`. - * - * @private - * @name get - * @memberOf Stack - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function stackGet(key) { - return this.__data__.get(key); - } - - /** - * Checks if a stack value for `key` exists. - * - * @private - * @name has - * @memberOf Stack - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function stackHas(key) { - return this.__data__.has(key); - } - - /** - * Sets the stack `key` to `value`. - * - * @private - * @name set - * @memberOf Stack - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the stack cache instance. - */ - function stackSet(key, value) { - var cache = this.__data__; - if (cache instanceof ListCache) { - var pairs = cache.__data__; - if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { - pairs.push([key, value]); - return this; - } - cache = this.__data__ = new MapCache(pairs); - } - cache.set(key, value); - return this; - } - - // Add methods to `Stack`. - Stack.prototype.clear = stackClear; - Stack.prototype['delete'] = stackDelete; - Stack.prototype.get = stackGet; - Stack.prototype.has = stackHas; - Stack.prototype.set = stackSet; - - /** - * Creates an array of the enumerable property names of the array-like `value`. - * - * @private - * @param {*} value The value to query. - * @param {boolean} inherited Specify returning inherited property names. - * @returns {Array} Returns the array of property names. - */ - function arrayLikeKeys(value, inherited) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - // Safari 9 makes `arguments.length` enumerable in strict mode. - var result = (isArray(value) || isArguments(value)) - ? baseTimes(value.length, String) - : []; - - var length = result.length, - skipIndexes = !!length; - - for (var key in value) { - if ((inherited || hasOwnProperty.call(value, key)) && - !(skipIndexes && (key == 'length' || isIndex(key, length)))) { - result.push(key); - } - } - return result; - } - - /** - * Gets the index at which the `key` is found in `array` of key-value pairs. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} key The key to search for. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function assocIndexOf(array, key) { - var length = array.length; - while (length--) { - if (eq(array[length][0], key)) { - return length; - } - } - return -1; - } - - /** - * The base implementation of `_.get` without support for default values. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @returns {*} Returns the resolved value. - */ - function baseGet(object, path) { - path = isKey(path, object) ? [path] : castPath(path); - - var index = 0, - length = path.length; - - while (object != null && index < length) { - object = object[toKey(path[index++])]; - } - return (index && index == length) ? object : undefined; - } - - /** - * The base implementation of `getTag`. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - function baseGetTag(value) { - return objectToString.call(value); - } - - /** - * The base implementation of `_.hasIn` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ - function baseHasIn(object, key) { - return object != null && key in Object(object); - } - - /** - * The base implementation of `_.isEqual` which supports partial comparisons - * and tracks traversed objects. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @param {Function} [customizer] The function to customize comparisons. - * @param {boolean} [bitmask] The bitmask of comparison flags. - * The bitmask may be composed of the following flags: - * 1 - Unordered comparison - * 2 - Partial comparison - * @param {Object} [stack] Tracks traversed `value` and `other` objects. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - */ - function baseIsEqual(value, other, customizer, bitmask, stack) { - if (value === other) { - return true; - } - if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) { - return value !== value && other !== other; - } - return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack); - } - - /** - * A specialized version of `baseIsEqual` for arrays and objects which performs - * deep comparisons and tracks traversed objects enabling objects with circular - * references to be compared. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} [customizer] The function to customize comparisons. - * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} [stack] Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) { - var objIsArr = isArray(object), - othIsArr = isArray(other), - objTag = arrayTag, - othTag = arrayTag; - - if (!objIsArr) { - objTag = getTag(object); - objTag = objTag == argsTag ? objectTag : objTag; - } - if (!othIsArr) { - othTag = getTag(other); - othTag = othTag == argsTag ? objectTag : othTag; - } - var objIsObj = objTag == objectTag && !isHostObject(object), - othIsObj = othTag == objectTag && !isHostObject(other), - isSameTag = objTag == othTag; - - if (isSameTag && !objIsObj) { - stack || (stack = new Stack); - return (objIsArr || isTypedArray(object)) - ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) - : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack); - } - if (!(bitmask & PARTIAL_COMPARE_FLAG)) { - var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); - - if (objIsWrapped || othIsWrapped) { - var objUnwrapped = objIsWrapped ? object.value() : object, - othUnwrapped = othIsWrapped ? other.value() : other; - - stack || (stack = new Stack); - return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack); - } - } - if (!isSameTag) { - return false; - } - stack || (stack = new Stack); - return equalObjects(object, other, equalFunc, customizer, bitmask, stack); - } - - /** - * The base implementation of `_.isMatch` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to inspect. - * @param {Object} source The object of property values to match. - * @param {Array} matchData The property names, values, and compare flags to match. - * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if `object` is a match, else `false`. - */ - function baseIsMatch(object, source, matchData, customizer) { - var index = matchData.length, - length = index, - noCustomizer = !customizer; - - if (object == null) { - return !length; - } - object = Object(object); - while (index--) { - var data = matchData[index]; - if ((noCustomizer && data[2]) - ? data[1] !== object[data[0]] - : !(data[0] in object) - ) { - return false; - } - } - while (++index < length) { - data = matchData[index]; - var key = data[0], - objValue = object[key], - srcValue = data[1]; - - if (noCustomizer && data[2]) { - if (objValue === undefined && !(key in object)) { - return false; - } - } else { - var stack = new Stack; - if (customizer) { - var result = customizer(objValue, srcValue, key, object, source, stack); - } - if (!(result === undefined - ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) - : result - )) { - return false; - } - } - } - return true; - } - - /** - * The base implementation of `_.isNative` without bad shim checks. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, - * else `false`. - */ - function baseIsNative(value) { - if (!isObject(value) || isMasked(value)) { - return false; - } - var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; - return pattern.test(toSource(value)); - } - - /** - * The base implementation of `_.isTypedArray` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - */ - function baseIsTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; - } - - /** - * The base implementation of `_.iteratee`. - * - * @private - * @param {*} [value=_.identity] The value to convert to an iteratee. - * @returns {Function} Returns the iteratee. - */ - function baseIteratee(value) { - // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. - // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. - if (typeof value == 'function') { - return value; - } - if (value == null) { - return identity; - } - if (typeof value == 'object') { - return isArray(value) - ? baseMatchesProperty(value[0], value[1]) - : baseMatches(value); - } - return property(value); - } - - /** - * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function baseKeys(object) { - if (!isPrototype(object)) { - return nativeKeys(object); - } - var result = []; - for (var key in Object(object)) { - if (hasOwnProperty.call(object, key) && key != 'constructor') { - result.push(key); - } - } - return result; - } - - /** - * The base implementation of `_.matches` which doesn't clone `source`. - * - * @private - * @param {Object} source The object of property values to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatches(source) { - var matchData = getMatchData(source); - if (matchData.length == 1 && matchData[0][2]) { - return matchesStrictComparable(matchData[0][0], matchData[0][1]); - } - return function(object) { - return object === source || baseIsMatch(object, source, matchData); - }; - } - - /** - * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. - * - * @private - * @param {string} path The path of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatchesProperty(path, srcValue) { - if (isKey(path) && isStrictComparable(srcValue)) { - return matchesStrictComparable(toKey(path), srcValue); - } - return function(object) { - var objValue = get(object, path); - return (objValue === undefined && objValue === srcValue) - ? hasIn(object, path) - : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG); - }; - } - - /** - * A specialized version of `baseProperty` which supports deep paths. - * - * @private - * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function basePropertyDeep(path) { - return function(object) { - return baseGet(object, path); - }; - } - - /** - * The base implementation of `_.pullAt` without support for individual - * indexes or capturing the removed elements. - * - * @private - * @param {Array} array The array to modify. - * @param {number[]} indexes The indexes of elements to remove. - * @returns {Array} Returns `array`. - */ - function basePullAt(array, indexes) { - var length = array ? indexes.length : 0, - lastIndex = length - 1; - - while (length--) { - var index = indexes[length]; - if (length == lastIndex || index !== previous) { - var previous = index; - if (isIndex(index)) { - splice.call(array, index, 1); - } - else if (!isKey(index, array)) { - var path = castPath(index), - object = parent(array, path); - - if (object != null) { - delete object[toKey(last(path))]; - } - } - else { - delete array[toKey(index)]; - } - } - } - return array; - } - - /** - * The base implementation of `_.slice` without an iteratee call guard. - * - * @private - * @param {Array} array The array to slice. - * @param {number} [start=0] The start position. - * @param {number} [end=array.length] The end position. - * @returns {Array} Returns the slice of `array`. - */ - function baseSlice(array, start, end) { - var index = -1, - length = array.length; - - if (start < 0) { - start = -start > length ? 0 : (length + start); - } - end = end > length ? length : end; - if (end < 0) { - end += length; - } - length = start > end ? 0 : ((end - start) >>> 0); - start >>>= 0; - - var result = Array(length); - while (++index < length) { - result[index] = array[index + start]; - } - return result; - } - - /** - * The base implementation of `_.toString` which doesn't convert nullish - * values to empty strings. - * - * @private - * @param {*} value The value to process. - * @returns {string} Returns the string. - */ - function baseToString(value) { - // Exit early for strings to avoid a performance hit in some environments. - if (typeof value == 'string') { - return value; - } - if (isSymbol(value)) { - return symbolToString ? symbolToString.call(value) : ''; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } - - /** - * Casts `value` to a path array if it's not one. - * - * @private - * @param {*} value The value to inspect. - * @returns {Array} Returns the cast property path array. - */ - function castPath(value) { - return isArray(value) ? value : stringToPath(value); - } - - /** - * A specialized version of `baseIsEqualDeep` for arrays with support for - * partial deep comparisons. - * - * @private - * @param {Array} array The array to compare. - * @param {Array} other The other array to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `array` and `other` objects. - * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. - */ - function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { - var isPartial = bitmask & PARTIAL_COMPARE_FLAG, - arrLength = array.length, - othLength = other.length; - - if (arrLength != othLength && !(isPartial && othLength > arrLength)) { - return false; - } - // Assume cyclic values are equal. - var stacked = stack.get(array); - if (stacked && stack.get(other)) { - return stacked == other; - } - var index = -1, - result = true, - seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined; - - stack.set(array, other); - stack.set(other, array); - - // Ignore non-index properties. - while (++index < arrLength) { - var arrValue = array[index], - othValue = other[index]; - - if (customizer) { - var compared = isPartial - ? customizer(othValue, arrValue, index, other, array, stack) - : customizer(arrValue, othValue, index, array, other, stack); - } - if (compared !== undefined) { - if (compared) { - continue; - } - result = false; - break; - } - // Recursively compare arrays (susceptible to call stack limits). - if (seen) { - if (!arraySome(other, function(othValue, othIndex) { - if (!seen.has(othIndex) && - (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { - return seen.add(othIndex); - } - })) { - result = false; - break; - } - } else if (!( - arrValue === othValue || - equalFunc(arrValue, othValue, customizer, bitmask, stack) - )) { - result = false; - break; - } - } - stack['delete'](array); - stack['delete'](other); - return result; - } - - /** - * A specialized version of `baseIsEqualDeep` for comparing objects of - * the same `toStringTag`. - * - * **Note:** This function only supports comparing values with tags of - * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {string} tag The `toStringTag` of the objects to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { - switch (tag) { - case dataViewTag: - if ((object.byteLength != other.byteLength) || - (object.byteOffset != other.byteOffset)) { - return false; - } - object = object.buffer; - other = other.buffer; - - case arrayBufferTag: - if ((object.byteLength != other.byteLength) || - !equalFunc(new Uint8Array(object), new Uint8Array(other))) { - return false; - } - return true; - - case boolTag: - case dateTag: - case numberTag: - // Coerce booleans to `1` or `0` and dates to milliseconds. - // Invalid dates are coerced to `NaN`. - return eq(+object, +other); - - case errorTag: - return object.name == other.name && object.message == other.message; - - case regexpTag: - case stringTag: - // Coerce regexes to strings and treat strings, primitives and objects, - // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring - // for more details. - return object == (other + ''); - - case mapTag: - var convert = mapToArray; - - case setTag: - var isPartial = bitmask & PARTIAL_COMPARE_FLAG; - convert || (convert = setToArray); - - if (object.size != other.size && !isPartial) { - return false; - } - // Assume cyclic values are equal. - var stacked = stack.get(object); - if (stacked) { - return stacked == other; - } - bitmask |= UNORDERED_COMPARE_FLAG; - - // Recursively compare objects (susceptible to call stack limits). - stack.set(object, other); - var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); - stack['delete'](object); - return result; - - case symbolTag: - if (symbolValueOf) { - return symbolValueOf.call(object) == symbolValueOf.call(other); - } - } - return false; - } - - /** - * A specialized version of `baseIsEqualDeep` for objects with support for - * partial deep comparisons. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalObjects(object, other, equalFunc, customizer, bitmask, stack) { - var isPartial = bitmask & PARTIAL_COMPARE_FLAG, - objProps = keys(object), - objLength = objProps.length, - othProps = keys(other), - othLength = othProps.length; - - if (objLength != othLength && !isPartial) { - return false; - } - var index = objLength; - while (index--) { - var key = objProps[index]; - if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { - return false; - } - } - // Assume cyclic values are equal. - var stacked = stack.get(object); - if (stacked && stack.get(other)) { - return stacked == other; - } - var result = true; - stack.set(object, other); - stack.set(other, object); - - var skipCtor = isPartial; - while (++index < objLength) { - key = objProps[index]; - var objValue = object[key], - othValue = other[key]; - - if (customizer) { - var compared = isPartial - ? customizer(othValue, objValue, key, other, object, stack) - : customizer(objValue, othValue, key, object, other, stack); - } - // Recursively compare objects (susceptible to call stack limits). - if (!(compared === undefined - ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack)) - : compared - )) { - result = false; - break; - } - skipCtor || (skipCtor = key == 'constructor'); - } - if (result && !skipCtor) { - var objCtor = object.constructor, - othCtor = other.constructor; - - // Non `Object` object instances with different constructors are not equal. - if (objCtor != othCtor && - ('constructor' in object && 'constructor' in other) && - !(typeof objCtor == 'function' && objCtor instanceof objCtor && - typeof othCtor == 'function' && othCtor instanceof othCtor)) { - result = false; - } - } - stack['delete'](object); - stack['delete'](other); - return result; - } - - /** - * Gets the data for `map`. - * - * @private - * @param {Object} map The map to query. - * @param {string} key The reference key. - * @returns {*} Returns the map data. - */ - function getMapData(map, key) { - var data = map.__data__; - return isKeyable(key) - ? data[typeof key == 'string' ? 'string' : 'hash'] - : data.map; - } - - /** - * Gets the property names, values, and compare flags of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the match data of `object`. - */ - function getMatchData(object) { - var result = keys(object), - length = result.length; - - while (length--) { - var key = result[length], - value = object[key]; - - result[length] = [key, value, isStrictComparable(value)]; - } - return result; - } - - /** - * Gets the native function at `key` of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {string} key The key of the method to get. - * @returns {*} Returns the function if it's native, else `undefined`. - */ - function getNative(object, key) { - var value = getValue(object, key); - return baseIsNative(value) ? value : undefined; - } - - /** - * Gets the `toStringTag` of `value`. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - var getTag = baseGetTag; - - // Fallback for data views, maps, sets, and weak maps in IE 11, - // for data views in Edge < 14, and promises in Node.js. - if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || - (Map && getTag(new Map) != mapTag) || - (Promise && getTag(Promise.resolve()) != promiseTag) || - (Set && getTag(new Set) != setTag) || - (WeakMap && getTag(new WeakMap) != weakMapTag)) { - getTag = function(value) { - var result = objectToString.call(value), - Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : undefined; - - if (ctorString) { - switch (ctorString) { - case dataViewCtorString: return dataViewTag; - case mapCtorString: return mapTag; - case promiseCtorString: return promiseTag; - case setCtorString: return setTag; - case weakMapCtorString: return weakMapTag; - } - } - return result; - }; - } - - /** - * Checks if `path` exists on `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @param {Function} hasFunc The function to check properties. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - */ - function hasPath(object, path, hasFunc) { - path = isKey(path, object) ? [path] : castPath(path); - - var result, - index = -1, - length = path.length; - - while (++index < length) { - var key = toKey(path[index]); - if (!(result = object != null && hasFunc(object, key))) { - break; - } - object = object[key]; - } - if (result) { - return result; - } - var length = object ? object.length : 0; - return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isArguments(object)); - } - - /** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ - function isIndex(value, length) { - length = length == null ? MAX_SAFE_INTEGER : length; - return !!length && - (typeof value == 'number' || reIsUint.test(value)) && - (value > -1 && value % 1 == 0 && value < length); - } - - /** - * Checks if `value` is a property name and not a property path. - * - * @private - * @param {*} value The value to check. - * @param {Object} [object] The object to query keys on. - * @returns {boolean} Returns `true` if `value` is a property name, else `false`. - */ - function isKey(value, object) { - if (isArray(value)) { - return false; - } - var type = typeof value; - if (type == 'number' || type == 'symbol' || type == 'boolean' || - value == null || isSymbol(value)) { - return true; - } - return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || - (object != null && value in Object(object)); - } - - /** - * Checks if `value` is suitable for use as unique object key. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is suitable, else `false`. - */ - function isKeyable(value) { - var type = typeof value; - return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') - ? (value !== '__proto__') - : (value === null); - } - - /** - * Checks if `func` has its source masked. - * - * @private - * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` is masked, else `false`. - */ - function isMasked(func) { - return !!maskSrcKey && (maskSrcKey in func); - } - - /** - * Checks if `value` is likely a prototype object. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. - */ - function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; - - return value === proto; - } - - /** - * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` if suitable for strict - * equality comparisons, else `false`. - */ - function isStrictComparable(value) { - return value === value && !isObject(value); - } - - /** - * A specialized version of `matchesProperty` for source values suitable - * for strict equality comparisons, i.e. `===`. - * - * @private - * @param {string} key The key of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function matchesStrictComparable(key, srcValue) { - return function(object) { - if (object == null) { - return false; - } - return object[key] === srcValue && - (srcValue !== undefined || (key in Object(object))); - }; - } - - /** - * Gets the parent value at `path` of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Array} path The path to get the parent value of. - * @returns {*} Returns the parent value. - */ - function parent(object, path) { - return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); - } - - /** - * Converts `string` to a property path array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the property path array. - */ - var stringToPath = memoize(function(string) { - string = toString(string); - - var result = []; - if (reLeadingDot.test(string)) { - result.push(''); - } - string.replace(rePropName, function(match, number, quote, string) { - result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); - }); - return result; - }); - - /** - * Converts `value` to a string key if it's not a string or symbol. - * - * @private - * @param {*} value The value to inspect. - * @returns {string|symbol} Returns the key. - */ - function toKey(value) { - if (typeof value == 'string' || isSymbol(value)) { - return value; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } - - /** - * Converts `func` to its source code. - * - * @private - * @param {Function} func The function to process. - * @returns {string} Returns the source code. - */ - function toSource(func) { - if (func != null) { - try { - return funcToString.call(func); - } catch (e) {} - try { - return (func + ''); - } catch (e) {} - } - return ''; - } - - /** - * Gets the last element of `array`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Array - * @param {Array} array The array to query. - * @returns {*} Returns the last element of `array`. - * @example - * - * _.last([1, 2, 3]); - * // => 3 - */ - function last(array) { - var length = array ? array.length : 0; - return length ? array[length - 1] : undefined; - } - - /** - * Removes all elements from `array` that `predicate` returns truthy for - * and returns an array of the removed elements. The predicate is invoked - * with three arguments: (value, index, array). - * - * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` - * to pull elements from an array by value. - * - * @static - * @memberOf _ - * @since 2.0.0 - * @category Array - * @param {Array} array The array to modify. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. - * @returns {Array} Returns the new array of removed elements. - * @example - * - * var array = [1, 2, 3, 4]; - * var evens = _.remove(array, function(n) { - * return n % 2 == 0; - * }); - * - * console.log(array); - * // => [1, 3] - * - * console.log(evens); - * // => [2, 4] - */ - function remove(array, predicate) { - var result = []; - if (!(array && array.length)) { - return result; - } - var index = -1, - indexes = [], - length = array.length; - - predicate = baseIteratee(predicate); - while (++index < length) { - var value = array[index]; - if (predicate(value, index, array)) { - result.push(value); - indexes.push(index); - } - } - basePullAt(array, indexes); - return result; - } - - /** - * Creates a function that memoizes the result of `func`. If `resolver` is - * provided, it determines the cache key for storing the result based on the - * arguments provided to the memoized function. By default, the first argument - * provided to the memoized function is used as the map cache key. The `func` - * is invoked with the `this` binding of the memoized function. - * - * **Note:** The cache is exposed as the `cache` property on the memoized - * function. Its creation may be customized by replacing the `_.memoize.Cache` - * constructor with one whose instances implement the - * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) - * method interface of `delete`, `get`, `has`, and `set`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] The function to resolve the cache key. - * @returns {Function} Returns the new memoized function. - * @example - * - * var object = { 'a': 1, 'b': 2 }; - * var other = { 'c': 3, 'd': 4 }; - * - * var values = _.memoize(_.values); - * values(object); - * // => [1, 2] - * - * values(other); - * // => [3, 4] - * - * object.a = 2; - * values(object); - * // => [1, 2] - * - * // Modify the result cache. - * values.cache.set(object, ['a', 'b']); - * values(object); - * // => ['a', 'b'] - * - * // Replace `_.memoize.Cache`. - * _.memoize.Cache = WeakMap; - */ - function memoize(func, resolver) { - if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { - throw new TypeError(FUNC_ERROR_TEXT); - } - var memoized = function() { - var args = arguments, - key = resolver ? resolver.apply(this, args) : args[0], - cache = memoized.cache; - - if (cache.has(key)) { - return cache.get(key); - } - var result = func.apply(this, args); - memoized.cache = cache.set(key, result); - return result; - }; - memoized.cache = new (memoize.Cache || MapCache); - return memoized; - } - - // Assign cache to `_.memoize`. - memoize.Cache = MapCache; - - /** - * Performs a - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * comparison between two values to determine if they are equivalent. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.eq(object, object); - * // => true - * - * _.eq(object, other); - * // => false - * - * _.eq('a', 'a'); - * // => true - * - * _.eq('a', Object('a')); - * // => false - * - * _.eq(NaN, NaN); - * // => true - */ - function eq(value, other) { - return value === other || (value !== value && other !== other); - } - - /** - * Checks if `value` is likely an `arguments` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. - * @example - * - * _.isArguments(function() { return arguments; }()); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ - function isArguments(value) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && - (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); - } - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; - - /** - * Checks if `value` is array-like. A value is considered array-like if it's - * not a function and has a `value.length` that's an integer greater than or - * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. - * @example - * - * _.isArrayLike([1, 2, 3]); - * // => true - * - * _.isArrayLike(document.body.children); - * // => true - * - * _.isArrayLike('abc'); - * // => true - * - * _.isArrayLike(_.noop); - * // => false - */ - function isArrayLike(value) { - return value != null && isLength(value.length) && !isFunction(value); - } - - /** - * This method is like `_.isArrayLike` except that it also checks if `value` - * is an object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, - * else `false`. - * @example - * - * _.isArrayLikeObject([1, 2, 3]); - * // => true - * - * _.isArrayLikeObject(document.body.children); - * // => true - * - * _.isArrayLikeObject('abc'); - * // => false - * - * _.isArrayLikeObject(_.noop); - * // => false - */ - function isArrayLikeObject(value) { - return isObjectLike(value) && isArrayLike(value); - } - - /** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a function, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ - function isFunction(value) { - // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8-9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag; - } - - /** - * Checks if `value` is a valid array-like length. - * - * **Note:** This method is loosely based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. - * @example - * - * _.isLength(3); - * // => true - * - * _.isLength(Number.MIN_VALUE); - * // => false - * - * _.isLength(Infinity); - * // => false - * - * _.isLength('3'); - * // => false - */ - function isLength(value) { - return typeof value == 'number' && - value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; - } - - /** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ - function isObject(value) { - var type = typeof value; - return !!value && (type == 'object' || type == 'function'); - } - - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return !!value && typeof value == 'object'; - } - - /** - * Checks if `value` is classified as a `Symbol` primitive or object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. - * @example - * - * _.isSymbol(Symbol.iterator); - * // => true - * - * _.isSymbol('abc'); - * // => false - */ - function isSymbol(value) { - return typeof value == 'symbol' || - (isObjectLike(value) && objectToString.call(value) == symbolTag); - } - - /** - * Checks if `value` is classified as a typed array. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - * @example - * - * _.isTypedArray(new Uint8Array); - * // => true - * - * _.isTypedArray([]); - * // => false - */ - var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; - - /** - * Converts `value` to a string. An empty string is returned for `null` - * and `undefined` values. The sign of `-0` is preserved. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to process. - * @returns {string} Returns the string. - * @example - * - * _.toString(null); - * // => '' - * - * _.toString(-0); - * // => '-0' - * - * _.toString([1, 2, 3]); - * // => '1,2,3' - */ - function toString(value) { - return value == null ? '' : baseToString(value); - } - - /** - * Gets the value at `path` of `object`. If the resolved value is - * `undefined`, the `defaultValue` is returned in its place. - * - * @static - * @memberOf _ - * @since 3.7.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @param {*} [defaultValue] The value returned for `undefined` resolved values. - * @returns {*} Returns the resolved value. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }] }; - * - * _.get(object, 'a[0].b.c'); - * // => 3 - * - * _.get(object, ['a', '0', 'b', 'c']); - * // => 3 - * - * _.get(object, 'a.b.c', 'default'); - * // => 'default' - */ - function get(object, path, defaultValue) { - var result = object == null ? undefined : baseGet(object, path); - return result === undefined ? defaultValue : result; - } - - /** - * Checks if `path` is a direct or inherited property of `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - * @example - * - * var object = _.create({ 'a': _.create({ 'b': 2 }) }); - * - * _.hasIn(object, 'a'); - * // => true - * - * _.hasIn(object, 'a.b'); - * // => true - * - * _.hasIn(object, ['a', 'b']); - * // => true - * - * _.hasIn(object, 'b'); - * // => false - */ - function hasIn(object, path) { - return object != null && hasPath(object, path, baseHasIn); - } - - /** - * Creates an array of the own enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. See the - * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * for more details. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keys(new Foo); - * // => ['a', 'b'] (iteration order is not guaranteed) - * - * _.keys('hi'); - * // => ['0', '1'] - */ - function keys(object) { - return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); - } - - /** - * This method returns the first argument it receives. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Util - * @param {*} value Any value. - * @returns {*} Returns `value`. - * @example - * - * var object = { 'a': 1 }; - * - * console.log(_.identity(object) === object); - * // => true - */ - function identity(value) { - return value; - } - - /** - * Creates a function that returns the value at `path` of a given object. - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Util - * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new accessor function. - * @example - * - * var objects = [ - * { 'a': { 'b': 2 } }, - * { 'a': { 'b': 1 } } - * ]; - * - * _.map(objects, _.property('a.b')); - * // => [2, 1] - * - * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b'); - * // => [1, 2] - */ - function property(path) { - return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path); - } - - module.exports = remove; - }); - - var lodash_filter = createCommonjsModule(function (module, exports) { - /** - * lodash (Custom Build) - * Build: `lodash modularize exports="npm" -o ./` - * Copyright jQuery Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ - - /** Used as the size to enable large array optimizations. */ - var LARGE_ARRAY_SIZE = 200; - - /** Used as the `TypeError` message for "Functions" methods. */ - var FUNC_ERROR_TEXT = 'Expected a function'; - - /** Used to stand-in for `undefined` hash values. */ - var HASH_UNDEFINED = '__lodash_hash_undefined__'; - - /** Used to compose bitmasks for comparison styles. */ - var UNORDERED_COMPARE_FLAG = 1, - PARTIAL_COMPARE_FLAG = 2; - - /** Used as references for various `Number` constants. */ - var INFINITY = 1 / 0, - MAX_SAFE_INTEGER = 9007199254740991; - - /** `Object#toString` result references. */ - var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]', - mapTag = '[object Map]', - numberTag = '[object Number]', - objectTag = '[object Object]', - promiseTag = '[object Promise]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - symbolTag = '[object Symbol]', - weakMapTag = '[object WeakMap]'; - - var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; - - /** Used to match property names within property paths. */ - var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, - reIsPlainProp = /^\w*$/, - reLeadingDot = /^\./, - rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; - - /** - * Used to match `RegExp` - * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). - */ - var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; - - /** Used to match backslashes in property paths. */ - var reEscapeChar = /\\(\\)?/g; - - /** Used to detect host constructors (Safari). */ - var reIsHostCtor = /^\[object .+?Constructor\]$/; - - /** Used to detect unsigned integer values. */ - var reIsUint = /^(?:0|[1-9]\d*)$/; - - /** Used to identify `toStringTag` values of typed arrays. */ - var typedArrayTags = {}; - typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = - typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = - typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = - typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = - typedArrayTags[uint32Tag] = true; - typedArrayTags[argsTag] = typedArrayTags[arrayTag] = - typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = - typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = - typedArrayTags[errorTag] = typedArrayTags[funcTag] = - typedArrayTags[mapTag] = typedArrayTags[numberTag] = - typedArrayTags[objectTag] = typedArrayTags[regexpTag] = - typedArrayTags[setTag] = typedArrayTags[stringTag] = - typedArrayTags[weakMapTag] = false; - - /** Detect free variable `global` from Node.js. */ - var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; - - /** Detect free variable `self`. */ - var freeSelf = typeof self == 'object' && self && self.Object === Object && self; - - /** Used as a reference to the global object. */ - var root = freeGlobal || freeSelf || Function('return this')(); - - /** Detect free variable `exports`. */ - var freeExports = exports && !exports.nodeType && exports; - - /** Detect free variable `module`. */ - var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; - - /** Detect the popular CommonJS extension `module.exports`. */ - var moduleExports = freeModule && freeModule.exports === freeExports; - - /** Detect free variable `process` from Node.js. */ - var freeProcess = moduleExports && freeGlobal.process; - - /** Used to access faster Node.js helpers. */ - var nodeUtil = (function() { - try { - return freeProcess && freeProcess.binding('util'); - } catch (e) {} - }()); - - /* Node.js helper references. */ - var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; - - /** - * A specialized version of `_.filter` for arrays without support for - * iteratee shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - */ - function arrayFilter(array, predicate) { - var index = -1, - length = array ? array.length : 0, - resIndex = 0, - result = []; - - while (++index < length) { - var value = array[index]; - if (predicate(value, index, array)) { - result[resIndex++] = value; - } - } - return result; - } - - /** - * A specialized version of `_.some` for arrays without support for iteratee - * shorthands. - * - * @private - * @param {Array} [array] The array to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {boolean} Returns `true` if any element passes the predicate check, - * else `false`. - */ - function arraySome(array, predicate) { - var index = -1, - length = array ? array.length : 0; - - while (++index < length) { - if (predicate(array[index], index, array)) { - return true; - } - } - return false; - } - - /** - * The base implementation of `_.property` without support for deep paths. - * - * @private - * @param {string} key The key of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; - }; - } - - /** - * The base implementation of `_.times` without support for iteratee shorthands - * or max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ - function baseTimes(n, iteratee) { - var index = -1, - result = Array(n); - - while (++index < n) { - result[index] = iteratee(index); - } - return result; - } - - /** - * The base implementation of `_.unary` without support for storing metadata. - * - * @private - * @param {Function} func The function to cap arguments for. - * @returns {Function} Returns the new capped function. - */ - function baseUnary(func) { - return function(value) { - return func(value); - }; - } - - /** - * Gets the value at `key` of `object`. - * - * @private - * @param {Object} [object] The object to query. - * @param {string} key The key of the property to get. - * @returns {*} Returns the property value. - */ - function getValue(object, key) { - return object == null ? undefined : object[key]; - } - - /** - * Checks if `value` is a host object in IE < 9. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a host object, else `false`. - */ - function isHostObject(value) { - // Many host objects are `Object` objects that can coerce to strings - // despite having improperly defined `toString` methods. - var result = false; - if (value != null && typeof value.toString != 'function') { - try { - result = !!(value + ''); - } catch (e) {} - } - return result; - } - - /** - * Converts `map` to its key-value pairs. - * - * @private - * @param {Object} map The map to convert. - * @returns {Array} Returns the key-value pairs. - */ - function mapToArray(map) { - var index = -1, - result = Array(map.size); - - map.forEach(function(value, key) { - result[++index] = [key, value]; - }); - return result; - } - - /** - * Creates a unary function that invokes `func` with its argument transformed. - * - * @private - * @param {Function} func The function to wrap. - * @param {Function} transform The argument transform. - * @returns {Function} Returns the new function. - */ - function overArg(func, transform) { - return function(arg) { - return func(transform(arg)); - }; - } - - /** - * Converts `set` to an array of its values. - * - * @private - * @param {Object} set The set to convert. - * @returns {Array} Returns the values. - */ - function setToArray(set) { - var index = -1, - result = Array(set.size); - - set.forEach(function(value) { - result[++index] = value; - }); - return result; - } - - /** Used for built-in method references. */ - var arrayProto = Array.prototype, - funcProto = Function.prototype, - objectProto = Object.prototype; - - /** Used to detect overreaching core-js shims. */ - var coreJsData = root['__core-js_shared__']; - - /** Used to detect methods masquerading as native. */ - var maskSrcKey = (function() { - var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); - return uid ? ('Symbol(src)_1.' + uid) : ''; - }()); - - /** Used to resolve the decompiled source of functions. */ - var funcToString = funcProto.toString; - - /** Used to check objects for own properties. */ - var hasOwnProperty = objectProto.hasOwnProperty; - - /** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ - var objectToString = objectProto.toString; - - /** Used to detect if a method is native. */ - var reIsNative = RegExp('^' + - funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') - .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' - ); - - /** Built-in value references. */ - var Symbol = root.Symbol, - Uint8Array = root.Uint8Array, - propertyIsEnumerable = objectProto.propertyIsEnumerable, - splice = arrayProto.splice; - - /* Built-in method references for those with the same name as other `lodash` methods. */ - var nativeKeys = overArg(Object.keys, Object); - - /* Built-in method references that are verified to be native. */ - var DataView = getNative(root, 'DataView'), - Map = getNative(root, 'Map'), - Promise = getNative(root, 'Promise'), - Set = getNative(root, 'Set'), - WeakMap = getNative(root, 'WeakMap'), - nativeCreate = getNative(Object, 'create'); - - /** Used to detect maps, sets, and weakmaps. */ - var dataViewCtorString = toSource(DataView), - mapCtorString = toSource(Map), - promiseCtorString = toSource(Promise), - setCtorString = toSource(Set), - weakMapCtorString = toSource(WeakMap); - - /** Used to convert symbols to primitives and strings. */ - var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolValueOf = symbolProto ? symbolProto.valueOf : undefined, - symbolToString = symbolProto ? symbolProto.toString : undefined; - - /** - * Creates a hash object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Hash(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the hash. - * - * @private - * @name clear - * @memberOf Hash - */ - function hashClear() { - this.__data__ = nativeCreate ? nativeCreate(null) : {}; - } - - /** - * Removes `key` and its value from the hash. - * - * @private - * @name delete - * @memberOf Hash - * @param {Object} hash The hash to modify. - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function hashDelete(key) { - return this.has(key) && delete this.__data__[key]; - } - - /** - * Gets the hash value for `key`. - * - * @private - * @name get - * @memberOf Hash - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function hashGet(key) { - var data = this.__data__; - if (nativeCreate) { - var result = data[key]; - return result === HASH_UNDEFINED ? undefined : result; - } - return hasOwnProperty.call(data, key) ? data[key] : undefined; - } - - /** - * Checks if a hash value for `key` exists. - * - * @private - * @name has - * @memberOf Hash - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function hashHas(key) { - var data = this.__data__; - return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key); - } - - /** - * Sets the hash `key` to `value`. - * - * @private - * @name set - * @memberOf Hash - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the hash instance. - */ - function hashSet(key, value) { - var data = this.__data__; - data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value; - return this; - } - - // Add methods to `Hash`. - Hash.prototype.clear = hashClear; - Hash.prototype['delete'] = hashDelete; - Hash.prototype.get = hashGet; - Hash.prototype.has = hashHas; - Hash.prototype.set = hashSet; - - /** - * Creates an list cache object. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function ListCache(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the list cache. - * - * @private - * @name clear - * @memberOf ListCache - */ - function listCacheClear() { - this.__data__ = []; - } - - /** - * Removes `key` and its value from the list cache. - * - * @private - * @name delete - * @memberOf ListCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function listCacheDelete(key) { - var data = this.__data__, - index = assocIndexOf(data, key); - - if (index < 0) { - return false; - } - var lastIndex = data.length - 1; - if (index == lastIndex) { - data.pop(); - } else { - splice.call(data, index, 1); - } - return true; - } - - /** - * Gets the list cache value for `key`. - * - * @private - * @name get - * @memberOf ListCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function listCacheGet(key) { - var data = this.__data__, - index = assocIndexOf(data, key); - - return index < 0 ? undefined : data[index][1]; - } - - /** - * Checks if a list cache value for `key` exists. - * - * @private - * @name has - * @memberOf ListCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function listCacheHas(key) { - return assocIndexOf(this.__data__, key) > -1; - } - - /** - * Sets the list cache `key` to `value`. - * - * @private - * @name set - * @memberOf ListCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the list cache instance. - */ - function listCacheSet(key, value) { - var data = this.__data__, - index = assocIndexOf(data, key); - - if (index < 0) { - data.push([key, value]); - } else { - data[index][1] = value; - } - return this; - } - - // Add methods to `ListCache`. - ListCache.prototype.clear = listCacheClear; - ListCache.prototype['delete'] = listCacheDelete; - ListCache.prototype.get = listCacheGet; - ListCache.prototype.has = listCacheHas; - ListCache.prototype.set = listCacheSet; - - /** - * Creates a map cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function MapCache(entries) { - var index = -1, - length = entries ? entries.length : 0; - - this.clear(); - while (++index < length) { - var entry = entries[index]; - this.set(entry[0], entry[1]); - } - } - - /** - * Removes all key-value entries from the map. - * - * @private - * @name clear - * @memberOf MapCache - */ - function mapCacheClear() { - this.__data__ = { - 'hash': new Hash, - 'map': new (Map || ListCache), - 'string': new Hash - }; - } - - /** - * Removes `key` and its value from the map. - * - * @private - * @name delete - * @memberOf MapCache - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function mapCacheDelete(key) { - return getMapData(this, key)['delete'](key); - } - - /** - * Gets the map value for `key`. - * - * @private - * @name get - * @memberOf MapCache - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function mapCacheGet(key) { - return getMapData(this, key).get(key); - } - - /** - * Checks if a map value for `key` exists. - * - * @private - * @name has - * @memberOf MapCache - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function mapCacheHas(key) { - return getMapData(this, key).has(key); - } - - /** - * Sets the map `key` to `value`. - * - * @private - * @name set - * @memberOf MapCache - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the map cache instance. - */ - function mapCacheSet(key, value) { - getMapData(this, key).set(key, value); - return this; - } - - // Add methods to `MapCache`. - MapCache.prototype.clear = mapCacheClear; - MapCache.prototype['delete'] = mapCacheDelete; - MapCache.prototype.get = mapCacheGet; - MapCache.prototype.has = mapCacheHas; - MapCache.prototype.set = mapCacheSet; - - /** - * - * Creates an array cache object to store unique values. - * - * @private - * @constructor - * @param {Array} [values] The values to cache. - */ - function SetCache(values) { - var index = -1, - length = values ? values.length : 0; - - this.__data__ = new MapCache; - while (++index < length) { - this.add(values[index]); - } - } - - /** - * Adds `value` to the array cache. - * - * @private - * @name add - * @memberOf SetCache - * @alias push - * @param {*} value The value to cache. - * @returns {Object} Returns the cache instance. - */ - function setCacheAdd(value) { - this.__data__.set(value, HASH_UNDEFINED); - return this; - } - - /** - * Checks if `value` is in the array cache. - * - * @private - * @name has - * @memberOf SetCache - * @param {*} value The value to search for. - * @returns {number} Returns `true` if `value` is found, else `false`. - */ - function setCacheHas(value) { - return this.__data__.has(value); - } - - // Add methods to `SetCache`. - SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; - SetCache.prototype.has = setCacheHas; - - /** - * Creates a stack cache object to store key-value pairs. - * - * @private - * @constructor - * @param {Array} [entries] The key-value pairs to cache. - */ - function Stack(entries) { - this.__data__ = new ListCache(entries); - } - - /** - * Removes all key-value entries from the stack. - * - * @private - * @name clear - * @memberOf Stack - */ - function stackClear() { - this.__data__ = new ListCache; - } - - /** - * Removes `key` and its value from the stack. - * - * @private - * @name delete - * @memberOf Stack - * @param {string} key The key of the value to remove. - * @returns {boolean} Returns `true` if the entry was removed, else `false`. - */ - function stackDelete(key) { - return this.__data__['delete'](key); - } - - /** - * Gets the stack value for `key`. - * - * @private - * @name get - * @memberOf Stack - * @param {string} key The key of the value to get. - * @returns {*} Returns the entry value. - */ - function stackGet(key) { - return this.__data__.get(key); - } - - /** - * Checks if a stack value for `key` exists. - * - * @private - * @name has - * @memberOf Stack - * @param {string} key The key of the entry to check. - * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. - */ - function stackHas(key) { - return this.__data__.has(key); - } - - /** - * Sets the stack `key` to `value`. - * - * @private - * @name set - * @memberOf Stack - * @param {string} key The key of the value to set. - * @param {*} value The value to set. - * @returns {Object} Returns the stack cache instance. - */ - function stackSet(key, value) { - var cache = this.__data__; - if (cache instanceof ListCache) { - var pairs = cache.__data__; - if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { - pairs.push([key, value]); - return this; - } - cache = this.__data__ = new MapCache(pairs); - } - cache.set(key, value); - return this; - } - - // Add methods to `Stack`. - Stack.prototype.clear = stackClear; - Stack.prototype['delete'] = stackDelete; - Stack.prototype.get = stackGet; - Stack.prototype.has = stackHas; - Stack.prototype.set = stackSet; - - /** - * Creates an array of the enumerable property names of the array-like `value`. - * - * @private - * @param {*} value The value to query. - * @param {boolean} inherited Specify returning inherited property names. - * @returns {Array} Returns the array of property names. - */ - function arrayLikeKeys(value, inherited) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - // Safari 9 makes `arguments.length` enumerable in strict mode. - var result = (isArray(value) || isArguments(value)) - ? baseTimes(value.length, String) - : []; - - var length = result.length, - skipIndexes = !!length; - - for (var key in value) { - if ((inherited || hasOwnProperty.call(value, key)) && - !(skipIndexes && (key == 'length' || isIndex(key, length)))) { - result.push(key); - } - } - return result; - } - - /** - * Gets the index at which the `key` is found in `array` of key-value pairs. - * - * @private - * @param {Array} array The array to inspect. - * @param {*} key The key to search for. - * @returns {number} Returns the index of the matched value, else `-1`. - */ - function assocIndexOf(array, key) { - var length = array.length; - while (length--) { - if (eq(array[length][0], key)) { - return length; - } - } - return -1; - } - - /** - * The base implementation of `_.forEach` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array|Object} Returns `collection`. - */ - var baseEach = createBaseEach(baseForOwn); - - /** - * The base implementation of `_.filter` without support for iteratee shorthands. - * - * @private - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} predicate The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - */ - function baseFilter(collection, predicate) { - var result = []; - baseEach(collection, function(value, index, collection) { - if (predicate(value, index, collection)) { - result.push(value); - } - }); - return result; - } - - /** - * The base implementation of `baseForOwn` which iterates over `object` - * properties returned by `keysFunc` and invokes `iteratee` for each property. - * Iteratee functions may exit iteration early by explicitly returning `false`. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {Function} keysFunc The function to get the keys of `object`. - * @returns {Object} Returns `object`. - */ - var baseFor = createBaseFor(); - - /** - * The base implementation of `_.forOwn` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. - */ - function baseForOwn(object, iteratee) { - return object && baseFor(object, iteratee, keys); - } - - /** - * The base implementation of `_.get` without support for default values. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @returns {*} Returns the resolved value. - */ - function baseGet(object, path) { - path = isKey(path, object) ? [path] : castPath(path); - - var index = 0, - length = path.length; - - while (object != null && index < length) { - object = object[toKey(path[index++])]; - } - return (index && index == length) ? object : undefined; - } - - /** - * The base implementation of `getTag`. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - function baseGetTag(value) { - return objectToString.call(value); - } - - /** - * The base implementation of `_.hasIn` without support for deep paths. - * - * @private - * @param {Object} [object] The object to query. - * @param {Array|string} key The key to check. - * @returns {boolean} Returns `true` if `key` exists, else `false`. - */ - function baseHasIn(object, key) { - return object != null && key in Object(object); - } - - /** - * The base implementation of `_.isEqual` which supports partial comparisons - * and tracks traversed objects. - * - * @private - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @param {Function} [customizer] The function to customize comparisons. - * @param {boolean} [bitmask] The bitmask of comparison flags. - * The bitmask may be composed of the following flags: - * 1 - Unordered comparison - * 2 - Partial comparison - * @param {Object} [stack] Tracks traversed `value` and `other` objects. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - */ - function baseIsEqual(value, other, customizer, bitmask, stack) { - if (value === other) { - return true; - } - if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) { - return value !== value && other !== other; - } - return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack); - } - - /** - * A specialized version of `baseIsEqual` for arrays and objects which performs - * deep comparisons and tracks traversed objects enabling objects with circular - * references to be compared. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} [customizer] The function to customize comparisons. - * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} [stack] Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) { - var objIsArr = isArray(object), - othIsArr = isArray(other), - objTag = arrayTag, - othTag = arrayTag; - - if (!objIsArr) { - objTag = getTag(object); - objTag = objTag == argsTag ? objectTag : objTag; - } - if (!othIsArr) { - othTag = getTag(other); - othTag = othTag == argsTag ? objectTag : othTag; - } - var objIsObj = objTag == objectTag && !isHostObject(object), - othIsObj = othTag == objectTag && !isHostObject(other), - isSameTag = objTag == othTag; - - if (isSameTag && !objIsObj) { - stack || (stack = new Stack); - return (objIsArr || isTypedArray(object)) - ? equalArrays(object, other, equalFunc, customizer, bitmask, stack) - : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack); - } - if (!(bitmask & PARTIAL_COMPARE_FLAG)) { - var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); - - if (objIsWrapped || othIsWrapped) { - var objUnwrapped = objIsWrapped ? object.value() : object, - othUnwrapped = othIsWrapped ? other.value() : other; - - stack || (stack = new Stack); - return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack); - } - } - if (!isSameTag) { - return false; - } - stack || (stack = new Stack); - return equalObjects(object, other, equalFunc, customizer, bitmask, stack); - } - - /** - * The base implementation of `_.isMatch` without support for iteratee shorthands. - * - * @private - * @param {Object} object The object to inspect. - * @param {Object} source The object of property values to match. - * @param {Array} matchData The property names, values, and compare flags to match. - * @param {Function} [customizer] The function to customize comparisons. - * @returns {boolean} Returns `true` if `object` is a match, else `false`. - */ - function baseIsMatch(object, source, matchData, customizer) { - var index = matchData.length, - length = index, - noCustomizer = !customizer; - - if (object == null) { - return !length; - } - object = Object(object); - while (index--) { - var data = matchData[index]; - if ((noCustomizer && data[2]) - ? data[1] !== object[data[0]] - : !(data[0] in object) - ) { - return false; - } - } - while (++index < length) { - data = matchData[index]; - var key = data[0], - objValue = object[key], - srcValue = data[1]; - - if (noCustomizer && data[2]) { - if (objValue === undefined && !(key in object)) { - return false; - } - } else { - var stack = new Stack; - if (customizer) { - var result = customizer(objValue, srcValue, key, object, source, stack); - } - if (!(result === undefined - ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack) - : result - )) { - return false; - } - } - } - return true; - } - - /** - * The base implementation of `_.isNative` without bad shim checks. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, - * else `false`. - */ - function baseIsNative(value) { - if (!isObject(value) || isMasked(value)) { - return false; - } - var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor; - return pattern.test(toSource(value)); - } - - /** - * The base implementation of `_.isTypedArray` without Node.js optimizations. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - */ - function baseIsTypedArray(value) { - return isObjectLike(value) && - isLength(value.length) && !!typedArrayTags[objectToString.call(value)]; - } - - /** - * The base implementation of `_.iteratee`. - * - * @private - * @param {*} [value=_.identity] The value to convert to an iteratee. - * @returns {Function} Returns the iteratee. - */ - function baseIteratee(value) { - // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. - // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. - if (typeof value == 'function') { - return value; - } - if (value == null) { - return identity; - } - if (typeof value == 'object') { - return isArray(value) - ? baseMatchesProperty(value[0], value[1]) - : baseMatches(value); - } - return property(value); - } - - /** - * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ - function baseKeys(object) { - if (!isPrototype(object)) { - return nativeKeys(object); - } - var result = []; - for (var key in Object(object)) { - if (hasOwnProperty.call(object, key) && key != 'constructor') { - result.push(key); - } - } - return result; - } - - /** - * The base implementation of `_.matches` which doesn't clone `source`. - * - * @private - * @param {Object} source The object of property values to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatches(source) { - var matchData = getMatchData(source); - if (matchData.length == 1 && matchData[0][2]) { - return matchesStrictComparable(matchData[0][0], matchData[0][1]); - } - return function(object) { - return object === source || baseIsMatch(object, source, matchData); - }; - } - - /** - * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. - * - * @private - * @param {string} path The path of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function baseMatchesProperty(path, srcValue) { - if (isKey(path) && isStrictComparable(srcValue)) { - return matchesStrictComparable(toKey(path), srcValue); - } - return function(object) { - var objValue = get(object, path); - return (objValue === undefined && objValue === srcValue) - ? hasIn(object, path) - : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG); - }; - } - - /** - * A specialized version of `baseProperty` which supports deep paths. - * - * @private - * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new accessor function. - */ - function basePropertyDeep(path) { - return function(object) { - return baseGet(object, path); - }; - } - - /** - * The base implementation of `_.toString` which doesn't convert nullish - * values to empty strings. - * - * @private - * @param {*} value The value to process. - * @returns {string} Returns the string. - */ - function baseToString(value) { - // Exit early for strings to avoid a performance hit in some environments. - if (typeof value == 'string') { - return value; - } - if (isSymbol(value)) { - return symbolToString ? symbolToString.call(value) : ''; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } - - /** - * Casts `value` to a path array if it's not one. - * - * @private - * @param {*} value The value to inspect. - * @returns {Array} Returns the cast property path array. - */ - function castPath(value) { - return isArray(value) ? value : stringToPath(value); - } - - /** - * Creates a `baseEach` or `baseEachRight` function. - * - * @private - * @param {Function} eachFunc The function to iterate over a collection. - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ - function createBaseEach(eachFunc, fromRight) { - return function(collection, iteratee) { - if (collection == null) { - return collection; - } - if (!isArrayLike(collection)) { - return eachFunc(collection, iteratee); - } - var length = collection.length, - index = fromRight ? length : -1, - iterable = Object(collection); - - while ((fromRight ? index-- : ++index < length)) { - if (iteratee(iterable[index], index, iterable) === false) { - break; - } - } - return collection; - }; - } - - /** - * Creates a base function for methods like `_.forIn` and `_.forOwn`. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ - function createBaseFor(fromRight) { - return function(object, iteratee, keysFunc) { - var index = -1, - iterable = Object(object), - props = keysFunc(object), - length = props.length; - - while (length--) { - var key = props[fromRight ? length : ++index]; - if (iteratee(iterable[key], key, iterable) === false) { - break; - } - } - return object; - }; - } - - /** - * A specialized version of `baseIsEqualDeep` for arrays with support for - * partial deep comparisons. - * - * @private - * @param {Array} array The array to compare. - * @param {Array} other The other array to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `array` and `other` objects. - * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. - */ - function equalArrays(array, other, equalFunc, customizer, bitmask, stack) { - var isPartial = bitmask & PARTIAL_COMPARE_FLAG, - arrLength = array.length, - othLength = other.length; - - if (arrLength != othLength && !(isPartial && othLength > arrLength)) { - return false; - } - // Assume cyclic values are equal. - var stacked = stack.get(array); - if (stacked && stack.get(other)) { - return stacked == other; - } - var index = -1, - result = true, - seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined; - - stack.set(array, other); - stack.set(other, array); - - // Ignore non-index properties. - while (++index < arrLength) { - var arrValue = array[index], - othValue = other[index]; - - if (customizer) { - var compared = isPartial - ? customizer(othValue, arrValue, index, other, array, stack) - : customizer(arrValue, othValue, index, array, other, stack); - } - if (compared !== undefined) { - if (compared) { - continue; - } - result = false; - break; - } - // Recursively compare arrays (susceptible to call stack limits). - if (seen) { - if (!arraySome(other, function(othValue, othIndex) { - if (!seen.has(othIndex) && - (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) { - return seen.add(othIndex); - } - })) { - result = false; - break; - } - } else if (!( - arrValue === othValue || - equalFunc(arrValue, othValue, customizer, bitmask, stack) - )) { - result = false; - break; - } - } - stack['delete'](array); - stack['delete'](other); - return result; - } - - /** - * A specialized version of `baseIsEqualDeep` for comparing objects of - * the same `toStringTag`. - * - * **Note:** This function only supports comparing values with tags of - * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {string} tag The `toStringTag` of the objects to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) { - switch (tag) { - case dataViewTag: - if ((object.byteLength != other.byteLength) || - (object.byteOffset != other.byteOffset)) { - return false; - } - object = object.buffer; - other = other.buffer; - - case arrayBufferTag: - if ((object.byteLength != other.byteLength) || - !equalFunc(new Uint8Array(object), new Uint8Array(other))) { - return false; - } - return true; - - case boolTag: - case dateTag: - case numberTag: - // Coerce booleans to `1` or `0` and dates to milliseconds. - // Invalid dates are coerced to `NaN`. - return eq(+object, +other); - - case errorTag: - return object.name == other.name && object.message == other.message; - - case regexpTag: - case stringTag: - // Coerce regexes to strings and treat strings, primitives and objects, - // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring - // for more details. - return object == (other + ''); - - case mapTag: - var convert = mapToArray; - - case setTag: - var isPartial = bitmask & PARTIAL_COMPARE_FLAG; - convert || (convert = setToArray); - - if (object.size != other.size && !isPartial) { - return false; - } - // Assume cyclic values are equal. - var stacked = stack.get(object); - if (stacked) { - return stacked == other; - } - bitmask |= UNORDERED_COMPARE_FLAG; - - // Recursively compare objects (susceptible to call stack limits). - stack.set(object, other); - var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack); - stack['delete'](object); - return result; - - case symbolTag: - if (symbolValueOf) { - return symbolValueOf.call(object) == symbolValueOf.call(other); - } - } - return false; - } - - /** - * A specialized version of `baseIsEqualDeep` for objects with support for - * partial deep comparisons. - * - * @private - * @param {Object} object The object to compare. - * @param {Object} other The other object to compare. - * @param {Function} equalFunc The function to determine equivalents of values. - * @param {Function} customizer The function to customize comparisons. - * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual` - * for more details. - * @param {Object} stack Tracks traversed `object` and `other` objects. - * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. - */ - function equalObjects(object, other, equalFunc, customizer, bitmask, stack) { - var isPartial = bitmask & PARTIAL_COMPARE_FLAG, - objProps = keys(object), - objLength = objProps.length, - othProps = keys(other), - othLength = othProps.length; - - if (objLength != othLength && !isPartial) { - return false; - } - var index = objLength; - while (index--) { - var key = objProps[index]; - if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { - return false; - } - } - // Assume cyclic values are equal. - var stacked = stack.get(object); - if (stacked && stack.get(other)) { - return stacked == other; - } - var result = true; - stack.set(object, other); - stack.set(other, object); - - var skipCtor = isPartial; - while (++index < objLength) { - key = objProps[index]; - var objValue = object[key], - othValue = other[key]; - - if (customizer) { - var compared = isPartial - ? customizer(othValue, objValue, key, other, object, stack) - : customizer(objValue, othValue, key, object, other, stack); - } - // Recursively compare objects (susceptible to call stack limits). - if (!(compared === undefined - ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack)) - : compared - )) { - result = false; - break; - } - skipCtor || (skipCtor = key == 'constructor'); - } - if (result && !skipCtor) { - var objCtor = object.constructor, - othCtor = other.constructor; - - // Non `Object` object instances with different constructors are not equal. - if (objCtor != othCtor && - ('constructor' in object && 'constructor' in other) && - !(typeof objCtor == 'function' && objCtor instanceof objCtor && - typeof othCtor == 'function' && othCtor instanceof othCtor)) { - result = false; - } - } - stack['delete'](object); - stack['delete'](other); - return result; - } - - /** - * Gets the data for `map`. - * - * @private - * @param {Object} map The map to query. - * @param {string} key The reference key. - * @returns {*} Returns the map data. - */ - function getMapData(map, key) { - var data = map.__data__; - return isKeyable(key) - ? data[typeof key == 'string' ? 'string' : 'hash'] - : data.map; - } - - /** - * Gets the property names, values, and compare flags of `object`. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the match data of `object`. - */ - function getMatchData(object) { - var result = keys(object), - length = result.length; - - while (length--) { - var key = result[length], - value = object[key]; - - result[length] = [key, value, isStrictComparable(value)]; - } - return result; - } - - /** - * Gets the native function at `key` of `object`. - * - * @private - * @param {Object} object The object to query. - * @param {string} key The key of the method to get. - * @returns {*} Returns the function if it's native, else `undefined`. - */ - function getNative(object, key) { - var value = getValue(object, key); - return baseIsNative(value) ? value : undefined; - } - - /** - * Gets the `toStringTag` of `value`. - * - * @private - * @param {*} value The value to query. - * @returns {string} Returns the `toStringTag`. - */ - var getTag = baseGetTag; - - // Fallback for data views, maps, sets, and weak maps in IE 11, - // for data views in Edge < 14, and promises in Node.js. - if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || - (Map && getTag(new Map) != mapTag) || - (Promise && getTag(Promise.resolve()) != promiseTag) || - (Set && getTag(new Set) != setTag) || - (WeakMap && getTag(new WeakMap) != weakMapTag)) { - getTag = function(value) { - var result = objectToString.call(value), - Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : undefined; - - if (ctorString) { - switch (ctorString) { - case dataViewCtorString: return dataViewTag; - case mapCtorString: return mapTag; - case promiseCtorString: return promiseTag; - case setCtorString: return setTag; - case weakMapCtorString: return weakMapTag; - } - } - return result; - }; - } - - /** - * Checks if `path` exists on `object`. - * - * @private - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @param {Function} hasFunc The function to check properties. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - */ - function hasPath(object, path, hasFunc) { - path = isKey(path, object) ? [path] : castPath(path); - - var result, - index = -1, - length = path.length; - - while (++index < length) { - var key = toKey(path[index]); - if (!(result = object != null && hasFunc(object, key))) { - break; - } - object = object[key]; - } - if (result) { - return result; - } - var length = object ? object.length : 0; - return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isArguments(object)); - } - - /** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ - function isIndex(value, length) { - length = length == null ? MAX_SAFE_INTEGER : length; - return !!length && - (typeof value == 'number' || reIsUint.test(value)) && - (value > -1 && value % 1 == 0 && value < length); - } - - /** - * Checks if `value` is a property name and not a property path. - * - * @private - * @param {*} value The value to check. - * @param {Object} [object] The object to query keys on. - * @returns {boolean} Returns `true` if `value` is a property name, else `false`. - */ - function isKey(value, object) { - if (isArray(value)) { - return false; - } - var type = typeof value; - if (type == 'number' || type == 'symbol' || type == 'boolean' || - value == null || isSymbol(value)) { - return true; - } - return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || - (object != null && value in Object(object)); - } - - /** - * Checks if `value` is suitable for use as unique object key. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is suitable, else `false`. - */ - function isKeyable(value) { - var type = typeof value; - return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') - ? (value !== '__proto__') - : (value === null); - } - - /** - * Checks if `func` has its source masked. - * - * @private - * @param {Function} func The function to check. - * @returns {boolean} Returns `true` if `func` is masked, else `false`. - */ - function isMasked(func) { - return !!maskSrcKey && (maskSrcKey in func); - } - - /** - * Checks if `value` is likely a prototype object. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. - */ - function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; - - return value === proto; - } - - /** - * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` if suitable for strict - * equality comparisons, else `false`. - */ - function isStrictComparable(value) { - return value === value && !isObject(value); - } - - /** - * A specialized version of `matchesProperty` for source values suitable - * for strict equality comparisons, i.e. `===`. - * - * @private - * @param {string} key The key of the property to get. - * @param {*} srcValue The value to match. - * @returns {Function} Returns the new spec function. - */ - function matchesStrictComparable(key, srcValue) { - return function(object) { - if (object == null) { - return false; - } - return object[key] === srcValue && - (srcValue !== undefined || (key in Object(object))); - }; - } - - /** - * Converts `string` to a property path array. - * - * @private - * @param {string} string The string to convert. - * @returns {Array} Returns the property path array. - */ - var stringToPath = memoize(function(string) { - string = toString(string); - - var result = []; - if (reLeadingDot.test(string)) { - result.push(''); - } - string.replace(rePropName, function(match, number, quote, string) { - result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); - }); - return result; - }); - - /** - * Converts `value` to a string key if it's not a string or symbol. - * - * @private - * @param {*} value The value to inspect. - * @returns {string|symbol} Returns the key. - */ - function toKey(value) { - if (typeof value == 'string' || isSymbol(value)) { - return value; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; - } - - /** - * Converts `func` to its source code. - * - * @private - * @param {Function} func The function to process. - * @returns {string} Returns the source code. - */ - function toSource(func) { - if (func != null) { - try { - return funcToString.call(func); - } catch (e) {} - try { - return (func + ''); - } catch (e) {} - } - return ''; - } - - /** - * Iterates over elements of `collection`, returning an array of all elements - * `predicate` returns truthy for. The predicate is invoked with three - * arguments: (value, index|key, collection). - * - * **Note:** Unlike `_.remove`, this method returns a new array. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Collection - * @param {Array|Object} collection The collection to iterate over. - * @param {Function} [predicate=_.identity] - * The function invoked per iteration. - * @returns {Array} Returns the new filtered array. - * @see _.reject - * @example - * - * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false } - * ]; - * - * _.filter(users, function(o) { return !o.active; }); - * // => objects for ['fred'] - * - * // The `_.matches` iteratee shorthand. - * _.filter(users, { 'age': 36, 'active': true }); - * // => objects for ['barney'] - * - * // The `_.matchesProperty` iteratee shorthand. - * _.filter(users, ['active', false]); - * // => objects for ['fred'] - * - * // The `_.property` iteratee shorthand. - * _.filter(users, 'active'); - * // => objects for ['barney'] - */ - function filter(collection, predicate) { - var func = isArray(collection) ? arrayFilter : baseFilter; - return func(collection, baseIteratee(predicate)); - } - - /** - * Creates a function that memoizes the result of `func`. If `resolver` is - * provided, it determines the cache key for storing the result based on the - * arguments provided to the memoized function. By default, the first argument - * provided to the memoized function is used as the map cache key. The `func` - * is invoked with the `this` binding of the memoized function. - * - * **Note:** The cache is exposed as the `cache` property on the memoized - * function. Its creation may be customized by replacing the `_.memoize.Cache` - * constructor with one whose instances implement the - * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) - * method interface of `delete`, `get`, `has`, and `set`. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Function - * @param {Function} func The function to have its output memoized. - * @param {Function} [resolver] The function to resolve the cache key. - * @returns {Function} Returns the new memoized function. - * @example - * - * var object = { 'a': 1, 'b': 2 }; - * var other = { 'c': 3, 'd': 4 }; - * - * var values = _.memoize(_.values); - * values(object); - * // => [1, 2] - * - * values(other); - * // => [3, 4] - * - * object.a = 2; - * values(object); - * // => [1, 2] - * - * // Modify the result cache. - * values.cache.set(object, ['a', 'b']); - * values(object); - * // => ['a', 'b'] - * - * // Replace `_.memoize.Cache`. - * _.memoize.Cache = WeakMap; - */ - function memoize(func, resolver) { - if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { - throw new TypeError(FUNC_ERROR_TEXT); - } - var memoized = function() { - var args = arguments, - key = resolver ? resolver.apply(this, args) : args[0], - cache = memoized.cache; - - if (cache.has(key)) { - return cache.get(key); - } - var result = func.apply(this, args); - memoized.cache = cache.set(key, result); - return result; - }; - memoized.cache = new (memoize.Cache || MapCache); - return memoized; - } - - // Assign cache to `_.memoize`. - memoize.Cache = MapCache; - - /** - * Performs a - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * comparison between two values to determine if they are equivalent. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.eq(object, object); - * // => true - * - * _.eq(object, other); - * // => false - * - * _.eq('a', 'a'); - * // => true - * - * _.eq('a', Object('a')); - * // => false - * - * _.eq(NaN, NaN); - * // => true - */ - function eq(value, other) { - return value === other || (value !== value && other !== other); - } - - /** - * Checks if `value` is likely an `arguments` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. - * @example - * - * _.isArguments(function() { return arguments; }()); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ - function isArguments(value) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && - (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); - } - - /** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ - var isArray = Array.isArray; - - /** - * Checks if `value` is array-like. A value is considered array-like if it's - * not a function and has a `value.length` that's an integer greater than or - * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. - * @example - * - * _.isArrayLike([1, 2, 3]); - * // => true - * - * _.isArrayLike(document.body.children); - * // => true - * - * _.isArrayLike('abc'); - * // => true - * - * _.isArrayLike(_.noop); - * // => false - */ - function isArrayLike(value) { - return value != null && isLength(value.length) && !isFunction(value); - } - - /** - * This method is like `_.isArrayLike` except that it also checks if `value` - * is an object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, - * else `false`. - * @example - * - * _.isArrayLikeObject([1, 2, 3]); - * // => true - * - * _.isArrayLikeObject(document.body.children); - * // => true - * - * _.isArrayLikeObject('abc'); - * // => false - * - * _.isArrayLikeObject(_.noop); - * // => false - */ - function isArrayLikeObject(value) { - return isObjectLike(value) && isArrayLike(value); - } - - /** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a function, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ - function isFunction(value) { - // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8-9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag; - } - - /** - * Checks if `value` is a valid array-like length. - * - * **Note:** This method is loosely based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. - * @example - * - * _.isLength(3); - * // => true - * - * _.isLength(Number.MIN_VALUE); - * // => false - * - * _.isLength(Infinity); - * // => false - * - * _.isLength('3'); - * // => false - */ - function isLength(value) { - return typeof value == 'number' && - value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; - } - - /** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ - function isObject(value) { - var type = typeof value; - return !!value && (type == 'object' || type == 'function'); - } - - /** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ - function isObjectLike(value) { - return !!value && typeof value == 'object'; - } - - /** - * Checks if `value` is classified as a `Symbol` primitive or object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. - * @example - * - * _.isSymbol(Symbol.iterator); - * // => true - * - * _.isSymbol('abc'); - * // => false - */ - function isSymbol(value) { - return typeof value == 'symbol' || - (isObjectLike(value) && objectToString.call(value) == symbolTag); - } - - /** - * Checks if `value` is classified as a typed array. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. - * @example - * - * _.isTypedArray(new Uint8Array); - * // => true - * - * _.isTypedArray([]); - * // => false - */ - var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; - - /** - * Converts `value` to a string. An empty string is returned for `null` - * and `undefined` values. The sign of `-0` is preserved. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to process. - * @returns {string} Returns the string. - * @example - * - * _.toString(null); - * // => '' - * - * _.toString(-0); - * // => '-0' - * - * _.toString([1, 2, 3]); - * // => '1,2,3' - */ - function toString(value) { - return value == null ? '' : baseToString(value); - } - - /** - * Gets the value at `path` of `object`. If the resolved value is - * `undefined`, the `defaultValue` is returned in its place. - * - * @static - * @memberOf _ - * @since 3.7.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path of the property to get. - * @param {*} [defaultValue] The value returned for `undefined` resolved values. - * @returns {*} Returns the resolved value. - * @example - * - * var object = { 'a': [{ 'b': { 'c': 3 } }] }; - * - * _.get(object, 'a[0].b.c'); - * // => 3 - * - * _.get(object, ['a', '0', 'b', 'c']); - * // => 3 - * - * _.get(object, 'a.b.c', 'default'); - * // => 'default' - */ - function get(object, path, defaultValue) { - var result = object == null ? undefined : baseGet(object, path); - return result === undefined ? defaultValue : result; - } - - /** - * Checks if `path` is a direct or inherited property of `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Object - * @param {Object} object The object to query. - * @param {Array|string} path The path to check. - * @returns {boolean} Returns `true` if `path` exists, else `false`. - * @example - * - * var object = _.create({ 'a': _.create({ 'b': 2 }) }); - * - * _.hasIn(object, 'a'); - * // => true - * - * _.hasIn(object, 'a.b'); - * // => true - * - * _.hasIn(object, ['a', 'b']); - * // => true - * - * _.hasIn(object, 'b'); - * // => false - */ - function hasIn(object, path) { - return object != null && hasPath(object, path, baseHasIn); - } - - /** - * Creates an array of the own enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. See the - * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * for more details. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keys(new Foo); - * // => ['a', 'b'] (iteration order is not guaranteed) - * - * _.keys('hi'); - * // => ['0', '1'] - */ - function keys(object) { - return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); - } - - /** - * This method returns the first argument it receives. - * - * @static - * @since 0.1.0 - * @memberOf _ - * @category Util - * @param {*} value Any value. - * @returns {*} Returns `value`. - * @example - * - * var object = { 'a': 1 }; - * - * console.log(_.identity(object) === object); - * // => true - */ - function identity(value) { - return value; - } - - /** - * Creates a function that returns the value at `path` of a given object. - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Util - * @param {Array|string} path The path of the property to get. - * @returns {Function} Returns the new accessor function. - * @example - * - * var objects = [ - * { 'a': { 'b': 2 } }, - * { 'a': { 'b': 1 } } - * ]; - * - * _.map(objects, _.property('a.b')); - * // => [2, 1] - * - * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b'); - * // => [1, 2] - */ - function property(path) { - return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path); - } - - module.exports = filter; - }); - - /** - * Tus based client uploader. - * - * It gives you the ability to upload a file to the reference tus server - */ - - // Global axios - - - - - - var _ = { - assignIn: lodash_assignin, - remove: lodash_remove, - filter: lodash_filter - }; - - /** - * Creates a new Tus based file Uploader - * - * @param {object} config - */ - var tusuploader = function (config) { - - var UploadStatus = { - /** - * Upload has been queued and waiting to be processed - */ - QUEUED: 1, - /** - * Upload has started, upload of the first chunk should begin shortly - */ - STARTED: 2, - /** - * Upload is in progress - */ - UPLOADING: 3, - /** - * Upload is completed - */ - COMPLETED: 4, - /** - * Upload has been cancelled - */ - CANCELLED: 5, - /** - * File upload failed - */ - FAILED: 6 - }; - - var defaultOptions = { - /** - * The endpoint that will authorize the upload request - * @var {string} - * @default /uploadjobs/ - */ - endpoint: "/uploadjobs/", - /** - * Retry delays in case of upload error - * @var {array} - * @default [0,1000,3000,5000] - */ - retryDelays: [0, 1000, 3000, 5000], - /** - * Automatically starts the upload after has been added to the queue - * - * @default false - * @var {boolean} - */ - autoUpload: false, - /** - * The number of bytes for each file chunk sent - * - * @default 5000 - * @var {integer} - */ - chunkSize: 5000 - }; - - var ee = mitt(); - - var uploadsQueue = []; - - var options = _.assignIn(defaultOptions, config || {}); - - if (typeof document.querySelector === undefined) { - throw new Error("TusUpload: Browser not supported."); - } - - if (!options.endpoint) { - throw new Error("TusUpload: Url not specified."); - } - - if (!tus.isSupported) { - throw new Error("TusUpload: Tus upload protocol not supported."); - } - - - - /** - * Handle the tus-client error event - */ - function handleUploadError(error) { - - this.status = UploadStatus.FAILED; - - ee.emit('upload.failed', { upload: this, type: 'upload.failed', error: error }); - } - - /** - * Handle the tus-client onChunkComplete event - */ - function handleUploadProgress(chunkSize, bytesUploaded, bytesTotal) { - var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); - - this.status = UploadStatus.UPLOADING; - this.uploadPercentage = percentage; - this.uploadTransferredSize = bytesUploaded; - - ee.emit('upload.progress', { upload: this, type: 'upload.progress', percentage: percentage, total: bytesTotal, transferred: bytesUploaded }); - } - - /** - * Handle the tus-client success event - */ - function handleUploadSuccess() { - this.status = UploadStatus.COMPLETED; - - ee.emit('upload.completed', { upload: this, type: 'upload.completed' }); - } - - - - /** - * Creates a new upload - * - * @param {File} file the file to upload - * @param {Object} metadata additional metadata to sent to the server - * @return {Upload} - */ - function Upload(file, metadata) { - - this.id = cuid_1(); - - this.metadata = _.assignIn({ - filename: file.name, - upload_request_id: this.id - }, metadata || {}); - - // Create a new tus upload - this.transport = new tus.Upload(file, { - endpoint: options.tus_endpoint, - retryDelays: options.retryDelays, - chunkSize: options.chunkSize, - metadata: this.metadata, - onError: handleUploadError.bind(this), - onChunkComplete: handleUploadProgress.bind(this), - onSuccess: handleUploadSuccess.bind(this) - }); - - this.status = UploadStatus.QUEUED; - this.uploadToken = null; - this.uploadPercentage = 0; - this.uploadSize = file.size; - this.uploadTransferredSize = 0; - this.uploadRemainingTime = null; - - this.file = file; - - return this; - } - - - /** - * Stop the upload - * - * @return {Upload} - */ - Upload.prototype.stop = function () { - this.transport.abort(); - this.status = UploadStatus.CANCELLED; - - window.axios.delete(options.endpoint + '' + this.id).then(function (/* response */) { - ee.emit('upload.cancelled', { upload: this, type: 'upload.cancelled' }); - // console.log('Upload cancelled', response) - }.bind(this)). - catch(function (/* error */) { - // console.error('upload cancel error', error); - }); - - return this; - }; - - /** - * Starts the upload - * - * @return {Upload} - */ - Upload.prototype.start = function () { - - this.status = UploadStatus.STARTED; - ee.emit('upload.started', { upload: this, type: 'upload.started' }); - - window.axios.post(options.endpoint, lodash_assignin({ - id: this.id, - filename: this.metadata.filename, - filesize: this.file.size || '', - filetype: this.file.type || '', - }, this.metadata)).then(function (response) { - - this.uploadToken = response.data.upload_token; - this.transport.options.metadata.token = this.uploadToken; - this.transport.options.endpoint = response.data.location; - - // set the upload token in the metadata of the transport - this.status = UploadStatus.UPLOADING; - this.transport.start(); - - }.bind(this)). - catch(function (error) { - handleUploadError(error); - }); - - - return this; - }; - - var TusUploadInner = {}; - - /** - * Add a file to the upload queue - * - * @param {File} file https://developer.mozilla.org/en-US/docs/Web/API/File - * @param {Object} metadata Application level metatada about the file that should be sent to the server - * @return {Upload} the upload entry added to the queue - */ - TusUploadInner.upload = function (file, metadata) { - - // Create a new upload - var upload = new Upload(file, metadata || {}); - - // add it to the queue - uploadsQueue.push(upload); - - ee.emit('upload.queued', { upload: upload, type: 'upload.queued' }); - - if (options.autoUpload) { - // Immediately start the upload - upload.start(); - } - - return upload; - }; - - TusUploadInner.add = TusUploadInner.upload; - - /** - * Remove the upload, identified by its id, from the queue. - * If the upload is already started, it will be cancelled. - * - * @emits upload.removed - * @emits upload.cancelled if the upload was already in progress before the removal - * @return {Array|null} the removed elements or null, if nothing has been removed - */ - TusUploadInner.remove = function(id){ - - var removed = _.remove(uploadsQueue, function(n){ - return n.id === id; - }); - - if(removed && removed.length >= 1){ - - removed.forEach(function(element) { - if(element.status === UploadStatus.UPLOADING){ - element.stop(); - } - }, this); - - ee.emit('upload.removed', { upload: removed, type: 'upload.removed' }); - - return removed; - } - - return null; - }; - - /** - * Cancel the upload, identified by its id, from the queue. - * - * @emits upload.cancelled when the upload is cancelled - * @return {Array|null} the cancelled uploads or null, if nothing has been cancelled - */ - TusUploadInner.cancel = function(id){ - - var cancelled = _.remove(uploadsQueue, function(n){ - return n.id === id; - }); - - if(cancelled && cancelled.length >= 1){ - - cancelled.forEach(function(element) { - if(element.status === UploadStatus.UPLOADING){ - element.stop(); - } - }, this); - - return cancelled.length == 1 ? cancelled[0] : cancelled; - } - - return null; - }; - - /** - * Access the upload queue - * - * @param {Function} [filter=_.identity] The filtering function, if specified allows to filter the upload queue - * @example - * TusUploads.uploads({ 'status': TusUploads.UploadStatus.COMPLETED }); - */ - TusUploadInner.uploads = function(filter){ - return _.filter(uploadsQueue, filter); - }; - - /** - * Add an event listener - * - * @param {string} event the event name to listen for - * @param {function} callback the callback invoked when the event is emitted. It will receive the event object as first parameter - * @return {TusUploader} - */ - TusUploadInner.on = function (event, callback) { - - ee.on(event, callback); - - return TusUploadInner; - }; - - /** - * Remove an event listener - * - * @param {string} event the event to unregister - * @param {function} callback the callback used during event registration - * @return {TusUploader} - */ - TusUploadInner.off = function (event, callback) { - - ee.removeListener(event, callback); - - return TusUploadInner; - }; - - TusUploadInner.Status = UploadStatus; - TusUploadInner.Upload = Upload; - - return TusUploadInner; - }; - - return tusuploader; - -}()); +var TusUploader=function(){"use strict";var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function unwrapExports(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function createCommonjsModule(e,t){return e(t={exports:{}},t.exports),t.exports}var tus=createCommonjsModule((function(module,exports){var f;f=function(){return function e(t,r,n){function o(a,u){if(!r[a]){if(!t[a]){var s="function"==typeof commonjsRequire&&commonjsRequire;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[a]={exports:{}};t[a][0].call(f.exports,(function(e){var r=t[a][1][e];return o(r||e)}),f,f.exports,e,t,r,n)}return r[a].exports}for(var i="function"==typeof commonjsRequire&&commonjsRequire,a=0;athis._bufferOffset&&(this._buffer=this._buffer.slice(e-this._bufferOffset),this._bufferOffset=e);var r=0===p(this._buffer);return this._done&&r?null:this._buffer.slice(0,t-e)}},{key:"close",value:function(){this._reader.cancel&&this._reader.cancel()}}]),e}();function p(e){return void 0===e?0:void 0!==e.size?e.size:e.length}},{"./isCordova":2,"./isReactNative":3,"./readAsByteArray":4,"./uriToBlob":8}],7:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;n(this,t);var a=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e.message));a.originalRequest=i,a.causingError=r;var u=e.message;return null!=r&&(u+=", caused by "+r.toString()),null!=i&&(u+=", originated from request (response code: "+i.status+", response text: "+i.responseText+")"),a.message=u,a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,Error),t}();r.default=i},{}],10:[function(e,t,r){var n,o=e("./upload"),i=(n=o)&&n.__esModule?n:{default:n},a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(e("./node/storage")),u=i.default.defaultOptions,s={Upload:i.default,canStoreURLs:a.canStoreURLs,defaultOptions:u};if("undefined"!=typeof window){var c=window,f=c.XMLHttpRequest,l=c.Blob;s.isSupported=f&&l&&"function"==typeof l.prototype.slice}else s.isSupported=!0,s.FileStorage=a.FileStorage;t.exports=s},{"./node/storage":7,"./upload":11}],11:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;rt._offsetBeforeRetry&&(t._retryAttempt=0);var r=!0;"undefined"!=typeof window&&"navigator"in window&&!1===window.navigator.onLine&&(r=!1);var i=e.originalRequest?e.originalRequest.status:0,a=!d(i,400)||409===i||423===i;if(t._retryAttemptthis._size)&&!this.options.uploadLengthDeferred&&(n=this._size),this._source.slice(r,n,(function(r,n,o){r?t._emitError(r):(t.options.uploadLengthDeferred&&o&&(t._size=t._offset+(n&&n.size?n.size:0),e.setRequestHeader("Upload-Length",t._size)),null===n?e.send():(e.send(n),t._emitProgress(t._offset,t._size)))}))}},{key:"_handleUploadResponse",value:function(e){var t=this,r=parseInt(e.getResponseHeader("Upload-Offset"),10);if(isNaN(r))this._emitXhrError(e,new Error("tus: invalid or missing offset value"));else{if(this._emitProgress(r,this._size),this._emitChunkComplete(r-this._offset,r,this._size),this._offset=r,r==this._size)return this.options.removeFingerprintOnSuccess&&this.options.resume&&this._storage.removeItem(this._fingerprint,(function(e){e&&t._emitError(e)})),this._emitSuccess(),void this._source.close();this._startUpload()}}}],[{key:"terminate",value:function(e,t,r){if("function"!=typeof t&&"function"!=typeof r)throw new Error("tus: a callback function must be specified");"function"==typeof t&&(r=t,t={});var n=(0,u.newRequest)();n.open("DELETE",e,!0),n.onload=function(){204===n.status?r():r(new o.default(new Error("tus: unexpected response while terminating upload"),null,n))},n.onerror=function(e){r(new o.default(e,new Error("tus: failed to terminate upload"),n))},h(n,t),n.send(null)}}]),e}();function d(e,t){return e>=t&&e>>6)+fromCharCode(128|63&t):fromCharCode(224|t>>>12&15)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t);var t=65536+1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320);return fromCharCode(240|t>>>18&7)+fromCharCode(128|t>>>12&63)+fromCharCode(128|t>>>6&63)+fromCharCode(128|63&t)},re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,utob=function(e){return e.replace(re_utob,cb_utob)},cb_encode=function(e){var t=[0,2,1][e.length%3],r=e.charCodeAt(0)<<16|(e.length>1?e.charCodeAt(1):0)<<8|(e.length>2?e.charCodeAt(2):0);return[b64chars.charAt(r>>>18),b64chars.charAt(r>>>12&63),t>=2?"=":b64chars.charAt(r>>>6&63),t>=1?"=":b64chars.charAt(63&r)].join("")},btoa=global.btoa?function(e){return global.btoa(e)}:function(e){return e.replace(/[\s\S]{1,3}/g,cb_encode)},_encode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(e){return(e.constructor===buffer.constructor?e:buffer.from(e)).toString("base64")}:function(e){return(e.constructor===buffer.constructor?e:new buffer(e)).toString("base64")}:function(e){return btoa(utob(e))},encode=function(e,t){return t?_encode(String(e)).replace(/[+\/]/g,(function(e){return"+"==e?"-":"_"})).replace(/=/g,""):_encode(String(e))},encodeURI=function(e){return encode(e,!0)},re_btou=new RegExp(["[À-ß][€-¿]","[à-ï][€-¿]{2}","[ð-÷][€-¿]{3}"].join("|"),"g"),cb_btou=function(e){switch(e.length){case 4:var t=((7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3))-65536;return fromCharCode(55296+(t>>>10))+fromCharCode(56320+(1023&t));case 3:return fromCharCode((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return fromCharCode((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}},btou=function(e){return e.replace(re_btou,cb_btou)},cb_decode=function(e){var t=e.length,r=t%4,n=(t>0?b64tab[e.charAt(0)]<<18:0)|(t>1?b64tab[e.charAt(1)]<<12:0)|(t>2?b64tab[e.charAt(2)]<<6:0)|(t>3?b64tab[e.charAt(3)]:0),o=[fromCharCode(n>>>16),fromCharCode(n>>>8&255),fromCharCode(255&n)];return o.length-=[0,0,2,1][r],o.join("")},atob=global.atob?function(e){return global.atob(e)}:function(e){return e.replace(/[\s\S]{1,4}/g,cb_decode)},_decode=buffer?buffer.from&&Uint8Array&&buffer.from!==Uint8Array.from?function(e){return(e.constructor===buffer.constructor?e:buffer.from(e,"base64")).toString()}:function(e){return(e.constructor===buffer.constructor?e:new buffer(e,"base64")).toString()}:function(e){return btou(atob(e))},decode=function(e){return _decode(String(e).replace(/[-_]/g,(function(e){return"-"==e?"+":"/"})).replace(/[^A-Za-z0-9\+\/]/g,""))},noConflict=function(){var e=global.Base64;return global.Base64=_Base64,e};if(global.Base64={VERSION:version,atob:atob,btoa:btoa,fromBase64:decode,toBase64:encode,utob:utob,encode:encode,encodeURI:encodeURI,btou:btou,decode:decode,noConflict:noConflict,__buffer__:buffer},"function"==typeof Object.defineProperty){var noEnum=function(e){return{value:e,enumerable:!1,writable:!0,configurable:!0}};global.Base64.extendString=function(){Object.defineProperty(String.prototype,"fromBase64",noEnum((function(){return decode(this)}))),Object.defineProperty(String.prototype,"toBase64",noEnum((function(e){return encode(this,e)}))),Object.defineProperty(String.prototype,"toBase64URI",noEnum((function(){return encode(this,!0)})))}}return global.Meteor&&(Base64=global.Base64),void 0!==module&&module.exports&&(module.exports.Base64=global.Base64),{Base64:global.Base64}}))}).call(this,void 0!==commonjsGlobal?commonjsGlobal:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(e,t,r){var n=Object.prototype.hasOwnProperty;function o(e){return decodeURIComponent(e.replace(/\+/g," "))}r.stringify=function(e,t){t=t||"";var r=[];for(var o in"string"!=typeof t&&(t="?"),e)n.call(e,o)&&r.push(encodeURIComponent(o)+"="+encodeURIComponent(e[o]));return r.length?t+r.join("&"):""},r.parse=function(e){for(var t,r=/([^=?&]+)=?([^&]*)/g,n={};t=r.exec(e);){var i=o(t[1]),a=o(t[2]);i in n||(n[i]=a)}return n}},{}],15:[function(e,t,r){t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}],16:[function(e,t,r){(function(r){var n=e("requires-port"),o=e("querystringify"),i=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,a=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,u=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],s={hash:1,query:1};function c(e){var t,n=r&&r.location||{},o={},i=typeof(e=e||n);if("blob:"===e.protocol)o=new l(unescape(e.pathname),{});else if("string"===i)for(t in o=new l(e,{}),s)delete o[t];else if("object"===i){for(t in e)t in s||(o[t]=e[t]);void 0===o.slashes&&(o.slashes=a.test(e.href))}return o}function f(e){var t=i.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function l(e,t,r){if(!(this instanceof l))return new l(e,t,r);var i,a,s,p,d,h,_=u.slice(),v=typeof t,b=this,y=0;for("object"!==v&&"string"!==v&&(r=t,t=null),r&&"function"!=typeof r&&(r=o.parse),t=c(t),i=!(a=f(e||"")).protocol&&!a.slashes,b.slashes=a.slashes||i&&t.slashes,b.protocol=a.protocol||t.protocol||"",e=a.rest,a.slashes||(_[3]=[/(.*)/,"pathname"]);y<_.length;y++)"function"!=typeof(p=_[y])?(s=p[0],h=p[1],s!=s?b[h]=e:"string"==typeof s?~(d=e.indexOf(s))&&("number"==typeof p[2]?(b[h]=e.slice(0,d),e=e.slice(d+p[2])):(b[h]=e.slice(d),e=e.slice(0,d))):(d=s.exec(e))&&(b[h]=d[1],e=e.slice(0,d.index)),b[h]=b[h]||i&&p[3]&&t[h]||"",p[4]&&(b[h]=b[h].toLowerCase())):e=p(e);r&&(b.query=r(b.query)),i&&t.slashes&&"/"!==b.pathname.charAt(0)&&(""!==b.pathname||""!==t.pathname)&&(b.pathname=function(e,t){for(var r=(t||"/").split("/").slice(0,-1).concat(e.split("/")),n=r.length,o=r[n-1],i=!1,a=0;n--;)"."===r[n]?r.splice(n,1):".."===r[n]?(r.splice(n,1),a++):a&&(0===n&&(i=!0),r.splice(n,1),a--);return i&&r.unshift(""),"."!==o&&".."!==o||r.push(""),r.join("/")}(b.pathname,t.pathname)),n(b.port,b.protocol)||(b.host=b.hostname,b.port=""),b.username=b.password="",b.auth&&(p=b.auth.split(":"),b.username=p[0]||"",b.password=p[1]||""),b.origin=b.protocol&&b.host&&"file:"!==b.protocol?b.protocol+"//"+b.host:"null",b.href=b.toString()}l.prototype={set:function(e,t,r){var i=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(r||o.parse)(t)),i[e]=t;break;case"port":i[e]=t,n(t,i.protocol)?t&&(i.host=i.hostname+":"+t):(i.host=i.hostname,i[e]="");break;case"hostname":i[e]=t,i.port&&(t+=":"+i.port),i.host=t;break;case"host":i[e]=t,/:\d+$/.test(t)?(t=t.split(":"),i.port=t.pop(),i.hostname=t.join(":")):(i.hostname=t,i.port="");break;case"protocol":i.protocol=t.toLowerCase(),i.slashes=!r;break;case"pathname":case"hash":if(t){var a="pathname"===e?"/":"#";i[e]=t.charAt(0)!==a?a+t:t}else i[e]=t;break;default:i[e]=t}for(var s=0;s>>0,1)},emit:function(t,r){(e[t]||[]).slice().map((function(e){e(r)})),(e["*"]||[]).slice().map((function(e){e(t,r)}))}}}unwrapExports(tus);var pad=function(e,t){var r="000000000"+e;return r.substr(r.length-t)},env="object"==typeof window?window:self,globalCount=Object.keys(env).length,mimeTypesLength=navigator.mimeTypes?navigator.mimeTypes.length:0,clientId=pad((mimeTypesLength+navigator.userAgent.length).toString(36)+globalCount.toString(36),4),fingerprint_browser=function(){return clientId},getRandomValue,crypto="undefined"!=typeof window&&(window.crypto||window.msCrypto)||"undefined"!=typeof self&&self.crypto;if(crypto){var lim=Math.pow(2,32)-1;getRandomValue=function(){return Math.abs(crypto.getRandomValues(new Uint32Array(1))[0]/lim)}}else getRandomValue=Math.random;var getRandomValue_browser=getRandomValue,c=0,blockSize=4,base=36,discreteValues=Math.pow(base,blockSize);function randomBlock(){return pad((getRandomValue_browser()*discreteValues<<0).toString(base),blockSize)}function safeCounter(){return c=c=7&&t<=10},cuid.fingerprint=fingerprint_browser;var cuid_1=cuid,MAX_SAFE_INTEGER=9007199254740991,argsTag="[object Arguments]",funcTag="[object Function]",genTag="[object GeneratorFunction]",reIsUint=/^(?:0|[1-9]\d*)$/;function apply(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}function baseTimes(e,t){for(var r=-1,n=Array(e);++r1?r[o-1]:void 0,a=o>2?r[2]:void 0;for(i=e.length>3&&"function"==typeof i?(o--,i):void 0,a&&isIterateeCall(r[0],r[1],a)&&(i=o<3?void 0:i,o=1),t=Object(t);++n-1&&e%1==0&&e-1&&e%1==0&&e<=MAX_SAFE_INTEGER}function isObject(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function isObjectLike(e){return!!e&&"object"==typeof e}var assignIn=createAssigner((function(e,t){copyObject(t,keysIn(t),e)}));function keysIn(e){return isArrayLike(e)?arrayLikeKeys(e,!0):baseKeysIn(e)}var lodash_assignin=assignIn,lodash_remove=createCommonjsModule((function(e,t){var r="[object Arguments]",n="[object Map]",o="[object Object]",i="[object Set]",a=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,u=/^\w*$/,s=/^\./,c=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,f=/\\(\\)?/g,l=/^\[object .+?Constructor\]$/,p=/^(?:0|[1-9]\d*)$/,d={};d["[object Float32Array]"]=d["[object Float64Array]"]=d["[object Int8Array]"]=d["[object Int16Array]"]=d["[object Int32Array]"]=d["[object Uint8Array]"]=d["[object Uint8ClampedArray]"]=d["[object Uint16Array]"]=d["[object Uint32Array]"]=!0,d[r]=d["[object Array]"]=d["[object ArrayBuffer]"]=d["[object Boolean]"]=d["[object DataView]"]=d["[object Date]"]=d["[object Error]"]=d["[object Function]"]=d[n]=d["[object Number]"]=d[o]=d["[object RegExp]"]=d[i]=d["[object String]"]=d["[object WeakMap]"]=!1;var h="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_="object"==typeof self&&self&&self.Object===Object&&self,v=h||_||Function("return this")(),b=t&&!t.nodeType&&t,y=b&&e&&!e.nodeType&&e,g=y&&y.exports===b&&h.process,m=function(){try{return g&&g.binding("util")}catch(e){}}(),w=m&&m.isTypedArray;function j(e,t){for(var r=-1,n=e?e.length:0;++ru))return!1;var c=i.get(e);if(c&&i.get(t))return c==t;var f=-1,l=!0,p=1&o?new ae:void 0;for(i.set(e,t),i.set(t,e);++f-1},oe.prototype.set=function(e,t){var r=this.__data__,n=ce(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},ie.prototype.clear=function(){this.__data__={hash:new ne,map:new(G||oe),string:new ne}},ie.prototype.delete=function(e){return ye(this,e).delete(e)},ie.prototype.get=function(e){return ye(this,e).get(e)},ie.prototype.has=function(e){return ye(this,e).has(e)},ie.prototype.set=function(e,t){return ye(this,e).set(e,t),this},ae.prototype.add=ae.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},ae.prototype.has=function(e){return this.__data__.has(e)},ue.prototype.clear=function(){this.__data__=new oe},ue.prototype.delete=function(e){return this.__data__.delete(e)},ue.prototype.get=function(e){return this.__data__.get(e)},ue.prototype.has=function(e){return this.__data__.has(e)},ue.prototype.set=function(e,t){var r=this.__data__;if(r instanceof oe){var n=r.__data__;if(!G||n.length<199)return n.push([e,t]),this;r=this.__data__=new ie(n)}return r.set(e,t),this};var me=function(e){return z.call(e)};function we(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||p.test(e))&&e>-1&&e%1==0&&eo?0:o+t),(r=r>o?o:r)<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n-1&&e%1==0&&e<=9007199254740991}function Le(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function qe(e){return!!e&&"object"==typeof e}function Me(e){return"symbol"==typeof e||qe(e)&&"[object Symbol]"==z.call(e)}var Be=w?function(e){return function(t){return e(t)}}(w):function(e){return qe(e)&&ze(e.length)&&!!d[z.call(e)]};function Fe(e){return De(e)?se(e):_e(e)}function Ne(e){return e}e.exports=function(e,t){var r=[];if(!e||!e.length)return r;var n=-1,o=[],i=e.length;for(t=he(t);++n-1},ie.prototype.set=function(e,t){var r=this.__data__,n=fe(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},ae.prototype.clear=function(){this.__data__={hash:new oe,map:new(H||ie),string:new oe}},ae.prototype.delete=function(e){return Ae(this,e).delete(e)},ae.prototype.get=function(e){return Ae(this,e).get(e)},ae.prototype.has=function(e){return Ae(this,e).has(e)},ae.prototype.set=function(e,t){return Ae(this,e).set(e,t),this},ue.prototype.add=ue.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},ue.prototype.has=function(e){return this.__data__.has(e)},se.prototype.clear=function(){this.__data__=new ie},se.prototype.delete=function(e){return this.__data__.delete(e)},se.prototype.get=function(e){return this.__data__.get(e)},se.prototype.has=function(e){return this.__data__.has(e)},se.prototype.set=function(e,t){var r=this.__data__;if(r instanceof ie){var n=r.__data__;if(!H||n.length<199)return n.push([e,t]),this;r=this.__data__=new ae(n)}return r.set(e,t),this};var le,pe,de=(le=function(e,t){return e&&_e(e,t,He)},function(e,t){if(null==e)return e;if(!qe(e))return le(e,t);for(var r=e.length,n=pe?r:-1,o=Object(e);(pe?n--:++nu))return!1;var c=i.get(e);if(c&&i.get(t))return c==t;var f=-1,l=!0,p=1&o?new ue:void 0;for(i.set(e,t),i.set(t,e);++f-1&&e%1==0&&e-1&&e%1==0&&e<=9007199254740991}function Fe(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Ne(e){return!!e&&"object"==typeof e}function Ve(e){return"symbol"==typeof e||Ne(e)&&"[object Symbol]"==L.call(e)}var Ge=w?function(e){return function(t){return e(t)}}(w):function(e){return Ne(e)&&Be(e.length)&&!!d[L.call(e)]};function He(e){return qe(e)?ce(e):we(e)}function Xe(e){return e}e.exports=function(e,t){return(Le(e)?j:he)(e,me(t))}})),_={assignIn:lodash_assignin,remove:lodash_remove,filter:lodash_filter},tusuploader=function(e){var t={QUEUED:1,STARTED:2,UPLOADING:3,COMPLETED:4,CANCELLED:5,FAILED:6},r=mitt(),n=[],o=_.assignIn({endpoint:"/uploadjobs/",retryDelays:[0,1e3,3e3,5e3],autoUpload:!1,chunkSize:5e3},e||{});if(void 0===typeof document.querySelector)throw new Error("TusUpload: Browser not supported.");if(!o.endpoint)throw new Error("TusUpload: Url not specified.");if(!tus.isSupported)throw new Error("TusUpload: Tus upload protocol not supported.");function i(e){this.status=t.FAILED,r.emit("upload.failed",{upload:this,type:"upload.failed",error:e})}function a(e,n,o){var i=(n/o*100).toFixed(2);this.status=t.UPLOADING,this.uploadPercentage=i,this.uploadTransferredSize=n,r.emit("upload.progress",{upload:this,type:"upload.progress",percentage:i,total:o,transferred:n})}function u(){this.status=t.COMPLETED,r.emit("upload.completed",{upload:this,type:"upload.completed"})}function s(e,r){return this.id=cuid_1(),this.metadata=_.assignIn({filename:e.name,upload_request_id:this.id},r||{}),this.transport=new tus.Upload(e,{endpoint:o.tus_endpoint,retryDelays:o.retryDelays,chunkSize:o.chunkSize,metadata:this.metadata,onError:i.bind(this),onChunkComplete:a.bind(this),onSuccess:u.bind(this)}),this.status=t.QUEUED,this.uploadToken=null,this.uploadPercentage=0,this.uploadSize=e.size,this.uploadTransferredSize=0,this.uploadRemainingTime=null,this.file=e,this}s.prototype.stop=function(){return this.transport.abort(),this.status=t.CANCELLED,window.axios.delete(o.endpoint+""+this.id).then(function(){r.emit("upload.cancelled",{upload:this,type:"upload.cancelled"})}.bind(this)).catch((function(){})),this},s.prototype.start=function(){return this.status=t.STARTED,r.emit("upload.started",{upload:this,type:"upload.started"}),window.axios.post(o.endpoint,lodash_assignin({id:this.id,filename:this.metadata.filename,filesize:this.file.size||"",filetype:this.file.type||""},this.metadata)).then(function(e){this.uploadToken=e.data.upload_token,this.transport.options.metadata.token=this.uploadToken,this.transport.options.endpoint=e.data.location,this.status=t.UPLOADING,this.transport.start()}.bind(this)).catch((function(e){i(e)})),this};var c={upload:function(e,t){var i=new s(e,t||{});return n.push(i),r.emit("upload.queued",{upload:i,type:"upload.queued"}),o.autoUpload&&i.start(),i}};return c.add=c.upload,c.remove=function(e){var o=_.remove(n,(function(t){return t.id===e}));return o&&o.length>=1?(o.forEach((function(e){e.status===t.UPLOADING&&e.stop()}),this),r.emit("upload.removed",{upload:o,type:"upload.removed"}),o):null},c.cancel=function(e){var r=_.remove(n,(function(t){return t.id===e}));return r&&r.length>=1?(r.forEach((function(e){e.status===t.UPLOADING&&e.stop()}),this),1==r.length?r[0]:r):null},c.uploads=function(e){return _.filter(n,e)},c.on=function(e,t){return r.on(e,t),c},c.off=function(e,t){return r.removeListener(e,t),c},c.Status=t,c.Upload=s,c};return tusuploader}(); diff --git a/public/js/tusuploader.umd.js b/public/js/tusuploader.umd.js deleted file mode 100644 index f48a53a..0000000 --- a/public/js/tusuploader.umd.js +++ /dev/null @@ -1,1914 +0,0 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global.TusUploader = factory()); -}(this, (function () { 'use strict'; - -var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - - - - -function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; -} - -var fingerprint_1 = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = fingerprint; -/** - * Generate a fingerprint for a file which will be used the store the endpoint - * - * @param {File} file - * @return {String} - */ -function fingerprint(file) { - return ["tus", file.name, file.type, file.size, file.lastModified].join("-"); -} -}); - -var error = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var DetailedError = function (_Error) { - _inherits(DetailedError, _Error); - - function DetailedError(error) { - var causingErr = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; - var xhr = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; - - _classCallCheck(this, DetailedError); - - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(DetailedError).call(this, error.message)); - - _this.originalRequest = xhr; - _this.causingError = causingErr; - - var message = error.message; - if (causingErr != null) { - message += ", caused by " + causingErr.toString(); - } - if (xhr != null) { - message += ", originated from request (response code: " + xhr.status + ", response text: " + xhr.responseText + ")"; - } - _this.message = message; - return _this; - } - - return DetailedError; -}(Error); - -exports.default = DetailedError; -}); - -var hasOwn = Object.prototype.hasOwnProperty; -var toStr = Object.prototype.toString; - -var isArray = function isArray(arr) { - if (typeof Array.isArray === 'function') { - return Array.isArray(arr); - } - - return toStr.call(arr) === '[object Array]'; -}; - -var isPlainObject = function isPlainObject(obj) { - if (!obj || toStr.call(obj) !== '[object Object]') { - return false; - } - - var hasOwnConstructor = hasOwn.call(obj, 'constructor'); - var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf'); - // Not own constructor property must be Object - if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) { - return false; - } - - // Own properties are enumerated firstly, so to speed up, - // if last one is own, then all properties are own. - var key; - for (key in obj) { /**/ } - - return typeof key === 'undefined' || hasOwn.call(obj, key); -}; - -var index$2 = function extend() { - var options, name, src, copy, copyIsArray, clone; - var target = arguments[0]; - var i = 1; - var length = arguments.length; - var deep = false; - - // Handle a deep copy situation - if (typeof target === 'boolean') { - deep = target; - target = arguments[1] || {}; - // skip the boolean and the target - i = 2; - } - if (target == null || (typeof target !== 'object' && typeof target !== 'function')) { - target = {}; - } - - for (; i < length; ++i) { - options = arguments[i]; - // Only deal with non-null/undefined values - if (options != null) { - // Extend the base object - for (name in options) { - src = target[name]; - copy = options[name]; - - // Prevent never-ending loop - if (target !== copy) { - // Recurse if we're merging plain objects or arrays - if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) { - if (copyIsArray) { - copyIsArray = false; - clone = src && isArray(src) ? src : []; - } else { - clone = src && isPlainObject(src) ? src : {}; - } - - // Never move original objects, clone them - target[name] = extend(deep, clone, copy); - - // Don't bring in undefined values - } else if (typeof copy !== 'undefined') { - target[name] = copy; - } - } - } - } - } - - // Return the modified object - return target; -}; - -var resolveUrl = createCommonjsModule(function (module, exports) { -// Copyright 2014 Simon Lydell -// X11 (“MIT”) Licensed. (See LICENSE.) - -void (function(root, factory) { - if (typeof undefined === "function" && undefined.amd) { - undefined(factory); - } else { - module.exports = factory(); - } -}(commonjsGlobal, function() { - - function resolveUrl(/* ...urls */) { - var numUrls = arguments.length; - - if (numUrls === 0) { - throw new Error("resolveUrl requires at least one argument; got none.") - } - - var base = document.createElement("base"); - base.href = arguments[0]; - - if (numUrls === 1) { - return base.href - } - - var head = document.getElementsByTagName("head")[0]; - head.insertBefore(base, head.firstChild); - - var a = document.createElement("a"); - var resolved; - - for (var index = 1; index < numUrls; index++) { - a.href = arguments[index]; - resolved = a.href; - base.href = resolved; - } - - head.removeChild(base); - - return resolved - } - - return resolveUrl - -})); -}); - -var request = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.newRequest = newRequest; -exports.resolveUrl = resolveUrl$$1; - - - -var _resolveUrl2 = _interopRequireDefault(resolveUrl); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function newRequest() { - return new window.XMLHttpRequest(); -} /* global window */ - - -function resolveUrl$$1(origin, link) { - return (0, _resolveUrl2.default)(origin, link); -} -}); - -var source = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.getSource = getSource; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var FileSource = function () { - function FileSource(file) { - _classCallCheck(this, FileSource); - - this._file = file; - this.size = file.size; - } - - _createClass(FileSource, [{ - key: "slice", - value: function slice(start, end) { - return this._file.slice(start, end); - } - }, { - key: "close", - value: function close() {} - }]); - - return FileSource; -}(); - -function getSource(input) { - // Since we emulate the Blob type in our tests (not all target browsers - // support it), we cannot use `instanceof` for testing whether the input value - // can be handled. Instead, we simply check is the slice() function and the - // size property are available. - if (typeof input.slice === "function" && typeof input.size !== "undefined") { - return new FileSource(input); - } - - throw new Error("source object may only be an instance of File or Blob in this environment"); -} -}); - -var base64 = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.encode = encode; -/* global: window */ - -var _window = window; -var btoa = _window.btoa; -function encode(data) { - return btoa(unescape(encodeURIComponent(data))); -} - -var isSupported = exports.isSupported = "btoa" in window; -}); - -var storage = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.setItem = setItem; -exports.getItem = getItem; -exports.removeItem = removeItem; -/* global window, localStorage */ - -var hasStorage = false; -try { - hasStorage = "localStorage" in window; - - // Attempt to store and read entries from the local storage to detect Private - // Mode on Safari on iOS (see #49) - var key = "tusSupport"; - localStorage.setItem(key, localStorage.getItem(key)); -} catch (e) { - // If we try to access localStorage inside a sandboxed iframe, a SecurityError - // is thrown. When in private mode on iOS Safari, a QuotaExceededError is - // thrown (see #49) - if (e.code === e.SECURITY_ERR || e.code === e.QUOTA_EXCEEDED_ERR) { - hasStorage = false; - } else { - throw e; - } -} - -var canStoreURLs = exports.canStoreURLs = hasStorage; - -function setItem(key, value) { - if (!hasStorage) return; - return localStorage.setItem(key, value); -} - -function getItem(key) { - if (!hasStorage) return; - return localStorage.getItem(key); -} - -function removeItem(key) { - if (!hasStorage) return; - return localStorage.removeItem(key); -} -}); - -var upload = createCommonjsModule(function (module, exports) { -// Generated by Babel -"use strict"; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global window */ - - -// We import the files used inside the Node environment which are rewritten -// for browsers using the rules defined in the package.json - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - - - -var _fingerprint2 = _interopRequireDefault(fingerprint_1); - - - -var _error2 = _interopRequireDefault(error); - - - -var _extend2 = _interopRequireDefault(index$2); - - - - - - - -var Base64 = _interopRequireWildcard(base64); - - - -var Storage = _interopRequireWildcard(storage); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var defaultOptions = { - endpoint: "", - fingerprint: _fingerprint2.default, - resume: true, - onProgress: null, - onChunkComplete: null, - onSuccess: null, - onError: null, - headers: {}, - chunkSize: Infinity, - withCredentials: false, - uploadUrl: null, - uploadSize: null, - overridePatchMethod: false, - retryDelays: null -}; - -var Upload = function () { - function Upload(file, options) { - _classCallCheck(this, Upload); - - this.options = (0, _extend2.default)(true, {}, defaultOptions, options); - - // The underlying File/Blob object - this.file = file; - - // The URL against which the file will be uploaded - this.url = null; - - // The underlying XHR object for the current PATCH request - this._xhr = null; - - // The fingerpinrt for the current file (set after start()) - this._fingerprint = null; - - // The offset used in the current PATCH request - this._offset = null; - - // True if the current PATCH request has been aborted - this._aborted = false; - - // The file's size in bytes - this._size = null; - - // The Source object which will wrap around the given file and provides us - // with a unified interface for getting its size and slice chunks from its - // content allowing us to easily handle Files, Blobs, Buffers and Streams. - this._source = null; - - // The current count of attempts which have been made. Null indicates none. - this._retryAttempt = 0; - - // The timeout's ID which is used to delay the next retry - this._retryTimeout = null; - - // The offset of the remote upload before the latest attempt was started. - this._offsetBeforeRetry = 0; - } - - _createClass(Upload, [{ - key: "start", - value: function start() { - var _this = this; - - var file = this.file; - - if (!file) { - this._emitError(new Error("tus: no file or stream to upload provided")); - return; - } - - if (!this.options.endpoint) { - this._emitError(new Error("tus: no endpoint provided")); - return; - } - - var source$$1 = this._source = (0, source.getSource)(file, this.options.chunkSize); - - // Firstly, check if the caller has supplied a manual upload size or else - // we will use the calculated size by the source object. - if (this.options.uploadSize != null) { - var size = +this.options.uploadSize; - if (isNaN(size)) { - throw new Error("tus: cannot convert `uploadSize` option into a number"); - } - - this._size = size; - } else { - var size = source$$1.size; - - // The size property will be null if we cannot calculate the file's size, - // for example if you handle a stream. - if (size == null) { - throw new Error("tus: cannot automatically derive upload's size from input and must be specified manually using the `uploadSize` option"); - } - - this._size = size; - } - - var retryDelays = this.options.retryDelays; - if (retryDelays != null) { - if (Object.prototype.toString.call(retryDelays) !== "[object Array]") { - throw new Error("tus: the `retryDelays` option must either be an array or null"); - } else { - (function () { - var errorCallback = _this.options.onError; - _this.options.onError = function (err) { - // Restore the original error callback which may have been set. - _this.options.onError = errorCallback; - - // We will reset the attempt counter if - // - we were already able to connect to the server (offset != null) and - // - we were able to upload a small chunk of data to the server - var shouldResetDelays = _this._offset != null && _this._offset > _this._offsetBeforeRetry; - if (shouldResetDelays) { - _this._retryAttempt = 0; - } - - var isOnline = true; - if (typeof window !== "undefined" && "navigator" in window && window.navigator.onLine === false) { - isOnline = false; - } - - // We only attempt a retry if - // - we didn't exceed the maxium number of retries, yet, and - // - this error was caused by a request or it's response and - // - the browser does not indicate that we are offline - var shouldRetry = _this._retryAttempt < retryDelays.length && err.originalRequest != null && isOnline; - - if (!shouldRetry) { - _this._emitError(err); - return; - } - - var delay = retryDelays[_this._retryAttempt++]; - - _this._offsetBeforeRetry = _this._offset; - _this.options.uploadUrl = _this.url; - - _this._retryTimeout = setTimeout(function () { - _this.start(); - }, delay); - }; - })(); - } - } - - // Reset the aborted flag when the upload is started or else the - // _startUpload will stop before sending a request if the upload has been - // aborted previously. - this._aborted = false; - - // A URL has manually been specified, so we try to resume - if (this.options.uploadUrl != null) { - this.url = this.options.uploadUrl; - this._resumeUpload(); - return; - } - - // Try to find the endpoint for the file in the storage - if (this.options.resume) { - this._fingerprint = this.options.fingerprint(file); - var resumedUrl = Storage.getItem(this._fingerprint); - - if (resumedUrl != null) { - this.url = resumedUrl; - this._resumeUpload(); - return; - } - } - - // An upload has not started for the file yet, so we start a new one - this._createUpload(); - } - }, { - key: "abort", - value: function abort() { - if (this._xhr !== null) { - this._xhr.abort(); - this._source.close(); - this._aborted = true; - } - - if (this._retryTimeout != null) { - clearTimeout(this._retryTimeout); - this._retryTimeout = null; - } - } - }, { - key: "_emitXhrError", - value: function _emitXhrError(xhr, err, causingErr) { - this._emitError(new _error2.default(err, causingErr, xhr)); - } - }, { - key: "_emitError", - value: function _emitError(err) { - if (typeof this.options.onError === "function") { - this.options.onError(err); - } else { - throw err; - } - } - }, { - key: "_emitSuccess", - value: function _emitSuccess() { - if (typeof this.options.onSuccess === "function") { - this.options.onSuccess(); - } - } - - /** - * Publishes notification when data has been sent to the server. This - * data may not have been accepted by the server yet. - * @param {number} bytesSent Number of bytes sent to the server. - * @param {number} bytesTotal Total number of bytes to be sent to the server. - */ - - }, { - key: "_emitProgress", - value: function _emitProgress(bytesSent, bytesTotal) { - if (typeof this.options.onProgress === "function") { - this.options.onProgress(bytesSent, bytesTotal); - } - } - - /** - * Publishes notification when a chunk of data has been sent to the server - * and accepted by the server. - * @param {number} chunkSize Size of the chunk that was accepted by the - * server. - * @param {number} bytesAccepted Total number of bytes that have been - * accepted by the server. - * @param {number} bytesTotal Total number of bytes to be sent to the server. - */ - - }, { - key: "_emitChunkComplete", - value: function _emitChunkComplete(chunkSize, bytesAccepted, bytesTotal) { - if (typeof this.options.onChunkComplete === "function") { - this.options.onChunkComplete(chunkSize, bytesAccepted, bytesTotal); - } - } - - /** - * Set the headers used in the request and the withCredentials property - * as defined in the options - * - * @param {XMLHttpRequest} xhr - */ - - }, { - key: "_setupXHR", - value: function _setupXHR(xhr) { - xhr.setRequestHeader("Tus-Resumable", "1.0.0"); - var headers = this.options.headers; - - for (var name in headers) { - xhr.setRequestHeader(name, headers[name]); - } - - xhr.withCredentials = this.options.withCredentials; - } - - /** - * Create a new upload using the creation extension by sending a POST - * request to the endpoint. After successful creation the file will be - * uploaded - * - * @api private - */ - - }, { - key: "_createUpload", - value: function _createUpload() { - var _this2 = this; - - var xhr = (0, request.newRequest)(); - xhr.open("POST", this.options.endpoint, true); - - xhr.onload = function () { - if (!(xhr.status >= 200 && xhr.status < 300)) { - _this2._emitXhrError(xhr, new Error("tus: unexpected response while creating upload")); - return; - } - - _this2.url = (0, request.resolveUrl)(_this2.options.endpoint, xhr.getResponseHeader("Location")); - - if (_this2.options.resume) { - Storage.setItem(_this2._fingerprint, _this2.url); - } - - _this2._offset = 0; - _this2._startUpload(); - }; - - xhr.onerror = function (err) { - _this2._emitXhrError(xhr, new Error("tus: failed to create upload"), err); - }; - - this._setupXHR(xhr); - xhr.setRequestHeader("Upload-Length", this._size); - - // Add metadata if values have been added - var metadata = encodeMetadata(this.options.metadata); - if (metadata !== "") { - xhr.setRequestHeader("Upload-Metadata", metadata); - } - - xhr.send(null); - } - - /* - * Try to resume an existing upload. First a HEAD request will be sent - * to retrieve the offset. If the request fails a new upload will be - * created. In the case of a successful response the file will be uploaded. - * - * @api private - */ - - }, { - key: "_resumeUpload", - value: function _resumeUpload() { - var _this3 = this; - - var xhr = (0, request.newRequest)(); - xhr.open("HEAD", this.url, true); - - xhr.onload = function () { - if (!(xhr.status >= 200 && xhr.status < 300)) { - if (_this3.options.resume) { - // Remove stored fingerprint and corresponding endpoint, - // since the file can not be found - Storage.removeItem(_this3._fingerprint); - } - - // If the upload is locked (indicated by the 423 Locked status code), we - // emit an error instead of directly starting a new upload. This way the - // retry logic can catch the error and will retry the upload. An upload - // is usually locked for a short period of time and will be available - // afterwards. - if (xhr.status === 423) { - _this3._emitXhrError(xhr, new Error("tus: upload is currently locked; retry later")); - return; - } - - // Try to create a new upload - _this3.url = null; - _this3._createUpload(); - return; - } - - var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10); - if (isNaN(offset)) { - _this3._emitXhrError(xhr, new Error("tus: invalid or missing offset value")); - return; - } - - var length = parseInt(xhr.getResponseHeader("Upload-Length"), 10); - if (isNaN(length)) { - _this3._emitXhrError(xhr, new Error("tus: invalid or missing length value")); - return; - } - - // Upload has already been completed and we do not need to send additional - // data to the server - if (offset === length) { - _this3._emitProgress(length, length); - _this3._emitSuccess(); - return; - } - - _this3._offset = offset; - _this3._startUpload(); - }; - - xhr.onerror = function (err) { - _this3._emitXhrError(xhr, new Error("tus: failed to resume upload"), err); - }; - - this._setupXHR(xhr); - xhr.send(null); - } - - /** - * Start uploading the file using PATCH requests. The file will be divided - * into chunks as specified in the chunkSize option. During the upload - * the onProgress event handler may be invoked multiple times. - * - * @api private - */ - - }, { - key: "_startUpload", - value: function _startUpload() { - var _this4 = this; - - // If the upload has been aborted, we will not send the next PATCH request. - // This is important if the abort method was called during a callback, such - // as onChunkComplete or onProgress. - if (this._aborted) { - return; - } - - var xhr = this._xhr = (0, request.newRequest)(); - - // Some browser and servers may not support the PATCH method. For those - // cases, you can tell tus-js-client to use a POST request with the - // X-HTTP-Method-Override header for simulating a PATCH request. - if (this.options.overridePatchMethod) { - xhr.open("POST", this.url, true); - xhr.setRequestHeader("X-HTTP-Method-Override", "PATCH"); - } else { - xhr.open("PATCH", this.url, true); - } - - xhr.onload = function () { - if (!(xhr.status >= 200 && xhr.status < 300)) { - _this4._emitXhrError(xhr, new Error("tus: unexpected response while uploading chunk")); - return; - } - - var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10); - if (isNaN(offset)) { - _this4._emitXhrError(xhr, new Error("tus: invalid or missing offset value")); - return; - } - - _this4._emitProgress(offset, _this4._size); - _this4._emitChunkComplete(offset - _this4._offset, offset, _this4._size); - - _this4._offset = offset; - - if (offset == _this4._size) { - // Yay, finally done :) - _this4._emitSuccess(); - _this4._source.close(); - return; - } - - _this4._startUpload(); - }; - - xhr.onerror = function (err) { - // Don't emit an error if the upload was aborted manually - if (_this4._aborted) { - return; - } - - _this4._emitXhrError(xhr, new Error("tus: failed to upload chunk at offset " + _this4._offset), err); - }; - - // Test support for progress events before attaching an event listener - if ("upload" in xhr) { - xhr.upload.onprogress = function (e) { - if (!e.lengthComputable) { - return; - } - - _this4._emitProgress(start + e.loaded, _this4._size); - }; - } - - this._setupXHR(xhr); - - xhr.setRequestHeader("Upload-Offset", this._offset); - xhr.setRequestHeader("Content-Type", "application/offset+octet-stream"); - - var start = this._offset; - var end = this._offset + this.options.chunkSize; - - // The specified chunkSize may be Infinity or the calcluated end position - // may exceed the file's size. In both cases, we limit the end position to - // the input's total size for simpler calculations and correctness. - if (end === Infinity || end > this._size) { - end = this._size; - } - - xhr.send(this._source.slice(start, end)); - } - }]); - - return Upload; -}(); - -function encodeMetadata(metadata) { - if (!Base64.isSupported) { - return ""; - } - - var encoded = []; - - for (var key in metadata) { - encoded.push(key + " " + Base64.encode(metadata[key])); - } - - return encoded.join(","); -} - -Upload.defaultOptions = defaultOptions; - -exports.default = Upload; -}); - -var index = createCommonjsModule(function (module) { -// Generated by Babel -"use strict"; - - - -var _upload2 = _interopRequireDefault(upload); - - - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/* global window */ -var defaultOptions = _upload2.default.defaultOptions; - - -if (typeof window !== "undefined") { - // Browser environment using XMLHttpRequest - var _window = window; - var XMLHttpRequest = _window.XMLHttpRequest; - var Blob = _window.Blob; - - - var isSupported = XMLHttpRequest && Blob && typeof Blob.prototype.slice === "function"; -} else { - // Node.js environment using http module - var isSupported = true; -} - -// The usage of the commonjs exporting syntax instead of the new ECMAScript -// one is actually inteded and prevents weird behaviour if we are trying to -// import this module in another module using Babel. -module.exports = { - Upload: _upload2.default, - isSupported: isSupported, - canStoreURLs: storage.canStoreURLs, - defaultOptions: defaultOptions -}; -}); - -var ee = createCommonjsModule(function (module) { -module.exports = { - on: function (ev, handler) { - var events = this._events;(events[ev] || (events[ev] = [])).push(handler); - }, - removeListener: function (ev, handler) { - var array = this._events[ev]; - - array && array.splice(array.indexOf(handler), 1); - }, - emit: function (ev) { - var args = [].slice.call(arguments, 1), - array = this._events[ev] || []; - - for (var i = 0, len = array.length; i < len; i++) { - array[i].apply(this, args); - } - }, - once: function (ev, handler) { - this.on(ev, function () { - handler.apply(this, arguments); - this.removeListener(ev, handler); - }); - }, - constructor: function constructor() { - this._events = {}; - return this - } -}; - -module.exports.constructor.prototype = module.exports; -}); - -var browserCuid = createCommonjsModule(function (module) { -/** - * cuid.js - * Collision-resistant UID generator for browsers and node. - * Sequential for fast db lookups and recency sorting. - * Safe for element IDs and server-side lookups. - * - * Extracted from CLCTR - * - * Copyright (c) Eric Elliott 2012 - * MIT License - */ - -/*global window, navigator, document, require, process, module */ -(function (app) { - 'use strict'; - var namespace = 'cuid', - c = 0, - blockSize = 4, - base = 36, - discreteValues = Math.pow(base, blockSize), - - pad = function pad(num, size) { - var s = "000000000" + num; - return s.substr(s.length-size); - }, - - randomBlock = function randomBlock() { - return pad((Math.random() * - discreteValues << 0) - .toString(base), blockSize); - }, - - safeCounter = function () { - c = (c < discreteValues) ? c : 0; - c++; // this is not subliminal - return c - 1; - }, - - api = function cuid() { - // Starting with a lowercase letter makes - // it HTML element ID friendly. - var letter = 'c', // hard-coded allows for sequential access - - // timestamp - // warning: this exposes the exact date and time - // that the uid was created. - timestamp = (new Date().getTime()).toString(base), - - // Prevent same-machine collisions. - counter, - - // A few chars to generate distinct ids for different - // clients (so different computers are far less - // likely to generate the same id) - fingerprint = api.fingerprint(), - - // Grab some more chars from Math.random() - random = randomBlock() + randomBlock(); - - counter = pad(safeCounter().toString(base), blockSize); - - return (letter + timestamp + counter + fingerprint + random); - }; - - api.slug = function slug() { - var date = new Date().getTime().toString(36), - counter, - print = api.fingerprint().slice(0,1) + - api.fingerprint().slice(-1), - random = randomBlock().slice(-2); - - counter = safeCounter().toString(36).slice(-4); - - return date.slice(-2) + - counter + print + random; - }; - - api.globalCount = function globalCount() { - // We want to cache the results of this - var cache = (function calc() { - var i, - count = 0; - - for (i in window) { - count++; - } - - return count; - }()); - - api.globalCount = function () { return cache; }; - return cache; - }; - - api.fingerprint = function browserPrint() { - return pad((navigator.mimeTypes.length + - navigator.userAgent.length).toString(36) + - api.globalCount().toString(36), 4); - }; - - // don't change anything from here down. - if (app.register) { - app.register(namespace, api); - } else { - module.exports = api; - } - -}(commonjsGlobal.applitude || commonjsGlobal)); -}); - -/** - * lodash (Custom Build) - * Build: `lodash modularize exports="npm" -o ./` - * Copyright jQuery Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ - -/** Used as references for various `Number` constants. */ -var MAX_SAFE_INTEGER = 9007199254740991; - -/** `Object#toString` result references. */ -var argsTag = '[object Arguments]'; -var funcTag = '[object Function]'; -var genTag = '[object GeneratorFunction]'; - -/** Used to detect unsigned integer values. */ -var reIsUint = /^(?:0|[1-9]\d*)$/; - -/** - * A faster alternative to `Function#apply`, this function invokes `func` - * with the `this` binding of `thisArg` and the arguments of `args`. - * - * @private - * @param {Function} func The function to invoke. - * @param {*} thisArg The `this` binding of `func`. - * @param {Array} args The arguments to invoke `func` with. - * @returns {*} Returns the result of `func`. - */ -function apply(func, thisArg, args) { - switch (args.length) { - case 0: return func.call(thisArg); - case 1: return func.call(thisArg, args[0]); - case 2: return func.call(thisArg, args[0], args[1]); - case 3: return func.call(thisArg, args[0], args[1], args[2]); - } - return func.apply(thisArg, args); -} - -/** - * The base implementation of `_.times` without support for iteratee shorthands - * or max array length checks. - * - * @private - * @param {number} n The number of times to invoke `iteratee`. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Array} Returns the array of results. - */ -function baseTimes(n, iteratee) { - var index = -1, - result = Array(n); - - while (++index < n) { - result[index] = iteratee(index); - } - return result; -} - -/** Used for built-in method references. */ -var objectProto = Object.prototype; - -/** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; - -/** - * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) - * of values. - */ -var objectToString = objectProto.toString; - -/** Built-in value references. */ -var propertyIsEnumerable = objectProto.propertyIsEnumerable; - -/* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; - -/** - * Creates an array of the enumerable property names of the array-like `value`. - * - * @private - * @param {*} value The value to query. - * @param {boolean} inherited Specify returning inherited property names. - * @returns {Array} Returns the array of property names. - */ -function arrayLikeKeys(value, inherited) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - // Safari 9 makes `arguments.length` enumerable in strict mode. - var result = (isArray$1(value) || isArguments(value)) - ? baseTimes(value.length, String) - : []; - - var length = result.length, - skipIndexes = !!length; - - for (var key in value) { - if ((inherited || hasOwnProperty.call(value, key)) && - !(skipIndexes && (key == 'length' || isIndex(key, length)))) { - result.push(key); - } - } - return result; -} - -/** - * Assigns `value` to `key` of `object` if the existing value is not equivalent - * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * for equality comparisons. - * - * @private - * @param {Object} object The object to modify. - * @param {string} key The key of the property to assign. - * @param {*} value The value to assign. - */ -function assignValue(object, key, value) { - var objValue = object[key]; - if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || - (value === undefined && !(key in object))) { - object[key] = value; - } -} - -/** - * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ -function baseKeysIn(object) { - if (!isObject(object)) { - return nativeKeysIn(object); - } - var isProto = isPrototype(object), - result = []; - - for (var key in object) { - if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { - result.push(key); - } - } - return result; -} - -/** - * The base implementation of `_.rest` which doesn't validate or coerce arguments. - * - * @private - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - */ -function baseRest(func, start) { - start = nativeMax(start === undefined ? (func.length - 1) : start, 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - array = Array(length); - - while (++index < length) { - array[index] = args[start + index]; - } - index = -1; - var otherArgs = Array(start + 1); - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = array; - return apply(func, this, otherArgs); - }; -} - -/** - * Copies properties of `source` to `object`. - * - * @private - * @param {Object} source The object to copy properties from. - * @param {Array} props The property identifiers to copy. - * @param {Object} [object={}] The object to copy properties to. - * @param {Function} [customizer] The function to customize copied values. - * @returns {Object} Returns `object`. - */ -function copyObject(source, props, object, customizer) { - object || (object = {}); - - var index = -1, - length = props.length; - - while (++index < length) { - var key = props[index]; - - var newValue = customizer - ? customizer(object[key], source[key], key, object, source) - : undefined; - - assignValue(object, key, newValue === undefined ? source[key] : newValue); - } - return object; -} - -/** - * Creates a function like `_.assign`. - * - * @private - * @param {Function} assigner The function to assign values. - * @returns {Function} Returns the new assigner function. - */ -function createAssigner(assigner) { - return baseRest(function(object, sources) { - var index = -1, - length = sources.length, - customizer = length > 1 ? sources[length - 1] : undefined, - guard = length > 2 ? sources[2] : undefined; - - customizer = (assigner.length > 3 && typeof customizer == 'function') - ? (length--, customizer) - : undefined; - - if (guard && isIterateeCall(sources[0], sources[1], guard)) { - customizer = length < 3 ? undefined : customizer; - length = 1; - } - object = Object(object); - while (++index < length) { - var source = sources[index]; - if (source) { - assigner(object, source, index, customizer); - } - } - return object; - }); -} - -/** - * Checks if `value` is a valid array-like index. - * - * @private - * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ -function isIndex(value, length) { - length = length == null ? MAX_SAFE_INTEGER : length; - return !!length && - (typeof value == 'number' || reIsUint.test(value)) && - (value > -1 && value % 1 == 0 && value < length); -} - -/** - * Checks if the given arguments are from an iteratee call. - * - * @private - * @param {*} value The potential iteratee value argument. - * @param {*} index The potential iteratee index or key argument. - * @param {*} object The potential iteratee object argument. - * @returns {boolean} Returns `true` if the arguments are from an iteratee call, - * else `false`. - */ -function isIterateeCall(value, index, object) { - if (!isObject(object)) { - return false; - } - var type = typeof index; - if (type == 'number' - ? (isArrayLike(object) && isIndex(index, object.length)) - : (type == 'string' && index in object) - ) { - return eq(object[index], value); - } - return false; -} - -/** - * Checks if `value` is likely a prototype object. - * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. - */ -function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; - - return value === proto; -} - -/** - * This function is like - * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) - * except that it includes inherited enumerable properties. - * - * @private - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - */ -function nativeKeysIn(object) { - var result = []; - if (object != null) { - for (var key in Object(object)) { - result.push(key); - } - } - return result; -} - -/** - * Performs a - * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) - * comparison between two values to determine if they are equivalent. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to compare. - * @param {*} other The other value to compare. - * @returns {boolean} Returns `true` if the values are equivalent, else `false`. - * @example - * - * var object = { 'a': 1 }; - * var other = { 'a': 1 }; - * - * _.eq(object, object); - * // => true - * - * _.eq(object, other); - * // => false - * - * _.eq('a', 'a'); - * // => true - * - * _.eq('a', Object('a')); - * // => false - * - * _.eq(NaN, NaN); - * // => true - */ -function eq(value, other) { - return value === other || (value !== value && other !== other); -} - -/** - * Checks if `value` is likely an `arguments` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. - * @example - * - * _.isArguments(function() { return arguments; }()); - * // => true - * - * _.isArguments([1, 2, 3]); - * // => false - */ -function isArguments(value) { - // Safari 8.1 makes `arguments.callee` enumerable in strict mode. - return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && - (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); -} - -/** - * Checks if `value` is classified as an `Array` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array, else `false`. - * @example - * - * _.isArray([1, 2, 3]); - * // => true - * - * _.isArray(document.body.children); - * // => false - * - * _.isArray('abc'); - * // => false - * - * _.isArray(_.noop); - * // => false - */ -var isArray$1 = Array.isArray; - -/** - * Checks if `value` is array-like. A value is considered array-like if it's - * not a function and has a `value.length` that's an integer greater than or - * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. - * @example - * - * _.isArrayLike([1, 2, 3]); - * // => true - * - * _.isArrayLike(document.body.children); - * // => true - * - * _.isArrayLike('abc'); - * // => true - * - * _.isArrayLike(_.noop); - * // => false - */ -function isArrayLike(value) { - return value != null && isLength(value.length) && !isFunction(value); -} - -/** - * This method is like `_.isArrayLike` except that it also checks if `value` - * is an object. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an array-like object, - * else `false`. - * @example - * - * _.isArrayLikeObject([1, 2, 3]); - * // => true - * - * _.isArrayLikeObject(document.body.children); - * // => true - * - * _.isArrayLikeObject('abc'); - * // => false - * - * _.isArrayLikeObject(_.noop); - * // => false - */ -function isArrayLikeObject(value) { - return isObjectLike(value) && isArrayLike(value); -} - -/** - * Checks if `value` is classified as a `Function` object. - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a function, else `false`. - * @example - * - * _.isFunction(_); - * // => true - * - * _.isFunction(/abc/); - * // => false - */ -function isFunction(value) { - // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8-9 which returns 'object' for typed array and other constructors. - var tag = isObject(value) ? objectToString.call(value) : ''; - return tag == funcTag || tag == genTag; -} - -/** - * Checks if `value` is a valid array-like length. - * - * **Note:** This method is loosely based on - * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. - * @example - * - * _.isLength(3); - * // => true - * - * _.isLength(Number.MIN_VALUE); - * // => false - * - * _.isLength(Infinity); - * // => false - * - * _.isLength('3'); - * // => false - */ -function isLength(value) { - return typeof value == 'number' && - value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; -} - -/** - * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) - * - * @static - * @memberOf _ - * @since 0.1.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an object, else `false`. - * @example - * - * _.isObject({}); - * // => true - * - * _.isObject([1, 2, 3]); - * // => true - * - * _.isObject(_.noop); - * // => true - * - * _.isObject(null); - * // => false - */ -function isObject(value) { - var type = typeof value; - return !!value && (type == 'object' || type == 'function'); -} - -/** - * Checks if `value` is object-like. A value is object-like if it's not `null` - * and has a `typeof` result of "object". - * - * @static - * @memberOf _ - * @since 4.0.0 - * @category Lang - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - * @example - * - * _.isObjectLike({}); - * // => true - * - * _.isObjectLike([1, 2, 3]); - * // => true - * - * _.isObjectLike(_.noop); - * // => false - * - * _.isObjectLike(null); - * // => false - */ -function isObjectLike(value) { - return !!value && typeof value == 'object'; -} - -/** - * This method is like `_.assign` except that it iterates over own and - * inherited source properties. - * - * **Note:** This method mutates `object`. - * - * @static - * @memberOf _ - * @since 4.0.0 - * @alias extend - * @category Object - * @param {Object} object The destination object. - * @param {...Object} [sources] The source objects. - * @returns {Object} Returns `object`. - * @see _.assign - * @example - * - * function Foo() { - * this.a = 1; - * } - * - * function Bar() { - * this.c = 3; - * } - * - * Foo.prototype.b = 2; - * Bar.prototype.d = 4; - * - * _.assignIn({ 'a': 0 }, new Foo, new Bar); - * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } - */ -var assignIn = createAssigner(function(object, source) { - copyObject(source, keysIn(source), object); -}); - -/** - * Creates an array of the own and inherited enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. - * - * @static - * @memberOf _ - * @since 3.0.0 - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. - * @example - * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } - * - * Foo.prototype.c = 3; - * - * _.keysIn(new Foo); - * // => ['a', 'b', 'c'] (iteration order is not guaranteed) - */ -function keysIn(object) { - return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); -} - -var index$4 = assignIn; - -/** - * Tus based client uploader. - * - * It gives you the ability to upload a file to the reference tus server - */ - -// Global axios - -//../../node_modules/tus-js-client/dist/tus - - - - -/** - * Creates a new Tus based file Uploader - * - * @param {object} options - */ -var tusuploader = function(options){ - - var UploadStatus = { - PENDING: 1, - UPLOADING: 2, - RETRYING: 3, - COMPLETED: 4, - CANCELLED: 5, - FAILED: 6, - }; - - var defaultOptions = { - /** - * The TUSd server endpoint - * - * @var {string} - */ - // tus_endpoint: "http://192.168.0.36:1080/uploads/", // might be in the response from the server - /** - * The endpoint that will authorize the upload request - * @var {string} - */ - endpoint: "/uploadjobs/", - /** - * - * @var {array} - */ - retryDelays: [0, 1000, 3000, 5000], - /** - * Automatically starts the upload after has been added to the queue - * - * @default false - * @var {boolean} - */ - autoUpload: false, - }; - - var uploadsQueue = []; - - options = index$4(defaultOptions, options || {}); - - if (typeof document.querySelector === undefined) { - throw new Error("TusUpload: Browser not supported."); - } - - if (!options.endpoint) { - throw new Error("TusUpload: Url not specified."); - } - - if(!index.isSupported) { - throw new Error("TusUpload: Tus upload protocol not supported."); - } - - - - - function handleUploadError(error){ - console.log('UploadError', this, "Failed because:", error); - } - - - function handleUploadProgress(bytesUploaded, bytesTotal){ - var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); - console.log('UploadProgress', this, bytesUploaded, bytesTotal, percentage + "%"); - } - - function handleUploadSuccess(){ - console.log('UploadComplete', this/*, "Download %s from %s", upload.file.name, upload.url*/); - } - - - - /** - * Creates a new upload - * - * @param {File} file the file to upload - * @param {Object} metadata additional metadata to sent to the server - * @return {Upload} - */ - function Upload(file, metadata){ - - this.id = browserCuid(); - - this.metadata = index$4({ - filename: file.name, - upload_request_id: this.id - }, metadata || {}); - - // Create a new tus upload - this.transport = new index.Upload(file, { - endpoint: options.tus_endpoint, - retryDelays: options.retryDelays, - metadata: this.metadata, - onError: handleUploadError.bind(this), - onProgress: handleUploadProgress.bind(this), - onSuccess: handleUploadSuccess.bind(this) - }); - - this.status = UploadStatus.PENDING; - this.uploadToken = null; - - this.file = file; - - return this; - } - - - /** - * Stop the upload - * - * @return {Upload} - */ - Upload.prototype.stop = function(){ - this.transport.abort(); - this.status = UploadStatus.CANCELLED; - return this; - }; - - /** - * Starts the upload - * - * @return {Upload} - */ - Upload.prototype.start = function(){ - - window.axios.post(options.endpoint, index$4({ - id: this.id, - filename: this.metadata.filename, - filesize: this.file.size || '', - filetype: this.file.type || '', - }, this.metadata )).then(function(response){ - - this.uploadToken = response.data.upload_token; - this.transport.options.metadata.token = this.uploadToken; - this.transport.options.endpoint = this.location; - // set the upload token in the metadata of the transport - this.status = UploadStatus.UPLOADING; - this.transport.start(); - - }.bind(this)).catch(function (error) { - console.log(error); - }.bind(this)); - - - return this; - }; - - var TusUploadInner = {}; - - /** - * Upload a file - * - * @param {File} file https://developer.mozilla.org/en-US/docs/Web/API/File - * @param {Object} metadata Application level metatada about the file that should be sent to the server - * @return {Upload} the upload entry added to the queue - */ - TusUploadInner.upload = function(file, metadata){ - - // Create a new upload - var upload = new Upload(file, metadata); - - // add it to the queue - uploadsQueue.push(upload); - - if(options.autoUpload){ - // Immediately start the upload - upload.start(); - } - - return upload; - }; - - TusUploadInner.Status = UploadStatus; - - - window.TusUpload = TusUploadInner; - - return TusUploadInner; -}; - -return tusuploader; - -}))); diff --git a/readme.md b/readme.md index 71a38d2..2615ccc 100644 --- a/readme.md +++ b/readme.md @@ -206,6 +206,8 @@ input.addEventListener("change", function(e) { ``` +> If you are using a module bundler, like Webpack, consider using the common js module version in `public/js/tusuploader.cjs.js` + ### `TusUploader` object The `TusUploader` object handles file upload and queue management. To create an instance of the `TusUploader` use diff --git a/rollup.config.js b/rollup.config.js index 98f9895..dfa9e8c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,22 +2,29 @@ import resolve from 'rollup-plugin-node-resolve'; import commonjs from 'rollup-plugin-commonjs'; import filesize from 'rollup-plugin-filesize'; import {eslint} from 'rollup-plugin-eslint'; +import {terser} from 'rollup-plugin-terser'; import pkg from './package.json'; export default [ - // browser-friendly UMD build { input: 'assets/js/tusuploader.js', - output: { - file: pkg.main, - format: 'iife', - name: 'TusUploader' - }, + output: [ + { + file: pkg.browser, + format: 'iife', + name: 'TusUploader' + }, + { + file: pkg.main, + format: 'cjs', + } + ], plugins: [ resolve({browser: true}), eslint(), - commonjs(), - filesize() + commonjs(), + filesize(), + terser(), ] } ]; diff --git a/src/Console/Commands/TusServerStartCommand.php b/src/Console/Commands/TusServerStartCommand.php index 65bd48d..1f8d6f6 100644 --- a/src/Console/Commands/TusServerStartCommand.php +++ b/src/Console/Commands/TusServerStartCommand.php @@ -57,7 +57,7 @@ public function handle() $noHooks = $this->option('no-hooks'); if($noHooks){ - config(['tusupload.hooks' => '']); + config(['tusupload.hooks_path' => '']); } static::startTusd(function ($type, $buffer) { diff --git a/src/Console/SupportsTusd.php b/src/Console/SupportsTusd.php index ac1a6d7..79cdf57 100644 --- a/src/Console/SupportsTusd.php +++ b/src/Console/SupportsTusd.php @@ -153,7 +153,7 @@ protected static function driverSuffix() protected static function hooksPath() { - $base = config('tusupload.hooks'); + $base = config('tusupload.hooks_path'); if(empty($base)){ return null; diff --git a/tests/Unit/SupportsTusdTraitTest.php b/tests/Unit/SupportsTusdTraitTest.php index c4d18c2..ab8332a 100644 --- a/tests/Unit/SupportsTusdTraitTest.php +++ b/tests/Unit/SupportsTusdTraitTest.php @@ -95,7 +95,7 @@ public function get_tus_arguments() // make also the hooks config empty - $this->app['config']->set('tusupload.hooks', ''); + $this->app['config']->set('tusupload.hooks_path', ''); $arguments = static::tusdArguments(); diff --git a/yarn.lock b/yarn.lock index 5c929d6..0813ae2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3380,6 +3380,17 @@ rollup-plugin-node-resolve@^5.2.0: resolve "^1.11.1" rollup-pluginutils "^2.8.1" +rollup-plugin-terser@^5.1.3: + version "5.1.3" + resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-5.1.3.tgz#5f4c4603b12b4f8d093f4b6f31c9aa5eba98a223" + integrity sha512-FuFuXE5QUJ7snyxHLPp/0LFXJhdomKlIx/aK7Tg88Yubsx/UU/lmInoJafXJ4jwVVNcORJ1wRUC5T9cy5yk0wA== + dependencies: + "@babel/code-frame" "^7.0.0" + jest-worker "^24.6.0" + rollup-pluginutils "^2.8.1" + serialize-javascript "^2.1.2" + terser "^4.1.0" + rollup-pluginutils@^2.7.1, rollup-pluginutils@^2.8.1: version "2.8.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" @@ -3467,6 +3478,11 @@ semver@^6.0.0, semver@^6.1.2, semver@^6.2.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== +serialize-javascript@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-2.1.2.tgz#ecec53b0e0317bdc95ef76ab7074b7384785fa61" + integrity sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ== + set-blocking@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -3782,6 +3798,15 @@ term-size@^2.1.0: resolved "https://registry.yarnpkg.com/term-size/-/term-size-2.1.1.tgz#f81ec25854af91a480d2f9d0c77ffcb26594ed1a" integrity sha512-UqvQSch04R+69g4RDhrslmGvGL3ucDRX/U+snYW0Mab4uCAyKSndUksaoqlJ81QKSpRnIsuOYQCbC2ZWx2896A== +terser@^4.1.0: + version "4.5.1" + resolved "https://registry.yarnpkg.com/terser/-/terser-4.5.1.tgz#63b52d6b6ce344aa6fedcd0ee06a695799eb50bd" + integrity sha512-lH9zLIbX8PRBEFCTvfHGCy0s9HEKnNso1Dx9swSopF3VUnFLB8DpQ61tHxoofovNC/sG0spajJM3EIIRSTByiQ== + dependencies: + commander "^2.20.0" + source-map "~0.6.1" + source-map-support "~0.5.12" + terser@^4.1.3: version "4.4.3" resolved "https://registry.yarnpkg.com/terser/-/terser-4.4.3.tgz#401abc52b88869cf904412503b1eb7da093ae2f0"