How to use the @sindresorhus/is.nodeStream function in @sindresorhus/is

To help you get started, we’ve selected a few @sindresorhus/is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / got / source / normalize-arguments.ts View on Github external
{
		// TODO: these checks should be moved to `preNormalizeArguments`
		const isForm = !is.undefined(options.form);
		const isJSON = !is.undefined(options.json);
		const isBody = !is.undefined(options.body);
		if ((isBody || isForm || isJSON) && withoutBody.has(options.method)) {
			throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
		}

		if ([isBody, isForm, isJSON].filter(isTrue => isTrue).length > 1) {
			throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');
		}

		if (
			isBody &&
			!is.nodeStream(options.body) &&
			!is.string(options.body) &&
			!is.buffer(options.body) &&
			!(is.object(options.body) && isFormData(options.body))
		) {
			throw new TypeError('The `body` option must be a stream.Readable, string or Buffer');
		}

		if (isForm && !is.object(options.form)) {
			throw new TypeError('The `form` option must be an Object');
		}
	}

	if (options.body) {
		// Special case for https://github.com/form-data/form-data
		if (is.object(options.body) && isFormData(options.body) && noContentType) {
			headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;
github sx1989827 / DOClever / node_modules / got / index.js View on Github external
ee.on('request', req => {
		proxy.emit('request', req);

		if (is.nodeStream(opts.body)) {
			opts.body.pipe(req);
			return;
		}

		if (opts.body) {
			req.end(opts.body);
			return;
		}

		if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
			input.pipe(req);
			return;
		}

		req.end();
	});
github htaussig / ProcProj / canvasSketch / future3D / node_modules / got / source / request-as-event-emitter.js View on Github external
timings = timer(request);

			progress.upload(request, emitter, uploadBodySize);

			if (options.gotTimeout) {
				timedOut(request, options.gotTimeout, options);
			}

			emitter.emit('request', request);

			const uploadComplete = () => {
				request.emit('upload-complete');
			};

			try {
				if (is.nodeStream(options.body)) {
					options.body.once('end', uploadComplete);
					options.body.pipe(request);
					options.body = undefined;
				} else if (options.body) {
					request.end(options.body, uploadComplete);
				} else if (input && (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH')) {
					input.once('end', uploadComplete);
					input.pipe(request);
				} else {
					request.end(uploadComplete);
				}
			} catch (error) {
				emitError(new RequestError(error, options));
			}
		};
github Hackdromeda / BugBrowser / node_modules / got / index.js View on Github external
ee.on('request', req => {
		proxy.emit('request', req);

		if (is.nodeStream(opts.body)) {
			opts.body.pipe(req);
			return;
		}

		if (opts.body) {
			req.end(opts.body);
			return;
		}

		if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH') {
			input.pipe(req);
			return;
		}

		req.end();
	});
github htaussig / ProcProj / canvasSketch / future3D / node_modules / got / source / utils / is-form-data.js View on Github external
module.exports = body => is.nodeStream(body) && is.function(body.getBoundary);