Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-to-formdata

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-to-formdata - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0

2

dist/index.js

@@ -1,2 +0,2 @@

function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(e)}var e=function(n){return void 0===n},t=function(n){return Array.isArray(n)},o=function(n){return n&&"number"==typeof n.size&&"string"==typeof n.type&&"function"==typeof n.slice};export default function i(r,f,u,s){if((f=f||{}).indices=!e(f.indices)&&f.indices,f.nullsAsUndefineds=!e(f.nullsAsUndefineds)&&f.nullsAsUndefineds,u=u||new FormData,e(r))return u;if(null===r)f.nullsAsUndefineds||u.append(s,"");else if(t(r))if(r.length)r.forEach((function(n,e){var t=s+"["+(f.indices?e:"")+"]";i(n,f,u,t)}));else{var l=s+"[]";u.append(l,"")}else!function(n){return n instanceof Date}(r)?!function(n){return n===Object(n)}(r)||function(e){return o(e)&&"string"==typeof e.name&&("object"===n(e.lastModifiedDate)||"number"==typeof e.lastModified)}(r)||o(r)?u.append(s,r):Object.keys(r).forEach((function(n){var e=r[n];if(t(e))for(;n.length>2&&n.lastIndexOf("[]")===n.length-2;)n=n.substring(0,n.length-2);i(e,f,u,s?s+"["+n+"]":n)})):u.append(s,r.toISOString());return u}
function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(e)}var e=function(n){return void 0===n},t=function(n){return Array.isArray(n)},o=function(n){return n&&"number"==typeof n.size&&"string"==typeof n.type&&"function"==typeof n.slice};export default function r(i,s,f,u){if((s=s||{}).indices=!e(s.indices)&&s.indices,s.booleansAsIntegers=!e(s.booleansAsIntegers)&&s.booleansAsIntegers,s.nullsAsUndefineds=!e(s.nullsAsUndefineds)&&s.nullsAsUndefineds,f=f||new FormData,e(i))return f;if(null===i)s.nullsAsUndefineds||f.append(u,"");else if(t(i))if(i.length)i.forEach((function(n,e){var t=u+"["+(s.indices?e:"")+"]";r(n,s,f,t)}));else{var l=u+"[]";f.append(l,"")}else!function(n){return n instanceof Date}(i)?!function(n){return"boolean"==typeof n}(i)?!function(n){return n===Object(n)}(i)||function(e){return o(e)&&"string"==typeof e.name&&("object"===n(e.lastModifiedDate)||"number"==typeof e.lastModified)}(i)||o(i)?f.append(u,i):Object.keys(i).forEach((function(n){var e=i[n];if(t(e))for(;n.length>2&&n.lastIndexOf("[]")===n.length-2;)n=n.substring(0,n.length-2);r(e,s,f,u?u+"["+n+"]":n)})):s.booleansAsIntegers?f.append(u,i?1:0):f.append(u,i):f.append(u,i.toISOString());return f}
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n=n||self).objectToFormData=e()}(this,(function(){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(e)}var e=function(n){return void 0===n},t=function(n){return Array.isArray(n)},o=function(n){return n&&"number"==typeof n.size&&"string"==typeof n.type&&"function"==typeof n.slice};return function i(f,r,u,s){if((r=r||{}).indices=!e(r.indices)&&r.indices,r.nullsAsUndefineds=!e(r.nullsAsUndefineds)&&r.nullsAsUndefineds,u=u||new FormData,e(f))return u;if(null===f)r.nullsAsUndefineds||u.append(s,"");else if(t(f))if(f.length)f.forEach((function(n,e){var t=s+"["+(r.indices?e:"")+"]";i(n,r,u,t)}));else{var c=s+"[]";u.append(c,"")}else!function(n){return n instanceof Date}(f)?!function(n){return n===Object(n)}(f)||function(e){return o(e)&&"string"==typeof e.name&&("object"===n(e.lastModifiedDate)||"number"==typeof e.lastModified)}(f)||o(f)?u.append(s,f):Object.keys(f).forEach((function(n){var e=f[n];if(t(e))for(;n.length>2&&n.lastIndexOf("[]")===n.length-2;)n=n.substring(0,n.length-2);i(e,r,u,s?s+"["+n+"]":n)})):u.append(s,f.toISOString());return u}}));
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n=n||self).objectToFormData=e()}(this,(function(){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(e)}var e=function(n){return void 0===n},t=function(n){return Array.isArray(n)},o=function(n){return n&&"number"==typeof n.size&&"string"==typeof n.type&&"function"==typeof n.slice};return function r(i,f,s,u){if((f=f||{}).indices=!e(f.indices)&&f.indices,f.booleansAsIntegers=!e(f.booleansAsIntegers)&&f.booleansAsIntegers,f.nullsAsUndefineds=!e(f.nullsAsUndefineds)&&f.nullsAsUndefineds,s=s||new FormData,e(i))return s;if(null===i)f.nullsAsUndefineds||s.append(u,"");else if(t(i))if(i.length)i.forEach((function(n,e){var t=u+"["+(f.indices?e:"")+"]";r(n,f,s,t)}));else{var l=u+"[]";s.append(l,"")}else!function(n){return n instanceof Date}(i)?!function(n){return"boolean"==typeof n}(i)?!function(n){return n===Object(n)}(i)||function(e){return o(e)&&"string"==typeof e.name&&("object"===n(e.lastModifiedDate)||"number"==typeof e.lastModified)}(i)||o(i)?s.append(u,i):Object.keys(i).forEach((function(n){var e=i[n];if(t(e))for(;n.length>2&&n.lastIndexOf("[]")===n.length-2;)n=n.substring(0,n.length-2);r(e,f,s,u?u+"["+n+"]":n)})):f.booleansAsIntegers?s.append(u,i?1:0):s.append(u,i):s.append(u,i.toISOString());return s}}));
//# sourceMappingURL=umd.js.map
{
"name": "object-to-formdata",
"version": "2.2.1",
"version": "2.3.0",
"repository": "therealparmesh/object-to-formdata",

@@ -23,4 +23,4 @@ "license": "MIT",

"devDependencies": {
"@babel/core": "7.7.7",
"@babel/preset-env": "7.7.7",
"@babel/core": "7.8.3",
"@babel/preset-env": "7.8.3",
"jest": "24.9.0",

@@ -27,0 +27,0 @@ "npm-run-all": "4.1.5",

@@ -11,2 +11,4 @@ const isUndefined = value => value === undefined

const isBoolean = value => typeof value === 'boolean'
const isBlob = value =>

@@ -27,2 +29,3 @@ value &&

cfg.indices = isUndefined(cfg.indices) ? false : cfg.indices
cfg.booleansAsIntegers = isUndefined(cfg.booleansAsIntegers) ? false : cfg.booleansAsIntegers
cfg.nullsAsUndefineds = isUndefined(cfg.nullsAsUndefineds) ? false : cfg.nullsAsUndefineds

@@ -51,2 +54,8 @@ fd = fd || new FormData()

fd.append(pre, obj.toISOString())
} else if (isBoolean(obj)) {
if (cfg.booleansAsIntegers) {
fd.append(pre, obj ? 1 : 0)
} else {
fd.append(pre, obj)
}
} else if (isObject(obj) && !isFile(obj) && !isBlob(obj)) {

@@ -53,0 +62,0 @@ Object.keys(obj).forEach(prop => {

@@ -55,3 +55,21 @@ import objectToFormData from '.'

test('number', () => {
test('boolean with booleansAsIntegers option', () => {
const formData = objectToFormData(
{
foo: true,
bar: false
},
{
booleansAsIntegers: true
}
)
expect(formData.append).toHaveBeenCalledTimes(2)
expect(formData.append).toHaveBeenNthCalledWith(1, 'foo', 1)
expect(formData.append).toHaveBeenNthCalledWith(2, 'bar', 0)
expect(formData.get('foo')).toBe('1')
expect(formData.get('bar')).toBe('0')
})
test('integer', () => {
const formData = objectToFormData({

@@ -66,2 +84,12 @@ foo: 1

test('float', () => {
const formData = objectToFormData({
foo: 1.0100
})
expect(formData.append).toHaveBeenCalledTimes(1)
expect(formData.append).toHaveBeenCalledWith('foo', 1.01)
expect(formData.get('foo')).toBe('1.01')
})
test('string', () => {

@@ -68,0 +96,0 @@ const formData = objectToFormData({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc