UNPKG

2.55 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import { Platform } from './platforms/platform';
18declare type FlagValue = number | boolean;
19declare type FlagEvaluationFn = (() => FlagValue) | (() => Promise<FlagValue>);
20export declare type Flags = {
21 [featureName: string]: FlagValue;
22};
23export declare type FlagRegistryEntry = {
24 evaluationFn: FlagEvaluationFn;
25 setHook?: (value: FlagValue) => void;
26};
27/**
28 * The environment contains evaluated flags as well as the registered platform.
29 * This is always used as a global singleton and can be retrieved with
30 * `tf.env()`.
31 *
32 * @doc {heading: 'Environment'}
33 */
34export declare class Environment {
35 global: any;
36 private flags;
37 private flagRegistry;
38 private urlFlags;
39 platformName: string;
40 platform: Platform;
41 getQueryParams: typeof getQueryParams;
42 constructor(global: any);
43 setPlatform(platformName: string, platform: Platform): void;
44 registerFlag(flagName: string, evaluationFn: FlagEvaluationFn, setHook?: (value: FlagValue) => void): void;
45 getAsync(flagName: string): Promise<FlagValue>;
46 get(flagName: string): FlagValue;
47 getNumber(flagName: string): number;
48 getBool(flagName: string): boolean;
49 getFlags(): Flags;
50 readonly features: Flags;
51 set(flagName: string, value: FlagValue): void;
52 private evaluateFlag;
53 setFlags(flags: Flags): void;
54 reset(): void;
55 private populateURLFlags;
56}
57export declare function getQueryParams(queryString: string): {
58 [key: string]: string;
59};
60/**
61 * Returns the current environment (a global singleton).
62 *
63 * The environment object contains the evaluated feature values as well as the
64 * active platform.
65 *
66 * @doc {heading: 'Environment'}
67 */
68export declare function env(): Environment;
69export declare let ENV: Environment;
70export declare function setEnvironmentGlobal(environment: Environment): void;
71export {};