Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

ponyfills.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module.exports = function init(global) {
  2. var interface = { FormData: FormData };
  3. // expose all constructor functions for testing purposes
  4. if (init.debug) {
  5. interface.Iterator = Iterator;
  6. }
  7. function FormData() {
  8. this.__items = [];
  9. }
  10. FormData.prototype.append = function(name, value, filename) {
  11. if (global.File && value instanceof global.File) {
  12. // nothing to do
  13. } else if (global.Blob && value instanceof global.Blob) {
  14. // mimic File instance by adding missing properties
  15. value.lastModifiedDate = new Date();
  16. value.name = filename !== undefined ? filename : 'blob';
  17. } else {
  18. value = String(value);
  19. }
  20. this.__items.push([ name, value ]);
  21. };
  22. FormData.prototype.entries = function() {
  23. return new Iterator(this.__items);
  24. };
  25. function Iterator(items) {
  26. this.__items = items;
  27. this.__position = -1;
  28. }
  29. Iterator.prototype.next = function() {
  30. this.__position += 1;
  31. if (this.__position < this.__items.length) {
  32. return { done: false, value: this.__items[this.__position] };
  33. }
  34. return { done: true, value: undefined };
  35. }
  36. return interface;
  37. };