forked from jimmywarting/FormData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formdata.min.js
17 lines (17 loc) · 6.03 KB
/
formdata.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var f,h="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)},l="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function n(){n=function(){};l.Symbol||(l.Symbol=p)}var q=0;function p(a){return"jscomp_symbol_"+(a||"")+q++}
function t(){n();var a=l.Symbol.iterator;a||(a=l.Symbol.iterator=l.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&h(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return u(this)}});t=function(){}}function u(a){var b=0;return v(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})}function v(a){t();a={next:a};a[l.Symbol.iterator]=function(){return this};return a}function w(a){t();n();t();var b=a[Symbol.iterator];return b?b.call(a):u(a)}
function y(a){for(var b,d=[];!(b=a.next()).done;)d.push(b.value);return d}var z=new WeakMap;n();window.Symbol&&Symbol.toStringTag&&(n(),Blob.prototype[Symbol.toStringTag]||(n(),Blob.prototype[Symbol.toStringTag]="Blob"),n(),"File"in window&&!File.prototype[Symbol.toStringTag]&&(n(),File.prototype[Symbol.toStringTag]="File"));
try{new File([],"")}catch(a){window.File=function(b,d,c){b=new Blob(b,c);c=c&&void 0!==c.lastModified?new Date(c.lastModified):new Date;Object.defineProperties(b,{name:{value:d},lastModifiedDate:{value:c},lastModified:{value:+c},toString:{value:function(){return"[object File]"}}});n();window.Symbol&&Symbol.toStringTag&&(n(),Object.defineProperty(b,Symbol.toStringTag,{value:"File"}));return b}}
function A(a){var b=w(a);a=b.next().value;b=b.next().value;a instanceof Blob&&(a=new File([a],b,{type:a.type,lastModified:a.lastModified}));return a}function C(a){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");return[a+""]}
function D(a,b,d){if(2>arguments.length)throw new TypeError("2 arguments required, but only "+arguments.length+" present.");return b instanceof Blob?[a+"",b,void 0!==d?d+"":"File"===Object.prototype.toString.call(b).slice(8,-1)?b.name:"Blob"]:[a+"",b+""]}
function E(a){z.set(this,Object.create(null));if(!a)return this;a=w(Array.from(a.elements));for(var b=a.next();!b.done;b=a.next()){var d=b.value,b=d.name,c=d.type,e=d.value,g=d.files,k=d.checked,d=d.selectedOptions;if(b)if("file"===c)for(c=w(g),e=c.next();!e.done;e=c.next())this.append(b,e.value);else if("select-multiple"===c||"select-one"===c)for(c=w(Array.from(d)),e=c.next();!e.done;e=c.next())this.append(b,e.value.value);else"checkbox"===c||'radio'===c?k&&this.append(b,e):this.append(b,e)}}f=E.prototype;
f.append=function(a,b,d){var c=z.get(this);c[a]||(c[a]=[]);c[a].push([b,d])};f["delete"]=function(a){delete z.get(this)[a]};
f.entries=function(){function a(a){for(;;)switch(b){case 0:x=z.get(K);m=[];k=x;for(g in k)m.push(g);r=0;case 1:if(!(r<m.length)){b=3;break}g=m[r];if(g in k){b=4;break}b=2;break;case 4:e=w(x[g]),c=e.next();case 5:if(c.done){b=7;break}d=c.value;b=8;return{value:[g,A(d)],done:!1};case 8:if(void 0===a){b=9;break}b=-1;throw a;case 9:case 6:c=e.next();b=5;break;case 7:case 2:r++;b=1;break;case 3:b=-1;default:return{value:void 0,done:!0}}}var b=0,d,c,e,g,k,r,m,x,K=this,B={next:function(){return a(void 0)},
"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();B[Symbol.iterator]=function(){return this};return B};f.forEach=function(a,b){for(var d=w(this),c=d.next();!c.done;c=d.next()){var e=w(c.value),c=e.next().value,e=e.next().value;a.call(b,e,c,this)}};f.get=function(a){var b=z.get(this);return b[a]?A(b[a][0]):null};f.getAll=function(a){return(z.get(this)[a]||[]).map(A)};f.has=function(a){return a in z.get(this)};
f.keys=function(){function a(a){for(;;)switch(b){case 0:k=w(r),g=k.next();case 1:if(g.done){b=3;break}e=g.value;c=w(e);d=c.next().value;b=4;return{value:d,done:!1};case 4:if(void 0===a){b=5;break}b=-1;throw a;case 5:case 2:g=k.next();b=1;break;case 3:b=-1;default:return{value:void 0,done:!0}}}var b=0,d,c,e,g,k,r=this,m={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();m[Symbol.iterator]=function(){return this};return m};
f.set=function(a,b,d){z.get(this)[a]=[[b,d]]};
f.values=function(){function a(a){for(;;)switch(b){case 0:k=w(r),g=k.next();case 1:if(g.done){b=3;break}e=g.value;c=w(e);c.next();d=c.next().value;b=4;return{value:d,done:!1};case 4:if(void 0===a){b=5;break}b=-1;throw a;case 5:case 2:g=k.next();b=1;break;case 3:b=-1;default:return{value:void 0,done:!0}}}var b=0,d,c,e,g,k,r=this,m={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();m[Symbol.iterator]=function(){return this};
return m};f.stream=function(){try{return this._blob().stream()}catch(a){throw Error("Include https://github.com/jimmywarting/Screw-FileReader for streaming support");}};E.prototype._asNative=function(){for(var a=new FormData,b=w(this),d=b.next();!d.done;d=b.next()){var c=w(d.value),d=c.next().value,c=c.next().value;a.append(d,c)}return a};
E.prototype._blob=function(){for(var a="----formdata-polyfill-"+Math.random(),b=[],d=w(this),c=d.next();!c.done;c=d.next()){var e=w(c.value),c=e.next().value,e=e.next().value;b.push("--"+a+"\r\n");e instanceof Blob?b.push('Content-Disposition: form-data; name="'+c+'"; filename="'+e.name+'"\r\n',"Content-Type: "+e.type+"\r\n\r\n",e,"\r\n"):b.push('Content-Disposition: form-data; name="'+c+'"\r\n\r\n'+e+"\r\n")}b.push("--"+a+"--");return new Blob(b,{type:"multipart/form-data; boundary="+a})};n();t();
E.prototype[Symbol.iterator]=function(){return this.entries()};E.prototype.toString=function(){return"[object FormData]"};n();window.Symbol&&Symbol.toStringTag&&(n(),E.prototype[Symbol.toStringTag]="FormData");
for(var F={},G=w([["append",D],["delete",C],["get",C],["getAll",C],["has",C],["set",D]]),H=G.next();!H.done;F={a:F.a,b:F.b},H=G.next()){var I=w(H.value),J=I.next().value;F.b=I.next().value;F.a=E.prototype[J];E.prototype[J]=function(a){return function(){return a.a.apply(this,a.b.apply(null,[].concat(arguments instanceof Array?arguments:y(w(arguments)))))}}(F)}module.exports=E;