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 4.4.2 to 4.5.0

8

package.json
{
"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;

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