x-js-tools
TypeScript icon, indicating that this package has built-in type declarations

2.6.11 • Public • Published

这是一个用于web开发的js工具函数库

使用方法示例:

 npm i x-js-tools
 import { arrToTree } from x-js-tools
函数名称 入参 回参 功能描述
arrToTree { pid: string | number; id: string | number; [k: string]: any }[] object[] 将一维数组转化为树状数据
treeToArr { [k: string]: any; children: &[] | undefined; } any[] 将树状数据转为一维数组
isContentEqual a: any, b: any boolean 比较基本类型、数组、纯对象数据的内容是否相等
anyArrSort arr: any[], order = 1, key: string any[] 对任何类型元素数组进行排序
isEffectiveValue any boolean 判断是否是有效值:value不为null、undefined、""、{}、[]
isBasicType any boolean 判断是否基本类型
isPureObject any boolean 判断变量是不是纯对象
isArray any boolean 判断是否数组
isNull any boolean 判断是否为null
isString any boolean 判断是否字符串
getRandomNumberInClosedInterval left: number, right: number number 获取闭区间内的随机数
getFullArrangement string string[] 获取全排列后的字符串数组
antiShaking fn: Function, delay: number, immediate: boolean = true Functon 防抖函数
deepClone val: any any 深拷贝
getCopiedText elementId: string void 拷贝文本 ,系统剪贴板获取到了拷贝内容
getRandomColor string 获取随机颜色值(16进制字符串形式)
throttle fn: Function, delay: number Function 节流函数
hLine2Hump str: string, line: '_'或者'-' string 将横线转为驼峰命名(横线可以是-或者_)
hump2HLine str: string, line: string string 将驼峰命名的字符串转为横线形式的字符串
isChinesePhoneFormat phone: string boolean 验证中国座机电话格式
isEmail email: string boolean 验证邮箱格式
addClass domSelector: string, className: string void 给元素添加类名
hasClass domSelector: string, className: string boolean 判断元素是否有某个类
removeClass domSelector: string, className: string void 去除类名
toggleClass domSelector: string, className: string void 切换类名
getMousePosition event: MouseEvent, type: 'client'/'offsetToParent'/'scrollToDoc' { x: number, y: number } 获取鼠标位置坐标
sleep millisecond: number Promise 延迟毫秒

This is a JS tool function library for web development

Example of usage:

import { arrToTree } from x-js-tools
Function Name Enter parameters Back reference Function description
arrToTree { pid: string | number; id: string | number; [k: string]: any }[] object[] Convert one-dimensional array to tree data
treeToArr { [k: string]: any; children: &[] | undefined; } any[] Convert tree data into one-dimensional array
isContentEqual a: any, b: any boolean Compare whether the contents of basic type, array and pure object data are equal
anyArrSort arr: any[], order = 1, key: string any[] Sort an array of elements of any type
isEffectiveValue any boolean Judge whether it is a valid value: value is not null, undefined, '', {}, []
isBasicType any boolean Judge whether the basic type is
isPureObject any boolean Judge whether the variable is a pure object
isArray any boolean Determine whether it is an array
isNull any boolean Judge whether it is null
isString any boolean Judge whether string
getRandomNumberInClosedInterval left: number, right: number number Obtain random numbers within a closed interval
getFullArrangement string string[] Obtain a fully arranged string array
antiShaking fn: Function, delay: number, immediate: boolean = true Functon Anti shake function
deepClone val: any any deep copy
getCopiedText elementId: string void Copy the text, the system clipboard obtained the copied content
getRandomColor string Obtain random color values (in hexadecimal string format)
throttle fn: Function, delay: number Function Throttling function
hLine2Hump str: string, line: '_' or '-' string Convert the horizontal line to a hump name (the horizontal line can be either - or _)
hump2HLine str: string, line: string string Convert the named string of the hump to a horizontal string
isChinesePhoneFormat phone: string boolean Verify Chinese landline phone format
isEmail email: string boolean Verify email format
addClass domSelector: string, className: string void Add a class name to an element
hasClass domSelector: string, className: string boolean Determine if an element has a certain class
removeClass domSelector: string, className: string void remove class
toggleClass domSelector: string, className: string void toggle class
getMousePosition event: MouseEvent, type: 'client'/'offsetToParent'/'scrollToDoc' { x: number, y: number } Obtain mouse position coordinates
sleep millisecond: number Promise Delay in milliseconds

Readme

Keywords

Package Sidebar

Install

npm i x-js-tools

Weekly Downloads

3

Version

2.6.11

License

ISC

Unpacked Size

49.6 kB

Total Files

62

Last publish

Collaborators

  • liu-er