All files / src/internal/shared utils.js

73.17% Statements 30/41
100% Branches 6/6
80% Functions 4/5
73.17% Lines 30/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 422x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 401x 401x 2x 2x 2x 315x 315x 2x 2x 2x 2114x 2132x 2132x 2114x 2x 2x 2x 2x 2x                        
export const noop = () => {};
 
// Adapted from https://github.com/then/is-promise/blob/master/index.js
// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE
 
/**
 * @template [T=any]
 * @param {any} value
 * @returns {value is PromiseLike<T>}
 */
export function is_promise(value) {
	return typeof value?.then === 'function';
}
 
/** @param {Function} fn */
export function run(fn) {
	return fn();
}
 
/** @param {Array<() => void>} arr */
export function run_all(arr) {
	for (var i = 0; i < arr.length; i++) {
		arr[i]();
	}
}
 
/**
 * @param {Function} fn
 */
export function call_once(fn) {
	let called = false;
	/** @type {unknown} */
	let result;
	return function () {
		if (!called) {
			called = true;
			result = fn();
		}
		return result;
	};
}