UNPKG

use-downloads

Version:

A js utilities that contains all the methods for downloading files

8 lines (7 loc) 1.14 kB
/*! * use-downloads v1.5.1 * A js utilities that contains all the methods for downloading files * (c) 2022-2023 saqqdy<https://github.com/saqqdy> * Released under the MIT License. */ this.useDownloads=function(){"use strict";function e(e,o){var n=window.URL||window.webkitURL||window,t=new Blob([e]),d=document.createElementNS("http://www.w3.org/1999/xhtml","a");d.href=n.createObjectURL(t),d.download=o,d.click()}function o(o,n){var t=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");t.open("GET",o,!0),t.responseType="blob",t.onload=function(){200===t.status&&e(t.response,n)},t.send()}function n(e,o,n){var t=document.createElement("a");t.style.display="none",t.download=o,t.href=e,document.body.appendChild(t),t.click(),document.body.removeChild(t)}return{version:"1.5.1",download:function(e,t,d){var i,l;void 0===d&&(d="download");var w=(null===(i=/[^\/]+$/.exec(e))||void 0===i?void 0:i[0])||"";null===(l=/[^\.]+$/.exec(w))||void 0===l||l[0].toLowerCase(),"open"===d?window.open(e):"href"===d?window.location.href=e:"request"===d?o(e,t||w):n(e,t||w)},downloadUrlFile:o,openFile:n,saveFile:e}}();