How to use the @sindresorhus/is.promise 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 Hypercubed / f-flat_node / src / env.js View on Github external
function dispatch (action) {
        self.lastAction = action;
        if (typeof action === 'undefined') {
          return;
        }

        if (is.promise(action)) {  // promise middleware
          self.status = YIELDING;
          return action.then(f => {
            self.status = IDLE;
            self.run([f]);
          });
        }

        if (action === null || typeof action.type === 'undefined') {
          return stackPush(action);
        }

        let tokenValue = action.value;

        switch (action.type) {
        case '@@Action':
          if (isImmediate(action)) {
github sindresorhus / got / source / normalize-arguments.ts View on Github external
},
		get: () => prefixUrl
	});

	// Make it possible to remove default headers
	for (const [key, value] of Object.entries(normalizedOptions.headers)) {
		if (is.undefined(value)) {
			// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
			delete normalizedOptions.headers[key];
		}
	}

	for (const hook of normalizedOptions.hooks.init) {
		const result = hook(normalizedOptions);

		if (is.promise(result)) {
			throw new TypeError('The `init` hook must be a synchronous function');
		}
	}

	return normalizedOptions;
};
github android-js / androidjs-builder / example / helloworld / node_modules / got / source / normalize-arguments.js View on Github external
url = urlToOptions(new URL(url, options.baseUrl));
		} else {
			url = url.replace(/^unix:/, 'http://$&');
			url = urlParseLax(url);
		}
	} else if (is(url) === 'URL') {
		url = urlToOptions(url);
	}

	// Override both null/undefined with default protocol
	options = merge({path: ''}, url, {protocol: url.protocol || 'https:'}, options);

	for (const hook of options.hooks.init) {
		const called = hook(options);

		if (is.promise(called)) {
			throw new TypeError('The `init` hook must be a synchronous function');
		}
	}

	const {baseUrl} = options;
	Object.defineProperty(options, 'baseUrl', {
		set: () => {
			throw new Error('Failed to set baseUrl. Options are normalized already.');
		},
		get: () => baseUrl
	});

	const {query} = options;
	if (is.nonEmptyString(query) || is.nonEmptyObject(query) || query instanceof URLSearchParams) {
		if (!is.string(query)) {
			options.query = (new URLSearchParams(query)).toString();
github dylang / logging / src / formatters / format-color / format-any / format-any.ts View on Github external
testError.stack = arg.replace(errorMessage, '').trim();
            return formatError(testError);
        }

        // This hack lets chalk template our strings, like '{blue i am blue}'
        const array = [arg] as TemplateStringsArray;
        array.raw = [arg.replace(/\\/g, '\\\\')];
        try {
            return chalk(array);
        } catch {
            // If chalk has errors just return original
        }
        return arg;
    }

    if (is.promise(arg)) {
        return chalk`{blue [Promise]}`;
    }

    if (is.error(arg)) {
        return formatError(arg);
    }

    if (is.generator(arg) || is.generatorFunction(arg)) {
        return chalk`{blue [Generator]}`;
    }
    return formatObject(arg);
};