How to use the @sindresorhus/is 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
options.prefixUrl += '/';
		}
	} else {
		options.prefixUrl = defaults ? defaults.prefixUrl : '';
	}

	// `options.hooks`
	if (is.undefined(options.hooks)) {
		options.hooks = {};
	}

	if (is.object(options.hooks)) {
		for (const event of knownHookEvents) {
			if (Reflect.has(options.hooks, event)) {
				if (!is.array(options.hooks[event])) {
					throw new TypeError(`Parameter \`${event}\` must be an Array, not ${is(options.hooks[event])}`);
				}
			} else {
				options.hooks[event] = [];
			}
		}
	} else {
		throw new TypeError(`Parameter \`hooks\` must be an Object, not ${is(options.hooks)}`);
	}

	if (defaults) {
		for (const event of knownHookEvents) {
			if (!(Reflect.has(options.hooks, event) && is.undefined(options.hooks[event]))) {
				// @ts-ignore Union type array is not assignable to union array type
				options.hooks[event] = [
					...defaults.hooks[event],
					...options.hooks[event]!
github sindresorhus / ow / source / predicates / predicate.ts View on Github external
message: (value, label) => {
				// We do not include type in this label as we do for other messages, because it would be redundant.
				const label_ = label?.slice(this.type.length + 1);

				return `Expected ${label_ || 'argument'} to be of type \`${this.type}\` but received type \`${is(value)}\``;
			},
			validator: value => (is as any)[x](value)
github sindresorhus / got / source / normalize-arguments.ts View on Github external
if (is.undefined(options.hooks)) {
		options.hooks = {};
	}

	if (is.object(options.hooks)) {
		for (const event of knownHookEvents) {
			if (Reflect.has(options.hooks, event)) {
				if (!is.array(options.hooks[event])) {
					throw new TypeError(`Parameter \`${event}\` must be an Array, not ${is(options.hooks[event])}`);
				}
			} else {
				options.hooks[event] = [];
			}
		}
	} else {
		throw new TypeError(`Parameter \`hooks\` must be an Object, not ${is(options.hooks)}`);
	}

	if (defaults) {
		for (const event of knownHookEvents) {
			if (!(Reflect.has(options.hooks, event) && is.undefined(options.hooks[event]))) {
				// @ts-ignore Union type array is not assignable to union array type
				options.hooks[event] = [
					...defaults.hooks[event],
					...options.hooks[event]!
				];
			}
		}
	}

	// `options.timeout`
	if (is.number(options.timeout)) {