mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-25 07:49:15 +08:00
fix(utils): circular dependency
This commit is contained in:
parent
4c369cb266
commit
7007fcf9ea
39
src/utils/base.ts
Normal file
39
src/utils/base.ts
Normal 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>);
|
||||
}
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* requestAnimationFrame polyfill
|
||||
*/
|
||||
|
||||
import { inBrowser } from '..';
|
||||
import { inBrowser } from '../base';
|
||||
|
||||
let prev = Date.now();
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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>);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { inBrowser } from '..';
|
||||
import { inBrowser } from '../base';
|
||||
|
||||
export function isAndroid(): boolean {
|
||||
return inBrowser ? /android/.test(navigator.userAgent.toLowerCase()) : false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user