当前位置:网站首页>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 节点 是否包含目标节点
}
边栏推荐
- 台风来袭!建筑工地该如何防范台风!
- hdu2377Bus Pass(构建更复杂的图+spfa)
- Maker education infiltrating the transformation of maker spirit and culture
- CLion配置visual studio(msvc)和JOM多核编译
- 【案例】元素的显示与隐藏的运用--元素遮罩
- Abnova CRISPR spcas9 polyclonal antibody protocol
- bazel是否有学习的必要
- AITM2-0002 12s或60s垂直燃烧试验
- Interpreting the daily application functions of cooperative robots
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
猜你喜欢

Abbkine trakine F-actin Staining Kit (green fluorescence) scheme
![最长摆动序列[贪心练习]](/img/e1/70dc21b924232c7e5e3da023a4bed2.png)
最长摆动序列[贪心练习]

leetcode:1755. 最接近目标值的子序列和

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

Duchefa cytokinin dihydrozeatin (DHZ) instructions

Clion-MinGW编译后的exe文件添加ico图标

Abnova e (diii) (WNV) recombinant protein Chinese and English instructions

Analyze the knowledge transfer and sharing spirit of maker Education

ClickHouse 复制粘贴多行sql语句报错

Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
随机推荐
10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
Monorepo management methodology and dependency security
ts 之 属性的修饰符public、private、protect
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
示波器探头对信号源阻抗的影响
Abnova DNA marker high quality control test program
解析五育融合之下的steam教育模式
Sophomore personal development summary
ts 之 类的简介、构造函数和它的this、继承、抽象类、接口
Clion-MinGW编译后的exe文件添加ico图标
当Steam教育进入个性化信息技术课程
重上吹麻滩——段芝堂创始人翟立冬游记
基于flask写一个接口
基于AVFoundation实现视频录制的两种方式
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
【案例】定位的运用-淘宝轮播图
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
Analyze the knowledge transfer and sharing spirit of maker Education
matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
Chemical properties and application instructions of prosci Lag3 antibody