- arrays
- diffElement(arr1, arr2) ⇒
Array
⏏ - diffObject(arr1, arr2, condition) ⇒
Array
⏏
- diffElement(arr1, arr2) ⇒
比较两个数组不同的元素,并收集全部的不同元素
Kind: Exported function
Returns: Array
- [description]
Param | Type | Description |
---|---|---|
arr1 | Array |
[description] |
arr2 | Array |
[description] |
取出数组中不同的对象元素
Kind: Exported function
Returns: Array
- [description]
Param | Type | Description |
---|---|---|
arr1 | Array |
[description] |
arr2 | Array |
[description] |
condition | Array |
对象唯一的条件 function |
Example
const arrA = [{name: "barry", age: 40}, {name: "alex", age: 30}, {name: "andrew", age: 25}]
const arrB = [{name: "vivi", age: 30}, {name: "alex", age: 30}, {name: "andrew", age: 25}]
const unique = diffObject(arrA, arrB, (a, b)=> a.name === b.name && a.age === b.age)
console.log(unique) // [{name: "barry", age: 40}, {name: "vivi", age: 30}]
获取当前时间戳
Kind: Exported function
Returns: number
- [description]
- devices
- getOs() ⇒
string
⏏ - isiOS() ⇒
Boolean
⏏ - isAndroid() ⇒
Boolean
⏏ - isWeiXinEnv() ⇒
Boolean
⏏ - screenWidth() ⇒
number
⏏ - screenHeight() ⇒
number
⏏
- getOs() ⇒
获取当前操作系统类型
Kind: Exported function
Returns: string
- 'iOS | android | WindowsPhone | MacOS | Windows | Linux | unknown'
判断是否处于 iOS 设备运行
Kind: Exported function
Returns: Boolean
- true is running in iOS
判断是否处于 Android 设备运行
Kind: Exported function
Returns: Boolean
- true is running in weixin
判断是否处于微信环境运行
Kind: Exported function
Returns: Boolean
- true is running in weixin
获取屏幕宽度
Kind: Exported function
Returns: number
- screen width
获取屏幕高度
Kind: Exported function
Returns: number
- screen height
- eventBus
- emit(event) ⇒
void
⏏ - on(event, func) ⇒
void
⏏ - off(event) ⇒
void
⏏
- emit(event) ⇒
发布事件
Kind: Exported function
Param | Type | Description |
---|---|---|
event | string |
事件名称 |
订阅事件
Kind: Exported function
Param | Type | Description |
---|---|---|
event | string |
事件名称 |
func | function |
事件处理函数 |
取消订阅 (不传事件名称,则取消所有订阅)
Kind: Exported function
Param | Type | Description |
---|---|---|
event | string |
事件名称 |
- functions
- throttle(func, delay, options) ⇒
function
⏏ - debounce(func, delay, immediate) ⇒
function
⏏
- throttle(func, delay, options) ⇒
节流函数 (在指定的时间内只会执行一次)
Kind: Exported function
Returns: function
- [description]
Param | Type | Description |
---|---|---|
func | function |
要执行的函数 |
delay | number |
延迟执行的毫秒数 |
options | object |
包含两个参数 leading => true 表示节流函数会首次执行 trailing => true 表示节流函数会最后执行一次 |
Example
const throttled = throttle(() => {}, 500)
window.scroll(throttled)
防抖函数 (在指定的时间内,每次触发,都需重新等待指定的时间) 使用场景:提交表单(防止多次提交)
Kind: Exported function
Returns: function
- [description]
Param | Type | Description |
---|---|---|
func | function |
[description] |
delay | number |
[description] |
immediate | boolean |
[description] |
Example
const debounced = debounce(()=>{}, 1000, true)
onPostForm() {
debounced();
}
判断浏览器是否支持 webP 格式
Kind: Exported function
Returns: Boolean
- [description]
- objects
- isArray(obj) ⇒
Boolean
⏏ - deepClone(obj) ⇒
object
⏏
- isArray(obj) ⇒
判断对象是否为数组
Kind: Exported function
Returns: Boolean
- true if is array
Param | Type | Description |
---|---|---|
obj | object |
object |
深拷贝对象
Kind: Exported function
Returns: object
- the deep copy of the object
Param | Type | Description |
---|---|---|
obj | object |
object |
- regexs
- isEmail(str) ⇒
Boolean
⏏ - isIdCard(str) ⇒
Boolean
⏏ - isPhoneNumber(str) ⇒
Boolean
⏏ - isUrl(str) ⇒
Boolean
⏏
- isEmail(str) ⇒
是否是邮箱
Kind: Exported function
Returns: Boolean
- true if is email
Param | Type | Description |
---|---|---|
str | string |
[description] |
是否是身份证
Kind: Exported function
Returns: Boolean
- true if is id-card
Param | Type | Description |
---|---|---|
str | string |
[description] |
是否是手机号
Kind: Exported function
Returns: Boolean
- true if is phone number
Param | Type | Description |
---|---|---|
str | string |
[description] |
是否是 url
Kind: Exported function
Returns: Boolean
- true if is url
Param | Type | Description |
---|---|---|
str | string |
[description] |
解析 GET 请求 参数
Kind: Exported function
Returns: object
- query param object or {}
Param | Type | Description |
---|---|---|
url | string |
url |