@aliretail/react-utils
Version:
37 lines (36 loc) • 1.04 kB
TypeScript
/**
* 环境判断等相关工具
*/
export declare const ENV: {
local: string;
daily: string;
pre: string;
prod: string;
};
declare type Keys = keyof typeof ENV;
declare type ENV_VARIABLES = typeof ENV[Keys];
declare global {
interface Window {
_APIMAP_ENV: ENV_VARIABLES;
}
}
/**
* 根据传入 hostname 判断当前处于什么环境
*
* - 首先从 window._APIMAP_ENV 取,如果是有效返回值之一,那么返回该值;
* - 否则根据 hostname 来判断,如果没显式传 hostname,那么用 location.hostname
*
* @param {string} hostname 传入的 hostname,如果不传,那么默认为 location.hostname
* @returns {ENV_VARIABLES} 返回 local、development、pre 或 production 之一
*/
export declare function getCurrentEnv(hostname?: string): ENV_VARIABLES;
declare const utils: {
env: string;
get(): any;
set(newEnv: ENV_VARIABLES): void;
isLocal(): boolean;
isDaily(): boolean;
isPre(): boolean;
isProd(): boolean;
};
export default utils;