UNPKG

2.62 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 */
17/// <amd-module name="@tensorflow/tfjs-core/dist/environment" />
18import { Platform } from './platforms/platform';
19declare type FlagValue = number | boolean;
20declare type FlagEvaluationFn = (() => FlagValue) | (() => Promise<FlagValue>);
21export declare type Flags = {
22 [featureName: string]: FlagValue;
23};
24export declare type FlagRegistryEntry = {
25 evaluationFn: FlagEvaluationFn;
26 setHook?: (value: FlagValue) => void;
27};
28/**
29 * The environment contains evaluated flags as well as the registered platform.
30 * This is always used as a global singleton and can be retrieved with
31 * `tf.env()`.
32 *
33 * @doc {heading: 'Environment'}
34 */
35export declare class Environment {
36 global: any;
37 private flags;
38 private flagRegistry;
39 private urlFlags;
40 platformName: string;
41 platform: Platform;
42 getQueryParams: typeof getQueryParams;
43 constructor(global: any);
44 setPlatform(platformName: string, platform: Platform): void;
45 registerFlag(flagName: string, evaluationFn: FlagEvaluationFn, setHook?: (value: FlagValue) => void): void;
46 getAsync(flagName: string): Promise<FlagValue>;
47 get(flagName: string): FlagValue;
48 getNumber(flagName: string): number;
49 getBool(flagName: string): boolean;
50 getFlags(): Flags;
51 readonly features: Flags;
52 set(flagName: string, value: FlagValue): void;
53 private evaluateFlag;
54 setFlags(flags: Flags): void;
55 reset(): void;
56 private populateURLFlags;
57}
58export declare function getQueryParams(queryString: string): {
59 [key: string]: string;
60};
61/**
62 * Returns the current environment (a global singleton).
63 *
64 * The environment object contains the evaluated feature values as well as the
65 * active platform.
66 *
67 * @doc {heading: 'Environment'}
68 */
69export declare function env(): Environment;
70export declare let ENV: Environment;
71export declare function setEnvironmentGlobal(environment: Environment): void;
72export {};