UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

52 lines (49 loc) 1.08 kB
import { get } from '../lodash-mini/get.mjs'; import { setWithString } from '../lodash-mini/set-with-string.mjs'; import '@babel/runtime/helpers/typeof'; import '../validate/is-index.mjs'; var mConfig; /** * 初始化config * @param {ConfigType} config */ function initConfig(config) { mConfig = config; } /** * 获取config * @param {string} name * @return {*} {*} * * @example * getConfig('login.loginType') * getConfig('game') */ function getConfig(name) { if (!mConfig) { throw new Error('config need init'); } if (!name) { console.warn('[getConfig] 请传入name进行取值,使用setConfig,避免直接赋值'); return mConfig; } var value = get(mConfig, name); if (value) return value; return value; } /** * 设置config * * @param {string} name * @param {*} value * * @example * setConfig('login.loginType','WXPC') */ function setConfig(name, value) { if (!mConfig) { throw new Error('[setConfig] config need init'); } mConfig = setWithString(mConfig, name, value); } export { getConfig, initConfig, setConfig };