当前位置:网站首页>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
}
边栏推荐
- bazel是否有学习的必要
- 解析创客教育的知识迁移和分享精神
- Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
- Influence of oscilloscope probe on signal source impedance
- php中explode函数存在的陷阱
- Norgen AAV extractant box instructions (including features)
- 挖财商学院给的证券账户安全吗?可以开户吗?
- SYSTEMd resolved enable debug log
- Duchefa丨P1001植物琼脂中英文说明书
- 模式-“里氏替换原则”
猜你喜欢
MySQL InnoDB架构原理
线程池的使用
Use of thread pool
Chemical properties and application instructions of prosci Lag3 antibody
MySQL fully parses json/ arrays
渗透创客精神文化转化的创客教育
Abnova CRISPR spcas9 polyclonal antibody protocol
PVC 塑料片BS 476-6 火焰传播性能测定
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
Pytorch实战——MNIST数据集手写数字识别
随机推荐
Learning notes of SAS programming and data mining business case 19
Clear app data and get Icon
教你自己训练的pytorch模型转caffe(一)
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
浅聊我和一些编程语言的缘分
PHP deserialization +md5 collision
Norgen AAV extractant box instructions (including features)
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
EN 438-7建筑覆盖物装饰用层压板材产品—CE认证
systemd-resolved 开启 debug 日志
The reason why the ncnn converted model on raspberry pie 4B always crashes when called
Influence of oscilloscope probe on signal source impedance
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
ts 之 属性的修饰符public、private、protect
ODPs next map / reduce preparation
LeetCode_哈希表_困难_149. 直线上最多的点数
Is the securities account given by the school of Finance and business safe? Can I open an account?
字典树简单入门题(居然是蓝题?)
Abnova丨血液总核酸纯化试剂盒预装相关说明书
Prosci LAG-3 recombinant protein specification