How to use the @sindresorhus/is.plainObject 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 / merge.ts View on Github external
}

			const targetValue = target[key];
			if (targetValue instanceof URLSearchParams && sourceValue instanceof URLSearchParams) {
				const params = new URLSearchParams();

				const append = (value: string, key: string): void => params.append(key, value);
				targetValue.forEach(append);
				sourceValue.forEach(append);

				// @ts-ignore https://github.com/microsoft/TypeScript/issues/31661
				target[key] = params;
			} else if (is.urlInstance(targetValue) && (is.urlInstance(sourceValue) || is.string(sourceValue))) {
				// @ts-ignore
				target[key] = new URL(sourceValue as string, targetValue);
			} else if (is.plainObject(sourceValue)) {
				if (is.plainObject(targetValue)) {
					// @ts-ignore
					target[key] = merge({}, targetValue, sourceValue);
				} else {
					// @ts-ignore
					target[key] = merge({}, sourceValue);
				}
			} else if (is.array(sourceValue)) {
				// @ts-ignore
				target[key] = sourceValue.slice();
			} else {
				// @ts-ignore
				target[key] = sourceValue;
			}
		}
	}
github sindresorhus / got / source / utils / merge.ts View on Github external
export default function merge(target: Target, ...sources: Source[]): Merge {
	for (const source of sources) {
		for (const [key, sourceValue] of Object.entries(source)) {
			const targetValue = target[key];

			if (is.urlInstance(targetValue) && is.string(sourceValue)) {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = new URL(sourceValue, targetValue);
			} else if (is.plainObject(sourceValue)) {
				if (is.plainObject(targetValue)) {
					// @ts-ignore TS doesn't recognise Target accepts string keys
					target[key] = merge({}, targetValue, sourceValue);
				} else {
					// @ts-ignore TS doesn't recognise Target accepts string keys
					target[key] = merge({}, sourceValue);
				}
			} else if (is.array(sourceValue)) {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = sourceValue.slice();
			} else {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = sourceValue;
			}
		}
	}
github sindresorhus / got / source / merge.ts View on Github external
const targetValue = target[key];
			if (targetValue instanceof URLSearchParams && sourceValue instanceof URLSearchParams) {
				const params = new URLSearchParams();

				const append = (value: string, key: string): void => params.append(key, value);
				targetValue.forEach(append);
				sourceValue.forEach(append);

				// @ts-ignore https://github.com/microsoft/TypeScript/issues/31661
				target[key] = params;
			} else if (is.urlInstance(targetValue) && (is.urlInstance(sourceValue) || is.string(sourceValue))) {
				// @ts-ignore
				target[key] = new URL(sourceValue as string, targetValue);
			} else if (is.plainObject(sourceValue)) {
				if (is.plainObject(targetValue)) {
					// @ts-ignore
					target[key] = merge({}, targetValue, sourceValue);
				} else {
					// @ts-ignore
					target[key] = merge({}, sourceValue);
				}
			} else if (is.array(sourceValue)) {
				// @ts-ignore
				target[key] = sourceValue.slice();
			} else {
				// @ts-ignore
				target[key] = sourceValue;
			}
		}
	}
github sindresorhus / got / source / utils / merge.ts View on Github external
export default function merge(target: Target, ...sources: Source[]): Merge {
	for (const source of sources) {
		for (const [key, sourceValue] of Object.entries(source)) {
			const targetValue = target[key];

			if (is.urlInstance(targetValue) && is.string(sourceValue)) {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = new URL(sourceValue, targetValue);
			} else if (is.plainObject(sourceValue)) {
				if (is.plainObject(targetValue)) {
					// @ts-ignore TS doesn't recognise Target accepts string keys
					target[key] = merge({}, targetValue, sourceValue);
				} else {
					// @ts-ignore TS doesn't recognise Target accepts string keys
					target[key] = merge({}, sourceValue);
				}
			} else if (is.array(sourceValue)) {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = sourceValue.slice();
			} else {
				// @ts-ignore TS doesn't recognise Target accepts string keys
				target[key] = sourceValue;
			}
		}
	}
github szmarczak / http2-wrapper / test / response.js View on Github external
test('properties', wrapper, async (t, server) => {
	const request = makeRequest(server.url);
	request.end();

	const response = await pEvent(request, 'response');
	response.resume();

	t.true(is.plainObject(response.headers));
	t.true(is.array(response.rawHeaders));
	t.true(is.plainObject(response.trailers));
	t.true(is.array(response.rawTrailers));
	t.is(request.socket, request.connection);
	t.is(response.socket, request.socket);
	t.is(response.connection, request.socket);
	t.truthy(response.req);
	t.is(response.httpVersion, '2.0');
	t.is(response.httpVersionMajor, 2);
	t.is(response.httpVersionMinor, 0);
	t.true(is.number(response.statusCode));
	t.is(response.statusMessage, '');
});
github szmarczak / http2-wrapper / test / response.js View on Github external
test('properties', wrapper, async (t, server) => {
	const request = makeRequest(server.url);
	request.end();

	const response = await pEvent(request, 'response');
	response.resume();

	t.true(is.plainObject(response.headers));
	t.true(is.array(response.rawHeaders));
	t.true(is.plainObject(response.trailers));
	t.true(is.array(response.rawTrailers));
	t.is(request.socket, request.connection);
	t.is(response.socket, request.socket);
	t.is(response.connection, request.socket);
	t.truthy(response.req);
	t.is(response.httpVersion, '2.0');
	t.is(response.httpVersionMajor, 2);
	t.is(response.httpVersionMinor, 0);
	t.true(is.number(response.statusCode));
	t.is(response.statusMessage, '');
});
github dylang / logging / src / formatters / format-json / format-json.ts View on Github external
const { errors, arrayOfObjects, everythingElse } = groupBy(args, (arg: unknown) =>
        is.error(arg) ? 'errors' : is.plainObject(arg) ? 'arrayOfObjects' : 'everythingElse'
    );
github sindresorhus / ow / source / predicates / object.ts View on Github external
			validator: object => is.plainObject(object)
		});
github android-js / androidjs-builder / example / helloworld / node_modules / got / source / normalize-arguments.js View on Github external
const normalize = (url, options, defaults) => {
	if (is.plainObject(url)) {
		options = {...url, ...options};
		url = options.url || {};
		delete options.url;
	}

	if (defaults) {
		options = merge({}, defaults.options, options ? preNormalize(options, defaults.options) : {});
	} else {
		options = merge({}, preNormalize(options));
	}

	if (!is.string(url) && !is.object(url)) {
		throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
	}

	if (is.string(url)) {