当前位置:网站首页>Utils/index TS tool function
Utils/index TS tool function
2022-07-05 20:58:00 【The legend of Feng】
Source code
import Vue from 'vue';
export { use } from './use';
export const isServer: boolean = Vue.prototype.$isServer;
//Vue The attributes of the prototype Determine whether it is running on the server
export function noop() {}
export function isDef(value: any): boolean {
// value:any Indicates that the parameter passed in is of any type boolean Indicates that the return value is boolean type
return value !== undefined && value !== null;
// The value passed in cannot be undefined Nor is null
}
// in 15.686s 0.486s
export function isObj(x: any): boolean {
// Judge whether a value is object type
// Incoming parameter yes any Any type i
// The return value is boolean
const type = typeof x;
// typeof Judge data type
// typeof When judging the data type null It's also object therefore type Not for null
// The function is also object
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 Indicates the underscore of numbers and letters
export function camelize(str: string): string {
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
//toUpperCase Convert letters to Capitalization
}
export function isAndroid(): boolean {
/* istanbul ignore next */
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
// Only on the non server side
// Determine whether it is an Android device
}
export function isIOS(): boolean {
/* istanbul ignore next */
return isServer ? false : /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
// Only on the non server side
// Judge whether it is ios equipment
}
export function range(num: number, min: number, max: number): number {
// Math.max Returns the largest number in a group
// Math.min The smallest of a group of several kinds returning to Shanghai
return Math.min(Math.max(num, min), max);
}
export function isInDocument(element: HTMLElement): boolean {
// stay ts j in dom Node type The type is HTMLElement
// The return value is boolean
return document.body.contains(element);
// document.body node Whether to include the target node
}
边栏推荐
- 示波器探头对信号源阻抗的影响
- Enclosed please find. Net Maui's latest learning resources
- 解析五育融合之下的steam教育模式
- Implementation of redis unique ID generator
- wpf 获取datagrid 中指定行列的DataGridTemplateColumn中的控件
- leetcode:1139. 最大的以 1 为边界的正方形
- 渗透创客精神文化转化的创客教育
- Interpreting the daily application functions of cooperative robots
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
- 树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
猜你喜欢
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
Pytorch实战——MNIST数据集手写数字识别
Abnova丨血液总核酸纯化试剂盒预装相关说明书
Interpreting the daily application functions of cooperative robots
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Abnova丨DNA 标记高质量控制测试方案
五层网络协议
Enclosed please find. Net Maui's latest learning resources
Abnova fluorescent dye 620-m streptavidin scheme
leetcode:1755. 最接近目标值的子序列和
随机推荐
How to open an account online for futures? Is it safe?
AITM2-0002 12s或60s垂直燃烧试验
ODPS 下一个map / reduce 准备
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
《SAS编程和数据挖掘商业案例》学习笔记# 19
如何让化工企业的ERP库存账目更准确
【案例】定位的运用-淘宝轮播图
实现浏览页面时校验用户是否已经完成登录的功能
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
leetcode:1139. 最大的以 1 为边界的正方形
Abnova cyclosporin a monoclonal antibody and its research tools
清除app data以及获取图标
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
使用WebAssembly在浏览器端操作Excel
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
Material design component - use bottomsheet to show extended content (II)
教你自己训练的pytorch模型转caffe(二)
Learning notes of SAS programming and data mining business case 19
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions