object-to-formdata
Advanced tools
Comparing version 4.4.2 to 4.5.0
{ | ||
"name": "object-to-formdata", | ||
"version": "4.4.2", | ||
"version": "4.5.0", | ||
"keywords": [ | ||
@@ -15,3 +15,3 @@ "form", | ||
"author": "Parmesh Krishen", | ||
"main": "src", | ||
"main": "src/index.js", | ||
"types": "types.d.ts", | ||
@@ -32,6 +32,6 @@ "scripts": { | ||
"jest": "^27.4.7", | ||
"prettier": "^2.5.1", | ||
"prettier": "^2.8.1", | ||
"pretty-quick": "^3.1.3", | ||
"pro-commit": "^1.2.2" | ||
"pro-commit": "^1.2.3" | ||
} | ||
} |
@@ -56,2 +56,8 @@ # object-to-formdata | ||
/** | ||
* don't include array notation in FormData keys for any Attributes excepted Files in arrays | ||
* defaults to false | ||
*/ | ||
noAttributesWithArrayNotation: false, | ||
/** | ||
* don't include array notation in FormData keys for Files in arrays | ||
@@ -58,0 +64,0 @@ * defaults to false |
@@ -54,2 +54,5 @@ function isUndefined(value) { | ||
cfg.allowEmptyArrays = initCfg(cfg.allowEmptyArrays); | ||
cfg.noAttributesWithArrayNotation = initCfg( | ||
cfg.noAttributesWithArrayNotation, | ||
); | ||
cfg.noFilesWithArrayNotation = initCfg(cfg.noFilesWithArrayNotation); | ||
@@ -77,3 +80,6 @@ cfg.dotsForObjectNotation = initCfg(cfg.dotsForObjectNotation); | ||
if (cfg.noFilesWithArrayNotation && isFile(value, isReactNative)) { | ||
if ( | ||
cfg.noAttributesWithArrayNotation || | ||
(cfg.noFilesWithArrayNotation && isFile(value, isReactNative)) | ||
) { | ||
key = pre; | ||
@@ -85,3 +91,3 @@ } | ||
} else if (cfg.allowEmptyArrays) { | ||
fd.append(pre + '[]', ''); | ||
fd.append(cfg.noAttributesWithArrayNotation ? pre : pre + '[]', ''); | ||
} | ||
@@ -88,0 +94,0 @@ } else if (isDate(obj)) { |
@@ -207,2 +207,18 @@ const { serialize } = require('.'); | ||
test('Array with noAttributesWithArrayNotation option', () => { | ||
const formData = serialize( | ||
{ | ||
foo: ['bar', 'baz'], | ||
}, | ||
{ | ||
noAttributesWithArrayNotation: true, | ||
}, | ||
); | ||
expect(formData.append).toHaveBeenCalledTimes(2); | ||
expect(formData.append).toHaveBeenNthCalledWith(1, 'foo', 'bar'); | ||
expect(formData.append).toHaveBeenNthCalledWith(2, 'foo', 'baz'); | ||
expect(formData.getAll('foo')).toEqual(['bar', 'baz']); | ||
}); | ||
test('empty Array', () => { | ||
@@ -228,2 +244,18 @@ const formData = serialize({ | ||
test('Array in Array with noAttributesWithArrayNotation option', () => { | ||
const formData = serialize( | ||
{ | ||
foo: [[['bar', 'baz']]], | ||
}, | ||
{ | ||
noAttributesWithArrayNotation: true, | ||
}, | ||
); | ||
expect(formData.append).toHaveBeenCalledTimes(2); | ||
expect(formData.append).toHaveBeenNthCalledWith(1, 'foo', 'bar'); | ||
expect(formData.append).toHaveBeenNthCalledWith(2, 'foo', 'baz'); | ||
expect(formData.getAll('foo')).toEqual(['bar', 'baz']); | ||
}); | ||
test('Array in Object', () => { | ||
@@ -270,2 +302,19 @@ const formData = serialize({ | ||
test('Array with indices and noAttributesWithArrayNotation option', () => { | ||
const formData = serialize( | ||
{ | ||
foo: ['bar', 'baz'], | ||
}, | ||
{ | ||
indices: true, | ||
noAttributesWithArrayNotation: true, | ||
}, | ||
); | ||
expect(formData.append).toHaveBeenCalledTimes(2); | ||
expect(formData.append).toHaveBeenNthCalledWith(1, 'foo', 'bar'); | ||
expect(formData.append).toHaveBeenNthCalledWith(2, 'foo', 'baz'); | ||
expect(formData.get('foo')).toBe('bar'); | ||
}); | ||
test('Array with allowEmptyArrays option', () => { | ||
@@ -272,0 +321,0 @@ const formData = serialize( |
@@ -6,2 +6,3 @@ export type Options = { | ||
allowEmptyArrays?: boolean; | ||
noAttributesWithArrayNotation?: boolean; | ||
noFilesWithArrayNotation?: boolean; | ||
@@ -8,0 +9,0 @@ dotsForObjectNotation?: boolean; |
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
17670
455
83