///
///
import type { EmptyInterface } from '../@types';
/**
*
*/
export declare type EnvironmentUnion = 'wxmina' | 'web' | 'node' | 'unknown';
/**
* Predicate whether the enviroment is Wexin Mini Program (MINA: MINA is not App).
* NOTE: `typeof` operator can operate on non-exist variable.
*
* @check `wx`, `wx.canIUse`
*/
export declare const isInWXMINAEnvironment: () => boolean;
/**
* Predicate whether the enviroment is Web.
*
* @check `document`, `window`
*/
export declare const isInWebEnvironment: () => boolean;
/**
* Predicate whether the enviroment is Browser.
*
* @check `document`, `window`
*
* @see {@link isInWebEnvironment}
*/
export declare const isInBrowserEnvironment: () => boolean;
/**
* Predicate whether the enviroment is Node.js.
*
* @check `global`, `process`
*/
export declare const isInNodeEnvironment: () => boolean;
interface CommonContexts {
globalThis: typeof globalThis;
}
export interface WebEnvContexts extends CommonContexts {
window: Window & typeof globalThis;
document: Document;
fetch: typeof fetch;
}
export interface NodeEnvContexts extends CommonContexts {
global: typeof globalThis;
process: typeof process;
}
export interface WXMINAEnvContexts extends CommonContexts {
wxmina: WechatMiniprogram.Wx;
}
export interface DefaultEnvContexts extends CommonContexts {
}
export declare const WEB_ENV_CONTEXTS: WebEnvContexts;
export declare const NODE_ENV_CONTEXTS: NodeEnvContexts;
export declare const WXMINA_ENV_CONTEXTS: WXMINAEnvContexts;
export declare const DEFAULT_ENV_CONTEXTS: DefaultEnvContexts;
export interface MultipleEnvironmentsAdaptions {
forWeb: (contexts: WebEnvContexts) => R;
forNode: (contexts: NodeEnvContexts) => R;
forWXMINA: (contexts: WXMINAEnvContexts) => R;
forDefault: (contexts: DefaultEnvContexts) => R;
}
export interface AsyncMultipleEnvironmentsAdaptions {
forWeb: (contexts: WebEnvContexts) => R | Promise;
forNode: (contexts: NodeEnvContexts) => R | Promise;
forWXMINA: (contexts: WXMINAEnvContexts) => R | Promise;
forDefault: (contexts: DefaultEnvContexts) => R | Promise;
}
/**
* (sync version of adaptMultiPlatformAsync) Run different function according to the environment.
*
* @see {@link adaptMultipleEnvironmentsAsync}
*/
export declare const adaptMultipleEnvironments: (adaptions: Partial>) => R;
/**
* (async version of adaptMultiPlatform) Run different function according to the environment.
*
* @see {@link adaptMultipleEnvironments}
*/
export declare const adaptMultipleEnvironmentsAsync: (adaptions: Partial>) => Promise;
declare type ParsersOfVariables = {
[K in keyof Variables]?: (value: string) => Variables[K];
};
interface EnvironmentVariableManagerOptions {
variables?: Variables;
parsers?: ParsersOfVariables;
}
/**
* 用于以类型安全的方式获取环境变量。
*
* @example
* interface ENV {
* DATABASE: string
* URL: string
* }
* const appEnvironmentVariableManager = EnvironmentVariableManager.of()
* const database = appEnvironmentVariableManager.get('DATABASE') // success
* const name = appEnvironmentVariableManager.get('NAME') // type check passed
* const safeName = appEnvironmentVariableManager.safeGet('NAME') // type check error
*/
export declare class EnvironmentVariableManager {
_variables: Variables;
_parsers: ParsersOfVariables;
constructor(options?: EnvironmentVariableManagerOptions);
resetVariables(): void;
get variables(): Variables;
static of(options?: EnvironmentVariableManagerOptions): EnvironmentVariableManager;
/**
* Get the value of the environment variable.
*
* @see {@link safeGet}, {@link recklessGet}
*/
get(key: Key): Variables[Key] | undefined;
/**
* Get the value of the environment variable.
* @see {@link get}, {@link safeGet}
*/
recklessGet(key: Key): Variables[Key];
/**
* Get the value of the environment variable.
* When the target key is not exist in variables, an error will be thrown.
*
* @see {@link get}, {@link recklessGet}
*/
safeGet(key: Key): Variables[Key];
}
export {};
//# sourceMappingURL=environment.d.ts.map