mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
[improvement] adjust utils
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Vue from 'vue';
|
||||
import { isNumber } from './validate/number';
|
||||
|
||||
export { use } from './use';
|
||||
export { suffixPx } from './format/unit';
|
||||
|
||||
export const isServer: boolean = Vue.prototype.$isServer;
|
||||
|
||||
@@ -26,39 +26,3 @@ export function get(object: any, path: string): any {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const camelizeRE = /-(\w)/g;
|
||||
export function camelize(str: string): string {
|
||||
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function isAndroid(): boolean {
|
||||
/* istanbul ignore next */
|
||||
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
|
||||
}
|
||||
|
||||
export function isIOS(): boolean {
|
||||
/* istanbul ignore next */
|
||||
return isServer ? false : /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
|
||||
}
|
||||
|
||||
export function range(num: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(num, min), max);
|
||||
}
|
||||
|
||||
export function isInDocument(element: HTMLElement): boolean {
|
||||
return document.body.contains(element);
|
||||
}
|
||||
|
||||
export function suffixPx(value?: string | number): string | undefined {
|
||||
if (!isDef(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
value = String(value);
|
||||
return isNumber(value) ? `${value}px` : value;
|
||||
}
|
||||
|
||||
export function padZero(num: number | string): string {
|
||||
return (num < 10 ? '0' : '') + num;
|
||||
}
|
||||
|
Reference in New Issue
Block a user