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

nested-formdata

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nested-formdata - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

32

dist/nested-formdata.cjs.development.js

@@ -5,22 +5,22 @@ 'use strict';

var lodash = require('lodash');
function objectToFormData(obj, form, namespace) {
var formData = form || new FormData();
var isArr = lodash.isArray(obj);
var isArr = Array.isArray(obj);
for (var key in obj) {
var property = obj[key];
if (!obj.hasOwnProperty(key) || !property) {
continue;
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var property = obj[key];
if (!property) {
continue;
}
var formKey = namespace ? isArr ? namespace : namespace + "[" + key + "]" : key;
if (property instanceof Date) {
formData.append(formKey, property.toISOString());
} else if (property instanceof File) {
formData.append(formKey, property);
} else if (typeof property !== 'object') {
formData.append(formKey, property.toString());
} else {
objectToFormData(property, formData, formKey);
}
}
var formKey = namespace ? isArr ? namespace : namespace + "[" + key + "]" : key;
if (lodash.isDate(property)) {
formData.append(key, property.toISOString());
} else if (property instanceof File) {
formData.append(formKey, property);
} else if (!lodash.isObject(property)) {
formData.append(formKey, property.toString());
} else if (lodash.isObject(property)) {
objectToFormData(property, formData, key);
}
}

@@ -27,0 +27,0 @@ return formData;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash");exports.objectToFormData=function r(t,a,o){var i=a||new FormData,n=e.isArray(t);for(var s in t){var p=t[s];if(t.hasOwnProperty(s)&&p){var c=o?n?o:o+"["+s+"]":s;e.isDate(p)?i.append(s,p.toISOString()):p instanceof File?i.append(c,p):e.isObject(p)?e.isObject(p)&&r(p,i,s):i.append(c,p.toString())}}return i};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.objectToFormData=function e(t,r,o){var a=r||new FormData,n=Array.isArray(t);for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var p=t[i];if(!p)continue;var c=o?n?o:o+"["+i+"]":i;p instanceof Date?a.append(c,p.toISOString()):p instanceof File?a.append(c,p):"object"!=typeof p?a.append(c,p.toString()):e(p,a,c)}return a};
//# sourceMappingURL=nested-formdata.cjs.production.min.js.map

@@ -1,21 +0,21 @@

import { isArray, isDate, isObject } from 'lodash-es';
function objectToFormData(obj, form, namespace) {
var formData = form || new FormData();
var isArr = isArray(obj);
var isArr = Array.isArray(obj);
for (var key in obj) {
var property = obj[key];
if (!obj.hasOwnProperty(key) || !property) {
continue;
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var property = obj[key];
if (!property) {
continue;
}
var formKey = namespace ? isArr ? namespace : namespace + "[" + key + "]" : key;
if (property instanceof Date) {
formData.append(formKey, property.toISOString());
} else if (property instanceof File) {
formData.append(formKey, property);
} else if (typeof property !== 'object') {
formData.append(formKey, property.toString());
} else {
objectToFormData(property, formData, formKey);
}
}
var formKey = namespace ? isArr ? namespace : namespace + "[" + key + "]" : key;
if (isDate(property)) {
formData.append(key, property.toISOString());
} else if (property instanceof File) {
formData.append(formKey, property);
} else if (!isObject(property)) {
formData.append(formKey, property.toString());
} else if (isObject(property)) {
objectToFormData(property, formData, key);
}
}

@@ -22,0 +22,0 @@ return formData;

{
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",

@@ -61,4 +61,3 @@ "main": "dist/index.js",

"dependencies": {
"lodash": "^4.17.21"
}
}

@@ -1,40 +0,40 @@

import { isArray, isDate, isObject } from 'lodash'
type BasicType = string | boolean | number | File | undefined | null;
type BasicType = string | boolean | number | File | undefined | null
type DataObj<T> =
| BasicType[]
| {
[P in keyof T]: BasicType | BasicType[] | Partial<DataObj<T>>
}
| BasicType[]
| {
[P in keyof T]: BasicType | BasicType[] | Partial<DataObj<T>>;
};
export function objectToFormData<
T extends {
[key: string | number]: unknown
}
T extends {
[key: string | number]: unknown;
}
>(obj: DataObj<T> | Partial<T>, form?: FormData, namespace?: string): FormData {
const formData = form || new FormData()
const formData = form || new FormData();
const isArr = isArray(obj)
const isArr = Array.isArray(obj);
for (const key in obj) {
const property = obj[key]
if (!obj.hasOwnProperty(key) || !property) {
continue
}
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
const property = obj[key];
if (!property) {
continue;
}
const formKey = namespace ? (isArr ? namespace : `${namespace}[${key}]`) : key
const formKey = namespace ? (isArr ? namespace : `${namespace}[${key}]`) : key;
if (isDate(property)) {
formData.append(key, property.toISOString())
} else if (property instanceof File) {
formData.append(formKey, property)
} else if (!isObject(property)) {
formData.append(formKey, property.toString())
} else if (isObject(property)) {
objectToFormData(property, formData, key)
}
}
if (property instanceof Date) {
formData.append(formKey, property.toISOString());
} else if (property instanceof File) {
formData.append(formKey, property);
} else if (typeof property !== 'object') {
formData.append(formKey, property.toString());
} else {
objectToFormData(property, formData, formKey);
}
}
}
return formData
}
return formData;
}

Sorry, the diff of this file is not supported yet

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