New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

form-data-utils

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-data-utils - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

6

declarations/index.d.ts
declare type Data = {
[key: string]: FormDataEntryValue_2[] | FormDataEntryValue_2 | string[] | number | Date | File | File[] | null;
[key: string]: FormDataEntryValue_2[] | FormDataEntryValue_2 | string[] | number | Date | File | File[] | unknown | unknown[] | null;
};

@@ -22,4 +22,8 @@

export declare function deleteValue(element: HTMLElement): boolean;
declare type FormDataEntryValue_2 = NonNullable<ReturnType<FormData['get']>>;
export declare function setValue(element: HTMLElement, value: unknown): void;
export { }

@@ -18,11 +18,11 @@ function dataFrom(event) {

const hasSubmitted = name in data;
if (!hasSubmitted)
data[name] = "";
if (!hasSubmitted && !(field instanceof HTMLButtonElement))
data[name] = null;
if (field instanceof HTMLSelectElement) {
if (field.hasAttribute("multiple")) {
data[field.name] = formData.getAll(field.name);
}
data[field.name] = getSelectValue(field);
} else if (field instanceof HTMLButtonElement && hasSubmitted) {
data[field.name] = field.value || null;
} else if (field instanceof HTMLInputElement) {
const _related = form.querySelectorAll(`[name="${name}"]`);
const related = [..._related];
const related = Array.from(_related);
if (!related.every((x) => x instanceof HTMLInputElement)) {

@@ -35,3 +35,3 @@ throw new Error(`Every element with name ${name} must be an input`);

case "range": {
data[field.name] = field.valueAsNumber;
data[field.name] = isNaN(field.valueAsNumber) ? null : field.valueAsNumber;
break;

@@ -49,6 +49,18 @@ }

if (hasMultipleValues) {
data[field.name] = related.filter((x) => x.checked).map((x) => x.value);
data[field.name] = related.filter((x) => x.checked).map((x) => getRadioCheckboxValue(x));
} else {
data[field.name] = getRadioCheckboxValue(field);
}
break;
}
case "radio": {
let radio;
if (hasMultipleValues) {
radio = related.find((x) => x.checked);
} else {
radio = field;
}
data[field.name] = radio ? getRadioCheckboxValue(radio) : null;
break;
}
case "file": {

@@ -67,5 +79,60 @@ if (field.files && field.files.length > 0) {

}
function getSelectValue(field) {
return field.multiple ? getMultipleSelectValue(field) : getSingleSelectValue(field);
}
function getSingleSelectValue(field) {
if (field.selectedIndex === -1)
return null;
let optionValue = null;
for (let opt of field.options) {
if (!opt.disabled && opt.selected) {
optionValue = getOptionValue(opt);
}
}
return optionValue;
}
function getMultipleSelectValue(field) {
if (field.selectedIndex === -1)
return [];
let optionValues = [];
for (let opt of field.options) {
if (!opt.disabled && opt.selected && opt.value !== "") {
optionValues.push(getOptionValue(opt));
}
}
return optionValues;
}
function getOptionValue(opt) {
if (!opt.disabled && opt.selected) {
if (opt.value === "")
return null;
return getValue(opt) || opt.value;
}
}
function getRadioCheckboxValue(el) {
if (el.disabled)
return;
const isValueDefined = el.getAttribute("value") !== null || getValue(el);
if (!isValueDefined)
return getValue(el) || el.checked;
if (el.checked) {
return getValue(el) || el.value;
}
return null;
}
const values = /* @__PURE__ */ new WeakMap();
function setValue(element, value) {
values.set(element, value);
}
function deleteValue(element) {
return values.delete(element);
}
function getValue(element) {
return values.get(element);
}
export {
dataFrom
dataFrom,
deleteValue,
setValue
};
//# sourceMappingURL=index.js.map

2

package.json
{
"name": "form-data-utils",
"type": "module",
"version": "0.5.0",
"version": "0.6.0",
"description": "A set of utilities for working with FormData",

@@ -6,0 +6,0 @@ "keywords": [

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