formdata-polyfill
Advanced tools
Comparing version 2.0.0 to 2.0.1
const map = new WeakMap | ||
const wm = o => map.get(o) | ||
var Fil | ||
let type = obj => Object.prototype.toString.call(obj).slice(8, -1) | ||
try { | ||
new File([], '') | ||
Fil = File | ||
} catch(e) { | ||
/** | ||
* @see http://www.w3.org/TR/FileAPI/#dfn-file | ||
* @param {!Array<string|!Blob|!ArrayBuffer>=} chunks | ||
* @param {string=} filename | ||
* @param {{type: (string|undefined), lastModified: (number|undefined)}=} | ||
* opts | ||
* @constructor | ||
* @extends {Blob} | ||
*/ | ||
Fil = function File(chunks, filename, opts) { | ||
var _this = new Blob(chunks, opts) | ||
var modified = opts && opts.lastModified !== undefined ? new Date(opts.lastModified) : new Date | ||
Object.defineProperties(_this, { | ||
name: { | ||
value: filename | ||
}, | ||
lastModifiedDate: { | ||
value: modified | ||
}, | ||
lastModified: { | ||
value: +modified | ||
}, | ||
toString: { | ||
value() { | ||
return '[object File]' | ||
} | ||
} | ||
}) | ||
Object.defineProperty(_this, Symbol.toStringTag, { | ||
value: 'File' | ||
}) | ||
return _this | ||
} | ||
} | ||
function normalizeValue([value, filename]) { | ||
if (value instanceof Blob) | ||
value = new File([value], filename, { | ||
value = new Fil([value], filename, { | ||
type: value.type, | ||
@@ -28,3 +72,3 @@ lastModified: value.lastModified | ||
? filename + '' | ||
: value[Symbol.toStringTag] === 'File' | ||
: type(value) === 'File' | ||
? value.name | ||
@@ -234,3 +278,3 @@ : 'Blob'] | ||
if (value[Symbol.toStringTag] === 'File') { | ||
if (value instanceof Blob) { | ||
chunks.push( | ||
@@ -268,11 +312,19 @@ `Content-Disposition: form-data; name="${name}"; filename="${value.name}"\r\n`, | ||
* Create the default string description. | ||
* It is accessed internally by the Object.prototype.toString(). | ||
* | ||
* @return {String} FormData | ||
* @return {String} [object FormData] | ||
*/ | ||
get [Symbol.toStringTag]() { | ||
return 'FormData' | ||
toString() { | ||
return '[object FormData]' | ||
} | ||
} | ||
/** | ||
* Create the default string description. | ||
* It is accessed internally by the Object.prototype.toString(). | ||
* | ||
* @return {String} FormData | ||
*/ | ||
FormDataPolyfill.prototype[Symbol.toStringTag] = 'FormData' | ||
for (let [method, overide] of [ | ||
@@ -279,0 +331,0 @@ ['append', normalizeArgs], |
@@ -1,15 +0,16 @@ | ||
var f,h="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)},m="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function n(){n=function(){};m.Symbol||(m.Symbol=p)}var q=0;function p(a){return"jscomp_symbol_"+(a||"")+q++} | ||
var f,h="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)},m="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function n(){n=function(){};m.Symbol||(m.Symbol=p)}var r=0;function p(a){return"jscomp_symbol_"+(a||"")+r++} | ||
function t(){n();var a=m.Symbol.iterator;a||(a=m.Symbol.iterator=m.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[m.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;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.");n();return b instanceof Blob?[a+"",b,void 0!==d?d+"":"File"===b[Symbol.toStringTag]?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,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&&this.append(b,e)}}n();f=E.prototype; | ||
function x(a){for(var b,d=[];!(b=a.next()).done;)d.push(b.value);return d}var z=new WeakMap,A;try{new File([],""),A=File}catch(a){A=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();Object.defineProperty(b,Symbol.toStringTag,{value:"File"});return b}} | ||
function B(a){var b=w(a);a=b.next().value;b=b.next().value;a instanceof Blob&&(a=new A([a],b,{type:a.type,lastModified:a.lastModified}));return a}function D(a){if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");return[a+""]} | ||
function E(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 F(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,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&&this.append(b,e)}}f=F.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(L);l=[];k=x;for(g in k)l.push(g);r=0;case 1:if(!(r<l.length)){b=3;break}g=l[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,l,x,L=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,l={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();l[Symbol.iterator]=function(){return this};return l}; | ||
f.entries=function(){function a(a){for(;;)switch(b){case 0:y=z.get(L);l=[];k=y;for(g in k)l.push(g);q=0;case 1:if(!(q<l.length)){b=3;break}g=l[q];if(g in k){b=4;break}b=2;break;case 4:e=w(y[g]),c=e.next();case 5:if(c.done){b=7;break}d=c.value;b=8;return{value:[g,B(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:q++;b=1;break;case 3:b=-1;default:return{value:void 0,done:!0}}}var b=0,d,c,e,g,k,q,l,y,L=this,C={next:function(){return a(void 0)}, | ||
"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();C[Symbol.iterator]=function(){return this};return C};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]?B(b[a][0]):null};f.getAll=function(a){return(z.get(this)[a]||[]).map(B)};f.has=function(a){return a in z.get(this)}; | ||
f.keys=function(){function a(a){for(;;)switch(b){case 0:k=w(q),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,q=this,l={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();l[Symbol.iterator]=function(){return this};return l}; | ||
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,l={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();l[Symbol.iterator]=function(){return this}; | ||
return l};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");n();"File"===e[Symbol.toStringTag]?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()};n();var F={};m.Object.defineProperties(E.prototype,(F[Symbol.toStringTag]={configurable:!0,enumerable:!0,get:function(){return"FormData"}},F)); | ||
for(var G={},H=w([["append",D],["delete",C],["get",C],["getAll",C],["has",C],["set",D]]),I=H.next();!I.done;G={a:G.a,b:G.b},I=H.next()){var J=w(I.value),K=J.next().value;G.b=J.next().value;G.a=E.prototype[K];E.prototype[K]=function(a){return function(){return a.a.apply(this,a.b.apply(null,[].concat(arguments instanceof Array?arguments:y(w(arguments)))))}}(G)}module.exports=E; | ||
f.values=function(){function a(a){for(;;)switch(b){case 0:k=w(q),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,q=this,l={next:function(){return a(void 0)},"throw":function(b){return a(b)},"return":function(){throw Error("Not yet implemented");}};t();l[Symbol.iterator]=function(){return this}; | ||
return l};f.stream=function(){try{return this._blob().stream()}catch(a){throw Error("Include https://github.com/jimmywarting/Screw-FileReader for streaming support");}};F.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}; | ||
F.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(); | ||
F.prototype[Symbol.iterator]=function(){return this.entries()};F.prototype.toString=function(){return"[object FormData]"};n();F.prototype[Symbol.toStringTag]="FormData"; | ||
for(var G={},H=w([["append",E],["delete",D],["get",D],["getAll",D],["has",D],["set",E]]),I=H.next();!I.done;G={a:G.a,b:G.b},I=H.next()){var J=w(I.value),K=J.next().value;G.b=J.next().value;G.a=F.prototype[K];F.prototype[K]=function(a){return function(){return a.a.apply(this,a.b.apply(null,[].concat(arguments instanceof Array?arguments:x(w(arguments)))))}}(G)}module.exports=F; |
{ | ||
"name": "formdata-polyfill", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "HTML5 `FormData` polyfill for Browsers.", | ||
@@ -5,0 +5,0 @@ "main": "formdata.min.js", |
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
17345
311