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

formdata-node

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formdata-node - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

@type/Blob.d.ts

12

@type/File.d.ts

@@ -1,3 +0,3 @@

import Blob from "fetch-blob";
export { Blob };
import type { ReadableStream } from "web-streams-polyfill";
import { Blob, BlobPropertyBag } from "./Blob";
export interface FileLike {

@@ -21,12 +21,8 @@ /**

[Symbol.toStringTag]: string;
stream(): {
stream(): ReadableStream | {
[Symbol.asyncIterator](): AsyncIterableIterator<Uint8Array>;
};
}
export interface FileOptions {
export interface FileOptions extends BlobPropertyBag {
/**
* Returns the media type ([`MIME`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)) of the file represented by a `File` object.
*/
type?: string;
/**
* The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.

@@ -33,0 +29,0 @@ */

@@ -14,3 +14,3 @@ /// <reference types="node" />

value: unknown;
filename?: string;
fileName?: string;
}>;

@@ -35,5 +35,5 @@ /**

or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
* @param filename The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
* @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
*/
append(name: string, value: unknown, filename?: string): void;
append(name: string, value: unknown, fileName?: string): void;
/**

@@ -46,6 +46,6 @@ * Set a new value for an existing key inside FormData,

or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
* @param filename The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
* @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
*
*/
set(name: string, value: unknown, filename?: string): void;
set(name: string, value: unknown, fileName?: string): void;
/**

@@ -52,0 +52,0 @@ * Returns the first value associated with a given key from within a `FormData` object.

export * from "./FormData";
export * from "./Blob";
export * from "./File";

@@ -13,11 +13,7 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _File_name, _File_lastModified;
Object.defineProperty(exports, "__esModule", { value: true });
exports.File = exports.Blob = void 0;
const fetch_blob_1 = __importDefault(require("fetch-blob"));
exports.Blob = fetch_blob_1.default;
class File extends fetch_blob_1.default {
exports.File = void 0;
const Blob_1 = require("./Blob");
class File extends Blob_1.Blob {
constructor(fileBits, name, options = { lastModified: Date.now() }) {

@@ -24,0 +20,0 @@ super(fileBits, options);

@@ -44,3 +44,3 @@ "use strict";

__classPrivateFieldSet(this, _FileFromPath_start, input.start || 0, "f");
this.name = path_1.basename(__classPrivateFieldGet(this, _FileFromPath_path, "f"));
this.name = (0, path_1.basename)(__classPrivateFieldGet(this, _FileFromPath_path, "f"));
this.size = input.size;

@@ -63,3 +63,3 @@ this.lastModified = input.lastModified;

if (this.size) {
yield* fs_1.createReadStream(__classPrivateFieldGet(this, _FileFromPath_path, "f"), {
yield* (0, fs_1.createReadStream)(__classPrivateFieldGet(this, _FileFromPath_path, "f"), {
start: __classPrivateFieldGet(this, _FileFromPath_start, "f"),

@@ -76,3 +76,3 @@ end: __classPrivateFieldGet(this, _FileFromPath_start, "f") + this.size - 1

let filename;
if (isPlainObject_1.default(filenameOrOptions)) {
if ((0, isPlainObject_1.default)(filenameOrOptions)) {
[options, filename] = [filenameOrOptions, undefined];

@@ -92,3 +92,3 @@ }

function fileFromPathSync(path, filenameOrOptions, options = {}) {
return createFileFromPath(path, fs_1.statSync(path), filenameOrOptions, options);
return createFileFromPath(path, (0, fs_1.statSync)(path), filenameOrOptions, options);
}

@@ -95,0 +95,0 @@ exports.fileFromPathSync = fileFromPathSync;

@@ -22,10 +22,10 @@ "use strict";

if (entries) {
entries.forEach(({ name, value, filename }) => this.append(name, value, filename));
entries.forEach(({ name, value, fileName }) => this.append(name, value, fileName));
}
}
append(name, value, filename) {
append(name, value, fileName) {
return __classPrivateFieldGet(this, _FormData_instances, "m", _FormData_setEntry).call(this, {
name,
value,
filename,
fileName,
append: true,

@@ -35,7 +35,7 @@ argsLength: arguments.length

}
set(name, value, filename) {
set(name, value, fileName) {
return __classPrivateFieldGet(this, _FormData_instances, "m", _FormData_setEntry).call(this, {
name,
value,
filename,
fileName,
append: false,

@@ -83,3 +83,3 @@ argsLength: arguments.length

}
[(_FormData_entries = new WeakMap(), _FormData_instances = new WeakSet(), _FormData_setEntry = function _FormData_setEntry({ name, value, append, filename, argsLength }) {
[(_FormData_entries = new WeakMap(), _FormData_instances = new WeakSet(), _FormData_setEntry = function _FormData_setEntry({ name, value, append, fileName, argsLength }) {
const methodName = append ? "append" : "set";

@@ -91,5 +91,6 @@ name = String(name);

}
if (isFile_1.isFile(value)) {
filename = normalizeFilename_1.default(filename === undefined ? value.name : filename);
value = new File_1.File([value], filename, {
let normalizedValue;
if ((0, isFile_1.isFile)(value)) {
fileName = (0, normalizeFilename_1.default)(fileName === undefined ? value.name : fileName);
normalizedValue = new File_1.File([value], fileName, {
type: value.type,

@@ -99,3 +100,3 @@ lastModified: value.lastModified

}
else if (filename) {
else if (fileName) {
throw new TypeError(`Failed to execute '${methodName}' on 'FormData': `

@@ -105,12 +106,12 @@ + "parameter 2 is not of type 'Blob'.");

else {
value = String(value);
normalizedValue = String(value);
}
const values = __classPrivateFieldGet(this, _FormData_entries, "f").get(name);
if (!values) {
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [value]);
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [normalizedValue]);
}
if (!append) {
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [value]);
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [normalizedValue]);
}
values.push(value);
values.push(normalizedValue);
}, Symbol.iterator)]() {

@@ -117,0 +118,0 @@ return this.entries();

@@ -14,2 +14,3 @@ "use strict";

__exportStar(require("./FormData"), exports);
__exportStar(require("./Blob"), exports);
__exportStar(require("./File"), exports);

@@ -13,4 +13,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

var _File_name, _File_lastModified;
import Blob from "fetch-blob";
export { Blob };
import { Blob } from "./Blob.js";
export class File extends Blob {

@@ -17,0 +16,0 @@ constructor(fileBits, name, options = { lastModified: Date.now() }) {

@@ -16,10 +16,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {

if (entries) {
entries.forEach(({ name, value, filename }) => this.append(name, value, filename));
entries.forEach(({ name, value, fileName }) => this.append(name, value, fileName));
}
}
append(name, value, filename) {
append(name, value, fileName) {
return __classPrivateFieldGet(this, _FormData_instances, "m", _FormData_setEntry).call(this, {
name,
value,
filename,
fileName,
append: true,

@@ -29,7 +29,7 @@ argsLength: arguments.length

}
set(name, value, filename) {
set(name, value, fileName) {
return __classPrivateFieldGet(this, _FormData_instances, "m", _FormData_setEntry).call(this, {
name,
value,
filename,
fileName,
append: false,

@@ -77,3 +77,3 @@ argsLength: arguments.length

}
[(_FormData_entries = new WeakMap(), _FormData_instances = new WeakSet(), _FormData_setEntry = function _FormData_setEntry({ name, value, append, filename, argsLength }) {
[(_FormData_entries = new WeakMap(), _FormData_instances = new WeakSet(), _FormData_setEntry = function _FormData_setEntry({ name, value, append, fileName, argsLength }) {
const methodName = append ? "append" : "set";

@@ -85,5 +85,6 @@ name = String(name);

}
let normalizedValue;
if (isFile(value)) {
filename = normalizeFilename(filename === undefined ? value.name : filename);
value = new File([value], filename, {
fileName = normalizeFilename(fileName === undefined ? value.name : fileName);
normalizedValue = new File([value], fileName, {
type: value.type,

@@ -93,3 +94,3 @@ lastModified: value.lastModified

}
else if (filename) {
else if (fileName) {
throw new TypeError(`Failed to execute '${methodName}' on 'FormData': `

@@ -99,12 +100,12 @@ + "parameter 2 is not of type 'Blob'.");

else {
value = String(value);
normalizedValue = String(value);
}
const values = __classPrivateFieldGet(this, _FormData_entries, "f").get(name);
if (!values) {
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [value]);
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [normalizedValue]);
}
if (!append) {
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [value]);
return void __classPrivateFieldGet(this, _FormData_entries, "f").set(name, [normalizedValue]);
}
values.push(value);
values.push(normalizedValue);
}, Symbol.iterator)]() {

@@ -111,0 +112,0 @@ return this.entries();

export * from "./FormData.js";
export * from "./Blob.js";
export * from "./File.js";
{
"name": "formdata-node",
"version": "4.0.1",
"version": "4.1.0",
"description": "Spec-compliant FormData implementation for Node.js",

@@ -9,7 +9,6 @@ "repository": "octet-stream/form-data",

"node",
"async-iterator",
"stream",
"form",
"upload",
"files-upload"
"files-upload",
"ponyfill"
],

@@ -68,6 +67,6 @@ "author": "Nick K. <io@octetstream.me>",

"@octetstream/eslint-config": "5.0.0",
"@types/node": "16.6.1",
"@types/node": "16.9.0",
"@types/sinon": "10.0.2",
"@typescript-eslint/eslint-plugin": "4.29.1",
"@typescript-eslint/parser": "4.29.1",
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
"@zoltu/typescript-transformer-append-js-extension": "1.0.1",

@@ -82,15 +81,15 @@ "ava": "3.15.0",

"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-react": "7.24.0",
"husky": "7.0.1",
"eslint-plugin-react": "7.25.1",
"husky": "7.0.2",
"lint-staged": "11.1.2",
"pinst": "2.1.6",
"sinon": "11.1.2",
"ts-node": "10.2.0",
"ts-node": "10.2.1",
"ttypescript": "1.5.12",
"typescript": "4.3.5"
"typescript": "4.4.2"
},
"dependencies": {
"fetch-blob": "2.1.2",
"node-domexception": "1.0.0"
"node-domexception": "1.0.0",
"web-streams-polyfill": "4.0.0-beta.1"
}
}

@@ -43,5 +43,5 @@ # FormData

got.post("https://httpbin.org/post", {body: form})
.then(res => console.log("Res: ", res.body))
.catch(err => console.error("Error: ", err))
const data = await got.post("https://httpbin.org/post", {body: form}).json()
console.log(data.form.greeting) // => Hello, World!
```

@@ -293,9 +293,59 @@

### `class Blob`
The `Blob` object represents a blob, which is a file-like object of immutable, raw data;
they can be read as text or binary data, or converted into a ReadableStream
so its methods can be used for processing the data.
##### `constructor(blobParts[, options]) -> {Blob}`
Creates a new `Blob` instance. The `Blob` constructor accepts following arguments:
- **{(ArrayBufferLike | ArrayBufferView | File | Blob | string)[]}** blobParts
- **{object}** [options = {}] - An options object containing optional attributes for the file. Available options are as follows
- **{string}** [options.type = ""] - Returns the media type ([`MIME`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)) of the blob represented by a `Blob` object.
#### Instance properties
##### `type -> {string}`
Returns the [`MIME type`](https://developer.mozilla.org/en-US/docs/Glossary/MIME_type) of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
##### `size -> {number}`
Returns the size of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) in bytes.
#### Instance methods
##### `slice([start, end, contentType]) -> {Blob}`
Creates and returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object which contains data from a subset of the blob on which it's called.
- **{number}** [start = 0] An index into the `Blob` indicating the first byte to include in the new `Blob`. If you specify a negative value, it's treated as an offset from the end of the `Blob` toward the beginning. For example, -10 would be the 10th from last byte in the `Blob`. The default value is 0. If you specify a value for start that is larger than the size of the source `Blob`, the returned `Blob` has size 0 and contains no data.
- **{number}** [end = `blob`.size] An index into the `Blob` indicating the first byte that will *not* be included in the new `Blob` (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the `Blob` toward the beginning. For example, -10 would be the 10th from last byte in the `Blob`. The default value is size.
- **{string}** [contentType = ""] The content type to assign to the new ``Blob``; this will be the value of its type property. The default value is an empty string.
##### `stream() -> {ReadableStream<Uint8Array>}`
Returns a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) which upon reading returns the data contained within the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
##### `arrayBuffer() -> {Promise<ArrayBuffer>}`
Returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with the contents of the blob as binary data contained in an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
##### `text() -> {Promise<string>}`
Returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with a string containing the contents of the blob, interpreted as UTF-8.
### `class File extends Blob`
##### `constructor(blobParts, filename[, options]) -> {File}`
The `File` class provides information about files. The `File` class inherits `Blob`.
The `File` class provides information about files. The `File` object inherits `Blob` from [`fetch-blob`](https://github.com/bitinn/fetch-blob) package.
##### `constructor(fileBits, filename[, options]) -> {File}`
- **{(ArrayBufferLike | ArrayBufferView | Blob | string)[]}** blobParts
Creates a new `File` instance. The `File` constructor accepts following arguments:
- **{(ArrayBufferLike | ArrayBufferView | File | Blob | string)[]}** fileBits
- **{string}** filename – Representing the file name.

@@ -302,0 +352,0 @@ - **{object}** [options = {}] - An options object containing optional attributes for the file. Available options are as follows

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