h-fun-tool
v0.0.7
Published
```js npm i h-fun-tool ```
Readme
使用:
npm i h-fun-tool import {regExp, obj,type,utils,url} from 'h-fun-tool'obj模块
clone ⇒
克隆对象(浅克隆)
举例: const obj = {name: 'ZCoder', info: {name: 'ZCoder'}} const objClone = clone(obj) obj === objClone // => false obj.info === objClone.info // => true
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | origin | Object | | result | Object |
deepClone ⇒
深克隆 说明:使用 WeakMap 存储中间数据,避免递归进入死循环导致栈内存溢出了 举例: const obj = {name: 'ZCoder', info: {name: 'ZCoder'}} const objClone = deepClone(obj) obj === objClone // => false obj.info === objClone.info // => false
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | data | Object | | weak | Map |
extend ⇒
合并对象 举例: const obj = {name: 'ZCoder', info: {name: 'ZCoder'}} extend(obj, {email: '123'}) => {name: 'ZCoder', info: {name: 'ZCoder'}, email: '123'}
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | target | Object | | ...args | Object |
filterKeys ⇒
根据保留/删除(keep/remove)类型过滤字段 说明:如果type='keep',则keys为要保留的字段名称列表,否则keys为要删除的字段名称组成的数组 示例:let fun = filterKeys('keep') let filterFun = fun({a:1,b:1}, ['a']) => {a:1}
示例:let fun = filterKeys() let filterFun = fun({a:1,b:1}, ['a']) => {b:1}
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | type | String | | obj | Object | | keys | Array |
keepKeys
保留给定字段 举例: keepKeys({id: 123, name: 'ZCoder', email: '123'}, ['id', 'name']) => {id: 123, name: 'ZCoder'}
Kind: global constant
| Param | Type | | --- | --- | | obj | Object | | keys | Array |
removeKeys
删除给定字段 举例: keepKeys({id: 123, name: 'ZCoder', email: '123'}, ['id', 'name']) => {email: '123'}
Kind: global constant
| Param | Type | | --- | --- | | obj | Object | | keys | Array |
replaceKeys ⇒
替换对象字段名 说明:rules 参数为键值对,key-要替换的字段名,value-新的字段名 举例:replaceKeys({id: 123, name: 'ZCoder', email: '123'},{name: 'username', email: 'userEmail'}) => {id: 123, username: "ZCoder", userEmail: "123"}
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | obj | Object | | rules | Object |
url模块
getParam2Json
将链接参数转为JSON格式返回 举例: getParam2Json('http://www.baidu.com?name=ZCoder&email=xxx126') => {name: "ZCoder", email: "xxx126"}
Kind: global constant
| Param | Type | | --- | --- | | url | String |
getUrlParam
获取链接指定字段名的值 说明:如果参数key为字符串数组则返回key-value对象 举例: getUrlParam('name', 'http://www.baidu.com?name=ZCoder&email=xxx126') => "ZCoder"
Kind: global constant
| Param | Type | | --- | --- | | key | String | | url | String |
getJson2Param
转换JSON为链接参数字符串 说明:参数json为key-value对象,如:{name: 'ZCoder'} 举例: getJson2Param({name: 'ZCoder', email: 'xxx126'}) => "name=ZCoder&email=xxx126"
Kind: global constant
| Param | Type | | --- | --- | | json | Object |
addParam2Url
添加参数到链接上 说明:参数params为key-value对象,如:{name: 'ZCoder'} 举例: addParam2Url({name: 'ZCoder'}, 'http://www.baidu.com?email=xxx126') => "http://www.baidu.com?email=xxx126&name=ZCoder"
Kind: global constant
| Param | Type | | --- | --- | | params | Object | | url | String |
removeParamFromUrl
删除链接指定的参数 说明:参数params如果为字符串时,多个字段名用英文','连接,如果为字符串数组是,则每个元素对应一个字段名,如果不传或者传的时空字符串或者空数组则删除全部参数 举例: removeParamFromUrl('http://www.baidu.com?name=ZCoder&email=xxx126', 'name') => "http://www.baidu.com?email=xxx126"
removeParamFromUrl('http://www.baidu.com?name=ZCoder&email=xxx126', ['name', 'email']) => "http://www.baidu.com"
removeParamFromUrl3('http://www.baidu.com?name=ZCoder&email=xxx126') => "http://www.baidu.com"
Kind: global constant
| Param | Type | | --- | --- | | url | String | | params | String |
type模块
isType ⇒
获取各种数据数据类型 示例: isType('String')('1')
Kind: global constant
Returns: anyBoolean
| Param | Type | | --- | --- | | type | String |
isObject ⇒
判断是否为对象
Kind: global constant
Returns: anyBoolean
| Param | Type | | --- | --- | | val | * |
isEmpty ⇒
判断是否为 null 或 undefined
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | * |
isArray ⇒
判断是否为数组
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | * |
isNumber ⇒
判断是否为 Number 类型
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | Number |
isString ⇒
判断是否为 String 类型
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | String |
utils模块
Functions
throttle ⇒
节流
说明:用于有连续事件响应,每间隔一定时间触发一次 func: 回调 interval: 触发长度间隔时间 leading: leading=false首次不会触发(如果触发了多次)
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | func | function | | interval | Number | | leading | Boolean |
debounce ⇒
防抖 说明:用于连续事件触发结束后只触发一次 func:回调 wait:触发长度间隔时间 immediate:是否立即执行
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | func | function | | wait | Number | | immediate | Boolean |
copy ⇒
复制到剪切板(异步方式) 举例: copy('内容') .then(() => { console.log('复制成功') }) .catch(err => { console.log(err) })
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | str | String |
getSign(params) ⇒
获取签名
Kind: global function
Returns: any
| Param | Type | | --- | --- | | params | * |
regExp模块
isLink ⇒
是否为合法链接
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | String |
isEMail ⇒
是否为合法邮箱
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | String |
isTel ⇒
是否为合法手机号码
Kind: global constant
Returns: any
| Param | Type | | --- | --- | | val | String |
