fix(utils): circular dependency

This commit is contained in:
chenjiahan 2020-09-28 17:48:07 +08:00
parent 4c369cb266
commit 7007fcf9ea
7 changed files with 46 additions and 45 deletions

39
src/utils/base.ts Normal file
View File

@ -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<T>(val: T): val is NonNullable<T> {
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<any, any> {
return val !== null && typeof val === 'object';
}
export function isPromise<T = any>(val: unknown): val is Promise<T> {
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<string, any>, keys: string[]) {
return keys.reduce((ret, key) => {
ret[key] = obj[key];
return ret;
}, {} as Record<string, any>);
}

View File

@ -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) {

View File

@ -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) {

View File

@ -2,7 +2,7 @@
* requestAnimationFrame polyfill
*/
import { inBrowser } from '..';
import { inBrowser } from '../base';
let prev = Date.now();

View File

@ -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 {

View File

@ -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<T>(val: T): val is NonNullable<T> {
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<any, any> {
return val !== null && typeof val === 'object';
}
export function isPromise<T = any>(val: unknown): val is Promise<T> {
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<string, any>, keys: string[]) {
return keys.reduce((ret, key) => {
ret[key] = obj[key];
return ret;
}, {} as Record<string, any>);
}

View File

@ -1,4 +1,4 @@
import { inBrowser } from '..';
import { inBrowser } from '../base';
export function isAndroid(): boolean {
return inBrowser ? /android/.test(navigator.userAgent.toLowerCase()) : false;