当前位置:网站首页>vant 源码解析之 utils/index.ts 工具函数
vant 源码解析之 utils/index.ts 工具函数
2022-07-05 20:58:00 【丰的传说】
源代码
import Vue from 'vue';
export { use } from './use';
export const isServer: boolean = Vue.prototype.$isServer;
//Vue 原型上自带的属性 判断上是否运行在服务端上
export function noop() {}
export function isDef(value: any): boolean {
// value:any 表示传入的参数是任意类型 boolean 表示返回值是boolean类型
return value !== undefined && value !== null;
// 传入的值不能是undefined 也不能是null
}
// in 15.686s 0.486s
export function isObj(x: any): boolean {
//判断一个值是否是 对象类型
// 传入的参数 是 any 任意类型i
// 返回值是 boolean
const type = typeof x;
// typeof 判断数据类型
// typeof 判断数据类型时 null 也是 object 所以 type 不能为null
// 函数也是 对象
return x !== null && (type === 'object' || type === 'function');
}
export function get(object: any, path: string): any {
const keys = path.split('.');
let result = object;
keys.forEach(key => {
result = isDef(result[key]) ? result[key] : '';
});
return result;
}
const camelizeRE = /-(\w)/g;//\w 表示数字字母吓下划线
export function camelize(str: string): string {
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
//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());
// 只有在非服务端
//判断是否是 ios设备
}
export function range(num: number, min: number, max: number): number {
// Math.max 返回一组数中的最大者
// Math.min 返沪一组数种的最小者
return Math.min(Math.max(num, min), max);
}
export function isInDocument(element: HTMLElement): boolean {
// 在ts j中 dom 节点的type类型是 HTMLElement
// 返回值是boolean
return document.body.contains(element);
// document.body 节点 是否包含目标节点
}
边栏推荐
- 珍爱网微服务底层框架演进从开源组件封装到自研
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
- Prosci LAG-3 recombinant protein specification
- Abnova cyclosporin a monoclonal antibody and its research tools
- Duchefa MS medium contains vitamin instructions
- SYSTEMd resolved enable debug log
- Abnova DNA marker high quality control test program
- 使用WebAssembly在浏览器端操作Excel
- 显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
- Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
猜你喜欢
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
Abnova blood total nucleic acid purification kit pre installed relevant instructions
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
最长摆动序列[贪心练习]
Duchefa丨S0188盐酸大观霉素五水合物中英文说明书
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
木板ISO 5660-1 热量释放速率摸底测试
leetcode:1139. 最大的以 1 为边界的正方形
台风来袭!建筑工地该如何防范台风!
随机推荐
Norgen AAV提取剂盒说明书(含特色)
Careercup its 1.8 serial shift includes problems
2.<tag-哈希表, 字符串>补充: 剑指 Offer 50. 第一个只出现一次的字符 dbc
Implementation of redis unique ID generator
CareerCup它1.8 串移包括问题
Specification of protein quantitative kit for abbkine BCA method
判断横竖屏的最佳实现
Write an interface based on flask
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
PVC 塑料片BS 476-6 火焰传播性能测定
AITM 2-0003 水平燃烧试验
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Duchefa MS medium contains vitamin instructions
Open source SPL eliminates tens of thousands of database intermediate tables
木板ISO 5660-1 热量释放速率摸底测试
Duchefa low melting point agarose PPC Chinese and English instructions
Duchefa丨P1001植物琼脂中英文说明书
驱动壳美国测试UL 2043 符合要求有哪些?
The development of research tourism practical education helps the development of cultural tourism industry
树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因