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

then-busboy

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

then-busboy - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

test/helper/mockHeader.js

112

lib/File.js

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

});
exports.default = void 0;

@@ -14,26 +15,14 @@ var _os = require("os");

var _stream = require("stream");
var _stream = _interopRequireDefault(require("stream"));
var _stream2 = _interopRequireDefault(_stream);
var _invariant = _interopRequireDefault(require("@octetstream/invariant"));
var _invariant = require("@octetstream/invariant");
var _nanoid = _interopRequireDefault(require("nanoid"));
var _invariant2 = _interopRequireDefault(_invariant);
var _isPlainObject = _interopRequireDefault(require("./util/isPlainObject"));
var _nanoid = require("nanoid");
var _isString = _interopRequireDefault(require("./util/isString"));
var _nanoid2 = _interopRequireDefault(_nanoid);
var _getType = _interopRequireDefault(require("./util/getType"));
var _isPlainObject = require("./util/isPlainObject");
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _isString = require("./util/isString");
var _isString2 = _interopRequireDefault(_isString);
var _getType = require("./util/getType");
var _getType2 = _interopRequireDefault(_getType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -52,43 +41,45 @@

constructor(options) {
this.read = () => new Promise((resolve, reject) => {
const data = [];
Object.defineProperty(this, "read", {
configurable: true,
enumerable: true,
writable: true,
value: () => new Promise((resolve, reject) => {
const data = [];
const onData = ch => void data.push(ch);
const onData = ch => void data.push(ch);
const onEnd = () => resolve(Buffer.concat(data));
const onEnd = () => resolve(Buffer.concat(data));
this.contents.on("error", reject).on("data", onData).on("end", onEnd);
this.contents.on("error", reject).on("data", onData).on("end", onEnd);
})
});
Object.defineProperty(this, "write", {
configurable: true,
enumerable: true,
writable: true,
value: path => new Promise((resolve, reject) => {
if (!path || !(0, _isString.default)(path)) {
path = this.path;
}
this.write = path => new Promise((resolve, reject) => {
if (!path || !(0, _isString2.default)(path)) {
path = this.path;
}
this.contents.on("error", reject).on("end", resolve).pipe((0, _fs.createWriteStream)(path));
this.contents.on("error", reject).on("end", resolve).pipe((0, _fs.createWriteStream)(path));
})
});
(0, _invariant2.default)(!(0, _isPlainObject2.default)(options), TypeError, "File options should be a plain object. Received", (0, _getType2.default)(options));
const { contents, filename, enc, mime } = options;
(0, _invariant2.default)(!contents, "File contents required.");
(0, _invariant2.default)(!(contents instanceof _stream2.default), TypeError, "Contents should be a Stream. Received %s", (0, _getType2.default)(contents));
(0, _invariant2.default)(!filename, "Filename required.");
(0, _invariant2.default)(!(0, _isString2.default)(filename), TypeError, "Filename should be a string. Received %s", (0, _getType2.default)(filename));
(0, _invariant2.default)(!enc, "File encoding required.");
(0, _invariant2.default)(!(0, _isString2.default)(enc), TypeError, "File encoding should be a string. Received %s", (0, _getType2.default)(enc));
(0, _invariant2.default)(!mime, "File mime type required.");
(0, _invariant2.default)(!(0, _isString2.default)(mime), TypeError, "File mime type should be a string. Received %s", (0, _getType2.default)(mime));
(0, _invariant.default)(!(0, _isPlainObject.default)(options), TypeError, "File options should be a plain object. Received", (0, _getType.default)(options));
const {
contents,
filename,
enc,
mime
} = options;
(0, _invariant.default)(!contents, "File contents required.");
(0, _invariant.default)(!(contents instanceof _stream.default), TypeError, "Contents should be a Stream. Received %s", (0, _getType.default)(contents));
(0, _invariant.default)(!filename, "Filename required.");
(0, _invariant.default)(!(0, _isString.default)(filename), TypeError, "Filename should be a string. Received %s", (0, _getType.default)(filename));
(0, _invariant.default)(!enc, "File encoding required.");
(0, _invariant.default)(!(0, _isString.default)(enc), TypeError, "File encoding should be a string. Received %s", (0, _getType.default)(enc));
(0, _invariant.default)(!mime, "File mime type required.");
(0, _invariant.default)(!(0, _isString.default)(mime), TypeError, "File mime type should be a string. Received %s", (0, _getType.default)(mime));
const ext = (0, _path.extname)(filename);
const base = (0, _path.basename)(filename, ext);
this.__contents = contents;

@@ -101,5 +92,3 @@ this.__stream = contents;

this.__enc = enc;
this.__path = (0, _path.join)((0, _os.tmpdir)(), `${(0, _nanoid2.default)()}_${this.filename}`);
this.__path = (0, _path.join)((0, _os.tmpdir)(), `${(0, _nanoid.default)()}_${this.filename}`);
this.toJSON = this.toJSON.bind(this);

@@ -140,3 +129,2 @@ this.inspect = this.inspect.bind(this);

}
/**

@@ -149,12 +137,2 @@ * Read file contents from a stream

/**
* Write file contents to a disk.
*
* @param {string} path – path to where contents will be stored
* (default – this.path)
*
* @return {Promise}
*/
toJSON() {

@@ -167,4 +145,6 @@ return this.inspect();

}
}
exports.default = File;
var _default = File;
exports.default = _default;

@@ -6,7 +6,6 @@ "use strict";

});
exports.default = void 0;
var _File = require("./File");
var _File = _interopRequireDefault(require("./File"));
var _File2 = _interopRequireDefault(_File);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,4 +22,5 @@

*/
const isFile = val => val instanceof _File2.default;
const isFile = val => val instanceof _File.default;
exports.default = isFile;
var _default = isFile;
exports.default = _default;

@@ -6,11 +6,8 @@ "use strict";

});
exports.default = void 0;
var _getFieldPath = require("../util/getFieldPath");
var _getFieldPath = _interopRequireDefault(require("../util/getFieldPath"));
var _getFieldPath2 = _interopRequireDefault(_getFieldPath);
var _restoreType = _interopRequireDefault(require("../util/restoreType"));
var _restoreType = require("../util/restoreType");
var _restoreType2 = _interopRequireDefault(_restoreType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -23,5 +20,4 @@

try {
const path = (0, _getFieldPath2.default)(fieldname);
cb(null, [path, options.restoreTypes ? (0, _restoreType2.default)(value) : value]);
const path = (0, _getFieldPath.default)(fieldname);
cb(null, [path, options.restoreTypes ? (0, _restoreType.default)(value) : value]);
} catch (err) {

@@ -32,2 +28,3 @@ return cb(err);

exports.default = onField;
var _default = onField;
exports.default = _default;

@@ -6,13 +6,10 @@ "use strict";

});
exports.default = void 0;
var _stream = require("stream");
var _File = require("../File");
var _File = _interopRequireDefault(require("../File"));
var _File2 = _interopRequireDefault(_File);
var _getFieldPath = _interopRequireDefault(require("../util/getFieldPath"));
var _getFieldPath = require("../util/getFieldPath");
var _getFieldPath2 = _interopRequireDefault(_getFieldPath);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -27,6 +24,8 @@

try {
const path = (0, _getFieldPath2.default)(fieldname);
const path = (0, _getFieldPath.default)(fieldname);
const contents = new _stream.Readable({
read() {
/* noop */
}
const contents = new _stream.Readable({
read() {/* noop */}
});

@@ -38,10 +37,13 @@

contents.push(null);
const file = new _File.default({
filename,
contents,
enc,
mime
});
cb(null, [path, file]);
} // Busboy doesn't emit an "end" event while file stream have not been read.
// So, we just read the stream and push it to the other [Readable] one. o_O
const file = new _File2.default({ filename, contents, enc, mime });
cb(null, [path, file]);
}
// Busboy doesn't emit an "end" event while file stream have not been read.
// So, we just read the stream and push it to the other [Readable] one. o_O
stream.on("error", cb).on("data", onData).on("end", onEnd);

@@ -53,2 +55,3 @@ } catch (err) {

exports.default = onFile;
var _default = onFile;
exports.default = _default;

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

});
exports.default = void 0;

@@ -12,41 +13,23 @@ var _http = require("http");

var _invariant = require("@octetstream/invariant");
var _invariant = _interopRequireDefault(require("@octetstream/invariant"));
var _invariant2 = _interopRequireDefault(_invariant);
var _busboy = _interopRequireDefault(require("busboy"));
var _busboy = require("busboy");
var _lodash = _interopRequireDefault(require("lodash.merge"));
var _busboy2 = _interopRequireDefault(_busboy);
var _mapListeners = _interopRequireDefault(require("./util/mapListeners"));
var _lodash = require("lodash.merge");
var _getType = _interopRequireDefault(require("./util/getType"));
var _lodash2 = _interopRequireDefault(_lodash);
var _isPlainObject = _interopRequireDefault(require("./util/isPlainObject"));
var _mapListeners = require("./util/mapListeners");
var _readListeners = _interopRequireDefault(require("./util/readListeners"));
var _mapListeners2 = _interopRequireDefault(_mapListeners);
var _objectFromEntries = _interopRequireDefault(require("./util/objectFromEntries"));
var _getType = require("./util/getType");
var _getType2 = _interopRequireDefault(_getType);
var _isPlainObject = require("./util/isPlainObject");
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _readListeners = require("./util/readListeners");
var _readListeners2 = _interopRequireDefault(_readListeners);
var _objectFromEntries = require("./util/objectFromEntries");
var _objectFromEntries2 = _interopRequireDefault(_objectFromEntries);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const initializers = (0, _readListeners2.default)((0, _path.join)(__dirname, "listener"));
const initializers = (0, _readListeners.default)((0, _path.join)(__dirname, "listener"));
const defaults = {
restoreTypes: true
/**

@@ -87,13 +70,13 @@ * Promise-based wrapper around Busboy. Inspired by async-busboy.

*/
};const thenBusboy = (request, options = {}) => new Promise((resolve, reject) => {
(0, _invariant2.default)(!(request instanceof _http.IncomingMessage), TypeError, "Request should be an instanceof http.IncomingMessage. Received %s", (0, _getType2.default)(request));
(0, _invariant2.default)(!(0, _isPlainObject2.default)(options), TypeError, "Options should be an object. Received %s", (0, _getType2.default)(options));
};
const thenBusboy = (request, options = {}) => new Promise((resolve, reject) => {
(0, _invariant.default)(!(request instanceof _http.IncomingMessage), TypeError, "Request should be an instanceof http.IncomingMessage. Received %s", (0, _getType.default)(request));
(0, _invariant.default)(!(0, _isPlainObject.default)(options), TypeError, "Options should be an object. Received %s", (0, _getType.default)(options));
const headers = request.headers;
options = (0, _lodash2.default)({}, defaults, options, { headers });
const busboy = new _busboy2.default(request, options);
options = (0, _lodash.default)({}, defaults, options, {
headers
});
const busboy = new _busboy.default(request, options);
const entries = [];

@@ -103,13 +86,12 @@

const listeners = (0, _mapListeners2.default)(initializers, fn => fn(options, fulfill));
const listeners = (0, _mapListeners.default)(initializers, fn => fn(options, fulfill)); // Set listeners before starting
// Set listeners before starting
void (0, _mapListeners2.default)(listeners, (fn, name) => busboy.on(name, fn));
void (0, _mapListeners.default)(listeners, (fn, name) => busboy.on(name, fn));
function onFinish() {
// Cleanup listeners
void (0, _mapListeners2.default)(listeners, (fn, name) => busboy.removeListener(name, fn));
void (0, _mapListeners.default)(listeners, (fn, name) => busboy.removeListener(name, fn));
try {
return resolve((0, _objectFromEntries2.default)(entries));
return resolve((0, _objectFromEntries.default)(entries));
} catch (err) {

@@ -121,6 +103,6 @@ return reject(err);

busboy.on("error", reject).on("finish", onFinish);
request.pipe(busboy);
});
exports.default = thenBusboy;
var _default = thenBusboy;
exports.default = _default;

@@ -6,23 +6,15 @@ "use strict";

});
exports.default = void 0;
var _invariant = require("@octetstream/invariant");
var _invariant = _interopRequireDefault(require("@octetstream/invariant"));
var _invariant2 = _interopRequireDefault(_invariant);
var _isString = _interopRequireDefault(require("./isString"));
var _isString = require("./isString");
var _getType = _interopRequireDefault(require("./getType"));
var _isString2 = _interopRequireDefault(_isString);
var _isNaN = _interopRequireDefault(require("./isNaN"));
var _getType = require("./getType");
var _getType2 = _interopRequireDefault(_getType);
var _isNaN = require("./isNaN");
var _isNaN2 = _interopRequireDefault(_isNaN);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const format = /^([^[\]\n]+)(\[[^[\]]+\])*$/;
/**

@@ -46,15 +38,12 @@ * Get a fild path

*/
function getFieldPath(fieldname) {
const res = [];
(0, _invariant.default)(!(0, _isString.default)(fieldname), TypeError, "Field name should be a string. Received %s", (0, _getType.default)(fieldname));
(0, _invariant.default)(!fieldname, "Field name cannot be empty.");
(0, _invariant.default)(!format.test(fieldname), "Unexpected name format of the field: %s", fieldname);
(0, _invariant2.default)(!(0, _isString2.default)(fieldname), TypeError, "Field name should be a string. Received %s", (0, _getType2.default)(fieldname));
(0, _invariant2.default)(!fieldname, "Field name cannot be empty.");
(0, _invariant2.default)(!format.test(fieldname), "Unexpected name format of the field: %s", fieldname);
for (const element of fieldname.split("[")) {
const key = element.endsWith("]") ? element.slice(0, -1) : element;
res.push((0, _isNaN2.default)(key) ? key : Number(key));
res.push((0, _isNaN.default)(key) ? key : Number(key));
}

@@ -65,2 +54,3 @@

exports.default = getFieldPath;
var _default = getFieldPath;
exports.default = _default;

@@ -6,4 +6,4 @@ "use strict";

});
exports.default = void 0;
const basicTypes = ["null", "number", "object", "array", "string", "function", "undefined", "boolean"];
/**

@@ -18,2 +18,3 @@ * Get a string with type name of the given value

*/
function getType(val) {

@@ -29,2 +30,3 @@ const type = Object.prototype.toString.call(val).slice(8, -1);

exports.default = getType;
var _default = getType;
exports.default = _default;

@@ -6,2 +6,4 @@ "use strict";

});
exports.default = void 0;
/**

@@ -18,2 +20,3 @@ * Check if given values is NaN

exports.default = isNaN;
var _default = isNaN;
exports.default = _default;

@@ -6,15 +6,13 @@ "use strict";

});
exports.default = void 0;
var _getType = require("./getType");
var _getType = _interopRequireDefault(require("./getType"));
var _getType2 = _interopRequireDefault(_getType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getPrototype = Object.getPrototypeOf;
const objectCtorString = Object.toString();
const objectCtorString = Object.toString(); // Based ob lodash/isPlainObject
// Based ob lodash/isPlainObject
function isPlainObject(val) {
if ((0, _getType2.default)(val) !== "object") {
if ((0, _getType.default)(val) !== "object") {
return false;

@@ -30,6 +28,6 @@ }

const Ctor = pp.constructor && pp.constructor.toString();
return Ctor === objectCtorString;
}
exports.default = isPlainObject;
var _default = isPlainObject;
exports.default = _default;

@@ -6,11 +6,11 @@ "use strict";

});
exports.default = void 0;
var _getType = require("./getType");
var _getType = _interopRequireDefault(require("./getType"));
var _getType2 = _interopRequireDefault(_getType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const isString = val => (0, _getType2.default)(val) === "string";
const isString = val => (0, _getType.default)(val) === "string";
exports.default = isString;
var _default = isString;
exports.default = _default;

@@ -6,9 +6,13 @@ "use strict";

});
exports.default = void 0;
const toLowerCase = str => String.prototype.toLowerCase.call(str);
/**
* @api private
*/
const leadToLowerCase = str => `${toLowerCase(str.charAt(0))}${str.slice(1)}`;
exports.default = leadToLowerCase;
var _default = leadToLowerCase;
exports.default = _default;

@@ -6,11 +6,9 @@ "use strict";

});
exports.default = void 0;
var _leadToLowerCase = require("./leadToLowerCase");
var _leadToLowerCase = _interopRequireDefault(require("./leadToLowerCase"));
var _leadToLowerCase2 = _interopRequireDefault(_leadToLowerCase);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const entries = Object.entries;
/**

@@ -24,2 +22,3 @@ * Walk throght listeners object and execute given function on each of them.

*/
function mapListeners(listeners, fn) {

@@ -29,3 +28,3 @@ const res = {};

for (const [key, value] of entries(listeners)) {
const name = key.startsWith("on") ? (0, _leadToLowerCase2.default)(key.slice(2)) : key;
const name = key.startsWith("on") ? (0, _leadToLowerCase.default)(key.slice(2)) : key;

@@ -40,2 +39,3 @@ if (!["error", "end"].includes(name)) {

exports.default = mapListeners;
var _default = mapListeners;
exports.default = _default;

@@ -6,7 +6,6 @@ "use strict";

});
exports.default = void 0;
var _isNaN = require("./isNaN");
var _isNaN = _interopRequireDefault(require("./isNaN"));
var _isNaN2 = _interopRequireDefault(_isNaN);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -25,3 +24,3 @@

const currentPath = path.shift();
const curr = (0, _isNaN2.default)(currentPath) ? {} : [];
const curr = (0, _isNaN.default)(currentPath) ? {} : [];

@@ -31,3 +30,2 @@ if (!target) {

curr[currentPath] = value;
return curr;

@@ -37,3 +35,2 @@ }

curr[currentPath] = restoreObjectStructure(curr[currentPath], path, value);
return curr;

@@ -44,3 +41,2 @@ }

target[currentPath] = value;
return target;

@@ -50,6 +46,4 @@ }

target[currentPath] = restoreObjectStructure(target[currentPath], path, value);
return target;
}
/**

@@ -80,2 +74,4 @@ * Create an object from given entries

*/
function objectFromEntries(entries) {

@@ -97,2 +93,3 @@ const res = {};

exports.default = objectFromEntries;
var _default = objectFromEntries;
exports.default = _default;

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

});
exports.default = void 0;

@@ -21,3 +22,2 @@ var _fs = require("fs");

const res = {};
const dir = (0, _fs.readdirSync)(path);

@@ -27,5 +27,5 @@

const ext = (0, _path.extname)(filename);
if (["js", "mjs"].includes(ext.slice(1))) {
const base = (0, _path.basename)(filename, ext);
res[base] = require((0, _path.join)(path, base)).default;

@@ -38,2 +38,3 @@ }

exports.default = readListeners;
var _default = readListeners;
exports.default = _default;

@@ -6,7 +6,6 @@ "use strict";

});
exports.default = void 0;
var _isNaN = require("./isNaN");
var _isNaN = _interopRequireDefault(require("./isNaN"));
var _isNaN2 = _interopRequireDefault(_isNaN);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -40,3 +39,3 @@

if (!(0, _isNaN2.default)(value)) {
if (!(0, _isNaN.default)(value)) {
return Number(value);

@@ -48,2 +47,3 @@ }

exports.default = restoreType;
var _default = restoreType;
exports.default = _default;

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

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isFile = exports.default = undefined;
var _thenBusboy = require("./lib/then-busboy");
var _thenBusboy2 = _interopRequireDefault(_thenBusboy);
var _isFile2 = require("./lib/isFile");
var _isFile3 = _interopRequireDefault(_isFile2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _thenBusboy2.default; // eslint-disable-line
exports.isFile = _isFile3.default; // eslint-disable-line
module.exports = require("./lib/then-busboy").default;
module.exports.isFile = require("./lib/isFile").default;
{
"name": "then-busboy",
"version": "2.1.3",
"description": "Promise-based wrapper around Busboy. Process multipart/form-data content and returns it as a single object.",
"version": "2.1.4",
"author": "Nick K. <nick.kruchinin@gmail.com>",
"license": "MIT",
"repository": "octet-stream/then-busboy",

@@ -37,6 +39,3 @@ "main": "./main.js",

},
"author": "Nick K. <nick.kruchinin@gmail.com>",
"license": "MIT",
"ava": {
"babel": "inherit",
"files": [

@@ -58,23 +57,23 @@ "test/**/*.js",

"lodash.merge": "4.6.0",
"nanoid": "1.0.0"
"nanoid": "1.0.1"
},
"devDependencies": {
"@babel/cli": ">=7.0.0-beta.34 <=7.0.0",
"@babel/core": ">=7.0.0-beta.34 <=7.0.0",
"@babel/plugin-proposal-class-properties": ">=7.0.0-beta.34 <=7.0.0",
"@babel/plugin-proposal-object-rest-spread": ">=7.0.0-beta.34 <=7.0.0",
"@babel/plugin-transform-modules-commonjs": ">=7.0.0-beta.34 <=7.0.0",
"@octetstream/eslint-config": "2.1.0",
"ava": "0.23.0",
"babel-cli": "6.26.0",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "6.26.0",
"babel-plugin-transform-export-extensions": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"ava": "0.24.0",
"codecov": "3.0.0",
"eslint": "^4.9.0",
"eslint-plugin-ava": "4.2.2",
"eslint": "4.13.1",
"eslint-plugin-ava": "4.4.0",
"husky": "0.14.3",
"nyc": "11.2.1",
"nyc": "11.3.0",
"promise-fs": "1.3.0",
"proxyquire": "1.8.0",
"rimraf": "2.6.2",
"sinon": "4.0.2",
"sinon": "4.1.3",
"supertest": "3.0.0"
}
}
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