blob: 0066cfe24e0ee081b6e97231207f7fb4439338ff (
plain) (
blame)
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
|
import {isMobileSafari} from 'webext-detect-page';
import {Promisable} from 'type-fest';
import {pEveryFunction, pSomeFunction} from './p-utils.js';
export type BooleanFunction = () => boolean;
export type PromisableBooleanFunction = () => Promisable<boolean>;
export type RunConditions = {
/** Every condition must be true */
asLongAs?: PromisableBooleanFunction[];
/** At least one condition must be true */
include?: PromisableBooleanFunction[];
/** No conditions must be true */
exclude?: PromisableBooleanFunction[];
};
export function isFeaturePrivate(id: string): boolean {
return id.startsWith('rgh-');
}
export const doesBrowserActionOpenOptions = isMobileSafari();
export async function shouldFeatureRun({
/** Every condition must be true */
asLongAs = [() => true],
/** At least one condition must be true */
include = [() => true],
/** No conditions must be true */
exclude = [() => false],
}: RunConditions): Promise<boolean> {
return await pEveryFunction(asLongAs, c => c())
&& await pSomeFunction(include, c => c())
&& pEveryFunction(exclude, async c => !await c());
}
|