当前位置:网站首页>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 节点 是否包含目标节点
}
边栏推荐
- Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
- Chemical properties and application instructions of prosci Lag3 antibody
- PHP反序列化+MD5碰撞
- 教你自己训练的pytorch模型转caffe(一)
- Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
- Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
- 判断横竖屏的最佳实现
- Cutting edge technology for cultivating robot education creativity
- Abnova fluorescent dye 620-m streptavidin scheme
- 示波器探头对测量带宽的影响
猜你喜欢
Abnova CRISPR spcas9 polyclonal antibody protocol
Typhoon is coming! How to prevent typhoons on construction sites!
Clion-MinGW编译后的exe文件添加ico图标
Duchefa MS medium contains vitamin instructions
Abbkine trakine F-actin Staining Kit (green fluorescence) scheme
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??
教你自己训练的pytorch模型转caffe(二)
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
如何让化工企业的ERP库存账目更准确
重上吹麻滩——段芝堂创始人翟立冬游记
随机推荐
Simple getting started example of Web Service
Analyze the knowledge transfer and sharing spirit of maker Education
Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
挖财商学院给的证券账户安全吗?可以开户吗?
Abnova fluorescent dye 620-m streptavidin scheme
POJ 3414 pots (bfs+ clues)
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
Material design component - use bottomsheet to show extended content (II)
ts 之 属性的修饰符public、private、protect
PHP deserialization +md5 collision
Talk about my fate with some programming languages
《SAS编程和数据挖掘商业案例》学习笔记# 19
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
Learning notes of SAS programming and data mining business case 19
CLion配置visual studio(msvc)和JOM多核编译
Use of thread pool
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
Enclosed please find. Net Maui's latest learning resources
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel