* @param {FormData} formData * @returns {Object}
(formData)
| 3968 | * @returns {Object} |
| 3969 | */ |
| 3970 | function formDataProxy(formData) { |
| 3971 | return new Proxy(formData, { |
| 3972 | get: function(target, name) { |
| 3973 | if (typeof name === 'symbol') { |
| 3974 | // Forward symbol calls to the FormData itself directly |
| 3975 | return Reflect.get(target, name) |
| 3976 | } |
| 3977 | if (name === 'toJSON') { |
| 3978 | // Support JSON.stringify call on proxy |
| 3979 | return () => Object.fromEntries(formData) |
| 3980 | } |
| 3981 | if (name in target) { |
| 3982 | // Wrap in function with apply to correctly bind the FormData context, as a direct call would result in an illegal invocation error |
| 3983 | if (typeof target[name] === 'function') { |
| 3984 | return function() { |
| 3985 | return formData[name].apply(formData, arguments) |
| 3986 | } |
| 3987 | } else { |
| 3988 | return target[name] |
| 3989 | } |
| 3990 | } |
| 3991 | const array = formData.getAll(name) |
| 3992 | // Those 2 undefined & single value returns are for retro-compatibility as we weren't using FormData before |
| 3993 | if (array.length === 0) { |
| 3994 | return undefined |
| 3995 | } else if (array.length === 1) { |
| 3996 | return array[0] |
| 3997 | } else { |
| 3998 | return formDataArrayProxy(target, name, array) |
| 3999 | } |
| 4000 | }, |
| 4001 | set: function(target, name, value) { |
| 4002 | if (typeof name !== 'string') { |
| 4003 | return false |
| 4004 | } |
| 4005 | target.delete(name) |
| 4006 | if (typeof value.forEach === 'function') { |
| 4007 | value.forEach(function(v) { target.append(name, v) }) |
| 4008 | } else { |
| 4009 | target.append(name, value) |
| 4010 | } |
| 4011 | return true |
| 4012 | }, |
| 4013 | deleteProperty: function(target, name) { |
| 4014 | if (typeof name === 'string') { |
| 4015 | target.delete(name) |
| 4016 | } |
| 4017 | return true |
| 4018 | }, |
| 4019 | // Support Object.assign call from proxy |
| 4020 | ownKeys: function(target) { |
| 4021 | return Reflect.ownKeys(Object.fromEntries(target)) |
| 4022 | }, |
| 4023 | getOwnPropertyDescriptor: function(target, prop) { |
| 4024 | return Reflect.getOwnPropertyDescriptor(Object.fromEntries(target), prop) |
| 4025 | } |
| 4026 | }) |
| 4027 | } |
no test coverage detected
searching dependent graphs…