当前位置:网站首页>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 节点 是否包含目标节点
}
边栏推荐
- 线程池的使用
- 当Steam教育进入个性化信息技术课程
- 木板ISO 5660-1 热量释放速率摸底测试
- Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
- How to renew NPDP? Here comes the operation guide!
- Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
- Duchefa low melting point agarose PPC Chinese and English instructions
- 基于flask写一个接口
- 重上吹麻滩——段芝堂创始人翟立冬游记
- 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?
猜你喜欢

Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案

Enclosed please find. Net Maui's latest learning resources

浅聊我和一些编程语言的缘分

Specification of protein quantitative kit for abbkine BCA method

Duchefa丨S0188盐酸大观霉素五水合物中英文说明书

学习机器人无从下手?带你体会当下机器人热门研究方向有哪些

台风来袭!建筑工地该如何防范台风!

When steam education enters personalized information technology courses

显示器要申请BS 476-7 怎么送样?跟显示屏一样吗??

Pytorch实战——MNIST数据集手写数字识别
随机推荐
systemd-resolved 开启 debug 日志
Chemical properties and application instructions of prosci Lag3 antibody
研學旅遊實踐教育的開展助力文旅產業發展
ClickHouse 复制粘贴多行sql语句报错
Écrire une interface basée sur flask
leetcode:1139. 最大的以 1 为边界的正方形
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
模式-“里氏替换原则”
Talk about my fate with some programming languages
水泥胶黏剂BS 476-4 不燃性测试
台风来袭!建筑工地该如何防范台风!
中国管理科学研究院凝聚行业专家,傅强荣获智库专家“十佳青年”称号
Duchefa cytokinin dihydrozeatin (DHZ) instructions
Maker education infiltrating the transformation of maker spirit and culture
Duchefa丨S0188盐酸大观霉素五水合物中英文说明书
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
国外LEAD美国简称对照表
Cutting edge technology for cultivating robot education creativity
浅聊我和一些编程语言的缘分
五层网络协议