From 7007fcf9eaea239f5e680068d59d8e9f8202ec3b Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Mon, 28 Sep 2020 17:48:07 +0800 Subject: [PATCH] fix(utils): circular dependency --- src/utils/base.ts | 39 +++++++++++++++++++++++++++++++++ src/utils/create/component.ts | 2 +- src/utils/create/i18n.ts | 3 ++- src/utils/dom/raf.ts | 2 +- src/utils/format/unit.ts | 2 +- src/utils/index.ts | 41 +---------------------------------- src/utils/validate/system.ts | 2 +- 7 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 src/utils/base.ts diff --git a/src/utils/base.ts b/src/utils/base.ts new file mode 100644 index 000000000..5df8c8bbb --- /dev/null +++ b/src/utils/base.ts @@ -0,0 +1,39 @@ +// eslint-disable-next-line @typescript-eslint/no-empty-function +export function noop() {} + +export const inBrowser = typeof window !== 'undefined'; + +export function isDef(val: T): val is NonNullable { + return val !== undefined && val !== null; +} + +// eslint-disable-next-line @typescript-eslint/ban-types +export function isFunction(val: unknown): val is Function { + return typeof val === 'function'; +} + +export function isObject(val: unknown): val is Record { + return val !== null && typeof val === 'object'; +} + +export function isPromise(val: unknown): val is Promise { + return isObject(val) && isFunction(val.then) && isFunction(val.catch); +} + +export function get(object: any, path: string): any { + const keys = path.split('.'); + let result = object; + + keys.forEach((key) => { + result = result[key] ?? ''; + }); + + return result; +} + +export function pick(obj: Record, keys: string[]) { + return keys.reduce((ret, key) => { + ret[key] = obj[key]; + return ret; + }, {} as Record); +} diff --git a/src/utils/create/component.ts b/src/utils/create/component.ts index 72fcaab29..711476143 100644 --- a/src/utils/create/component.ts +++ b/src/utils/create/component.ts @@ -2,7 +2,7 @@ * Create a basic component with common options */ import { App, defineComponent, ComponentOptionsWithObjectProps } from 'vue'; -import { camelize } from '..'; +import { camelize } from '../format/string'; export function createComponent(name: string) { return function (sfc: ComponentOptionsWithObjectProps) { diff --git a/src/utils/create/i18n.ts b/src/utils/create/i18n.ts index 69a1040db..456289551 100644 --- a/src/utils/create/i18n.ts +++ b/src/utils/create/i18n.ts @@ -1,4 +1,5 @@ -import { get, camelize, isFunction } from '..'; +import { get, isFunction } from '../base'; +import { camelize } from '../format/string'; import locale from '../../locale'; export function createI18N(name: string) { diff --git a/src/utils/dom/raf.ts b/src/utils/dom/raf.ts index e87308dbb..0af210e98 100644 --- a/src/utils/dom/raf.ts +++ b/src/utils/dom/raf.ts @@ -2,7 +2,7 @@ * requestAnimationFrame polyfill */ -import { inBrowser } from '..'; +import { inBrowser } from '../base'; let prev = Date.now(); diff --git a/src/utils/format/unit.ts b/src/utils/format/unit.ts index 941a3261c..9a15c5bde 100644 --- a/src/utils/format/unit.ts +++ b/src/utils/format/unit.ts @@ -1,4 +1,4 @@ -import { isDef, inBrowser } from '..'; +import { isDef, inBrowser } from '../base'; import { isNumeric } from '../validate/number'; export function addUnit(value?: string | number): string | undefined { diff --git a/src/utils/index.ts b/src/utils/index.ts index 55c2d802b..01ff55df8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,3 +1,4 @@ +export * from './base'; export * from './create'; export * from './format/unit'; export * from './format/number'; @@ -6,43 +7,3 @@ export * from './dom/raf'; export * from './dom/style'; export * from './dom/event'; export * from './dom/scroll'; - -// eslint-disable-next-line @typescript-eslint/no-empty-function -export function noop() {} - -export const inBrowser = typeof window !== 'undefined'; - -export function isDef(val: T): val is NonNullable { - return val !== undefined && val !== null; -} - -// eslint-disable-next-line @typescript-eslint/ban-types -export function isFunction(val: unknown): val is Function { - return typeof val === 'function'; -} - -export function isObject(val: unknown): val is Record { - return val !== null && typeof val === 'object'; -} - -export function isPromise(val: unknown): val is Promise { - return isObject(val) && isFunction(val.then) && isFunction(val.catch); -} - -export function get(object: any, path: string): any { - const keys = path.split('.'); - let result = object; - - keys.forEach((key) => { - result = result[key] ?? ''; - }); - - return result; -} - -export function pick(obj: Record, keys: string[]) { - return keys.reduce((ret, key) => { - ret[key] = obj[key]; - return ret; - }, {} as Record); -} diff --git a/src/utils/validate/system.ts b/src/utils/validate/system.ts index ec0331241..1667621b1 100644 --- a/src/utils/validate/system.ts +++ b/src/utils/validate/system.ts @@ -1,4 +1,4 @@ -import { inBrowser } from '..'; +import { inBrowser } from '../base'; export function isAndroid(): boolean { return inBrowser ? /android/.test(navigator.userAgent.toLowerCase()) : false;