js-file-downloader
Advanced tools
Comparing version 1.1.18 to 1.1.19
@@ -103,3 +103,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
\**************************/ | ||
/*! exports provided: downloadException */ | ||
/*! exports provided: DownloadException, downloadException */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -109,2 +109,3 @@ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DownloadException", function() { return DownloadException; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "downloadException", function() { return downloadException; }); | ||
@@ -135,22 +136,27 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var downloadException = /*#__PURE__*/function (_Error) { | ||
_inherits(downloadException, _Error); | ||
var DownloadException = /*#__PURE__*/function (_Error) { | ||
_inherits(DownloadException, _Error); | ||
var _super = _createSuper(downloadException); | ||
var _super = _createSuper(DownloadException); | ||
function downloadException(message, request) { | ||
function DownloadException(message, request) { | ||
var _this; | ||
_classCallCheck(this, downloadException); | ||
_classCallCheck(this, DownloadException); | ||
_this = _super.call(this, "Downloader error: ".concat(message)); | ||
_this.request = request; | ||
_this.name = 'downloadException'; | ||
_this.name = 'DownloadException'; | ||
return _this; | ||
} | ||
return downloadException; | ||
return DownloadException; | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
; | ||
/** | ||
* @deprecated use DownloadException instead, it will be removed in next releases! | ||
*/ | ||
var downloadException = DownloadException; | ||
/***/ }), | ||
@@ -169,3 +175,3 @@ | ||
/*! | ||
* JS File Downloader v 1.1.18 | ||
* JS File Downloader v 1.1.19 | ||
* https://github.com/AleeeKoi/js-file-downloader | ||
@@ -246,3 +252,3 @@ * | ||
if (!this.params.url) { | ||
return reject('Downloader error: url param not defined!'); | ||
return reject(new _exception__WEBPACK_IMPORTED_MODULE_0__["DownloadException"]('url param not defined!', this.request)); | ||
} | ||
@@ -252,4 +258,3 @@ | ||
if (parseInt(_this2.request.status, 10) !== 200) { | ||
// eslint-disable-next-line new-cap | ||
return reject(new _exception__WEBPACK_IMPORTED_MODULE_0__["downloadException"]("status code [".concat(_this2.request.status, "]"), _this2.request)); | ||
return reject(new _exception__WEBPACK_IMPORTED_MODULE_0__["DownloadException"]("status code [".concat(_this2.request.status, "]"), _this2.request)); | ||
} | ||
@@ -263,7 +268,7 @@ | ||
this.request.ontimeout = function () { | ||
reject(new Error('Downloader error: request timeout')); | ||
reject(new _exception__WEBPACK_IMPORTED_MODULE_0__["DownloadException"]('request timeout', _this2.request)); | ||
}; | ||
this.request.onerror = function (e) { | ||
reject(e); | ||
this.request.onerror = function () { | ||
reject(new _exception__WEBPACK_IMPORTED_MODULE_0__["DownloadException"]('network error', _this2.request)); | ||
}; | ||
@@ -270,0 +275,0 @@ |
@@ -1,4 +0,4 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.jsFileDownloader=t():e.jsFileDownloader=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return a(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)})(e)}function a(e,t,n){return(a=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&s(o,n.prototype),o}).apply(null,arguments)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.r(t);var l=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(i,e);var t,n,r=(t=i,n=u(),function(){var e,r=c(t);if(n){var i=c(this).constructor;e=Reflect.construct(r,arguments,i)}else e=r.apply(this,arguments);return o(this,e)});function i(e,t){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(n=r.call(this,"Downloader error: ".concat(e))).request=t,n.name="downloadException",n}return i}(i(Error)); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.jsFileDownloader=t():e.jsFileDownloader=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return a(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)})(e)}function a(e,t,n){return(a=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&s(o,n.prototype),o}).apply(null,arguments)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function s(e,t){return(s=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.r(t);var l=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&s(e,t)}(i,e);var t,n,r=(t=i,n=u(),function(){var e,r=c(t);if(n){var i=c(this).constructor;e=Reflect.construct(r,arguments,i)}else e=r.apply(this,arguments);return o(this,e)});function i(e,t){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(n=r.call(this,"Downloader error: ".concat(e))).request=t,n.name="DownloadException",n}return i}(i(Error)); | ||
/*! | ||
* JS File Downloader v 1.1.18 | ||
* JS File Downloader v 1.1.19 | ||
* https://github.com/AleeeKoi/js-file-downloader | ||
@@ -10,3 +10,3 @@ * | ||
*/ | ||
function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var d={timeout:4e4,headers:[],forceDesktopMode:!1,autoStart:!0,withCredentials:!1,method:"GET",nameCallback:function(e){return e}},h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return f(this,e),this.params=Object.assign({},d,t),this.link=this.createLink(),this.request=null,this.params.autoStart?this.downloadFile():this}var t,n,r;return t=e,(n=[{key:"start",value:function(){return this.downloadFile()}},{key:"downloadFile",value:function(){var e=this;return new Promise((function(t,n){e.initDonwload(t,n)}))}},{key:"initDonwload",value:function(e,t){var n=this;return!("download"in this.link)||this.isMobile()?(this.link.target="_blank",this.link.href=this.params.url,this.clickLink(),e()):(this.request=this.createRequest(),this.params.url?(this.request.onload=function(){return 200!==parseInt(n.request.status,10)?t(new l("status code [".concat(n.request.status,"]"),n.request)):(n.startDownload(),e(n))},this.request.ontimeout=function(){t(new Error("Downloader error: request timeout"))},this.request.onerror=function(e){t(e)},this.request.send(),this):t("Downloader error: url param not defined!"))}},{key:"isMobile",value:function(){return!this.params.forceDesktopMode&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"createRequest",value:function(){var e=new XMLHttpRequest;return e.open(this.params.method,this.params.url,!0),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),this.params.headers.forEach((function(t){e.setRequestHeader(t.name,t.value)})),e.responseType="arraybuffer",this.params.process&&"function"==typeof this.params.process&&e.addEventListener("progress",this.params.process),e.timeout=this.params.timeout,e.withCredentials=!!this.params.withCredentials||!!this.params.includeCredentials,e}},{key:"getFileName",value:function(){if("string"==typeof this.params.filename)return this.params.filename;var e=this.request.getResponseHeader("Content-Disposition"),t=[];e&&(t=e.replace(/["']/g,"").match(/filename\*?=([^;]+)/));var n=t&&t.length>=1?t[1]:this.params.url.split("/").pop().split("?")[0];return this.params.nameCallback(n)}},{key:"createLink",value:function(){var e=document.createElement("a");return e.style.display="none",e}},{key:"clickLink",value:function(){var e;try{e=new MouseEvent("click")}catch(t){(e=document.createEvent("MouseEvent")).initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}this.link.dispatchEvent(e)}},{key:"getFile",value:function(e,t){var n=null,r={type:"application/octet-stream"};try{n=new File([e],t,r)}catch(o){(n=new Blob([e],r)).name=t,n.lastModifiedDate=new Date}return n}},{key:"startDownload",value:function(){var e=this.getFileName(),t=this.getFile(this.request.response,e);if("msSaveOrOpenBlob"in window.navigator)return window.navigator.msSaveOrOpenBlob(t,e);var n=window.URL.createObjectURL(t);return this.link.href=n,this.link.download=e,this.clickLink(),setTimeout((function(){(window.URL||window.webkitURL||window).revokeObjectURL(n)}),4e4),this}}])&&p(t.prototype,n),r&&p(t,r),e}();t.default=h}]).default})); | ||
function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var d={timeout:4e4,headers:[],forceDesktopMode:!1,autoStart:!0,withCredentials:!1,method:"GET",nameCallback:function(e){return e}},h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return f(this,e),this.params=Object.assign({},d,t),this.link=this.createLink(),this.request=null,this.params.autoStart?this.downloadFile():this}var t,n,r;return t=e,(n=[{key:"start",value:function(){return this.downloadFile()}},{key:"downloadFile",value:function(){var e=this;return new Promise((function(t,n){e.initDonwload(t,n)}))}},{key:"initDonwload",value:function(e,t){var n=this;return!("download"in this.link)||this.isMobile()?(this.link.target="_blank",this.link.href=this.params.url,this.clickLink(),e()):(this.request=this.createRequest(),this.params.url?(this.request.onload=function(){return 200!==parseInt(n.request.status,10)?t(new l("status code [".concat(n.request.status,"]"),n.request)):(n.startDownload(),e(n))},this.request.ontimeout=function(){t(new l("request timeout",n.request))},this.request.onerror=function(){t(new l("network error",n.request))},this.request.send(),this):t(new l("url param not defined!",this.request)))}},{key:"isMobile",value:function(){return!this.params.forceDesktopMode&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}},{key:"createRequest",value:function(){var e=new XMLHttpRequest;return e.open(this.params.method,this.params.url,!0),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),this.params.headers.forEach((function(t){e.setRequestHeader(t.name,t.value)})),e.responseType="arraybuffer",this.params.process&&"function"==typeof this.params.process&&e.addEventListener("progress",this.params.process),e.timeout=this.params.timeout,e.withCredentials=!!this.params.withCredentials||!!this.params.includeCredentials,e}},{key:"getFileName",value:function(){if("string"==typeof this.params.filename)return this.params.filename;var e=this.request.getResponseHeader("Content-Disposition"),t=[];e&&(t=e.replace(/["']/g,"").match(/filename\*?=([^;]+)/));var n=t&&t.length>=1?t[1]:this.params.url.split("/").pop().split("?")[0];return this.params.nameCallback(n)}},{key:"createLink",value:function(){var e=document.createElement("a");return e.style.display="none",e}},{key:"clickLink",value:function(){var e;try{e=new MouseEvent("click")}catch(t){(e=document.createEvent("MouseEvent")).initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)}this.link.dispatchEvent(e)}},{key:"getFile",value:function(e,t){var n=null,r={type:"application/octet-stream"};try{n=new File([e],t,r)}catch(o){(n=new Blob([e],r)).name=t,n.lastModifiedDate=new Date}return n}},{key:"startDownload",value:function(){var e=this.getFileName(),t=this.getFile(this.request.response,e);if("msSaveOrOpenBlob"in window.navigator)return window.navigator.msSaveOrOpenBlob(t,e);var n=window.URL.createObjectURL(t);return this.link.href=n,this.link.download=e,this.clickLink(),setTimeout((function(){(window.URL||window.webkitURL||window).revokeObjectURL(n)}),4e4),this}}])&&p(t.prototype,n),r&&p(t,r),e}();t.default=h}]).default})); | ||
//# sourceMappingURL=js-file-downloader.min.js.map |
{ | ||
"name": "js-file-downloader", | ||
"version": "1.1.18", | ||
"version": "1.1.19", | ||
"description": "Small lib for a cool download experience", | ||
@@ -33,6 +33,6 @@ "main": "dist/js-file-downloader.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.13.10", | ||
"@babel/core": "^7.13.10", | ||
"@babel/preset-env": "^7.13.10", | ||
"@babel/register": "^7.13.8", | ||
"@babel/cli": "^7.13.14", | ||
"@babel/core": "^7.13.15", | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/register": "^7.13.14", | ||
"babel-eslint": "^10.1.0", | ||
@@ -39,0 +39,0 @@ "babel-loader": "^8.2.2", |
@@ -1,7 +0,12 @@ | ||
export class downloadException extends Error { | ||
export class DownloadException extends Error { | ||
constructor (message, request) { | ||
super(`Downloader error: ${message}`); | ||
this.request = request; | ||
this.name = 'downloadException'; | ||
this.name = 'DownloadException'; | ||
} | ||
}; | ||
/** | ||
* @deprecated use DownloadException instead, it will be removed in next releases! | ||
*/ | ||
export const downloadException = DownloadException; |
@@ -12,3 +12,3 @@ /*! | ||
import { downloadException } from './exception'; | ||
import { DownloadException } from './exception'; | ||
@@ -64,3 +64,3 @@ const DEFAULT_PARAMS = { | ||
if (!this.params.url) { | ||
return reject('Downloader error: url param not defined!'); | ||
return reject(new DownloadException('url param not defined!', this.request)); | ||
} | ||
@@ -70,4 +70,3 @@ | ||
if (parseInt(this.request.status, 10) !== 200) { | ||
// eslint-disable-next-line new-cap | ||
return reject(new downloadException(`status code [${this.request.status}]`, this.request)); | ||
return reject(new DownloadException(`status code [${this.request.status}]`, this.request)); | ||
} | ||
@@ -79,7 +78,7 @@ this.startDownload(); | ||
this.request.ontimeout = () => { | ||
reject(new Error('Downloader error: request timeout')); | ||
reject(new DownloadException('request timeout', this.request)); | ||
}; | ||
this.request.onerror = (e) => { | ||
reject(e); | ||
this.request.onerror = () => { | ||
reject(new DownloadException('network error', this.request)); | ||
}; | ||
@@ -86,0 +85,0 @@ |
@@ -106,3 +106,3 @@ import chai from 'chai'; | ||
e.name.should.be.a('string'); | ||
e.name.should.be.equal('downloadException'); | ||
e.name.should.be.equal('DownloadException'); | ||
e.message.should.be.a('string'); | ||
@@ -109,0 +109,0 @@ e.request.should.be.a('XMLHttpRequest'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86234
690