mjd507 / dorado

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dorado

Build Status Coverage Status

Modules

arrays
dates
devices
eventBus
functions
images
objects
regexs
urls

arrays

diffElement(arr1, arr2) ⇒ Array

比较两个数组不同的元素,并收集全部的不同元素

Kind: Exported function
Returns: Array - [description]

Param Type Description
arr1 Array [description]
arr2 Array [description]

diffObject(arr1, arr2, condition) ⇒ Array

取出数组中不同的对象元素

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}]

dates

now() ⇒ number

获取当前时间戳

Kind: Exported function
Returns: number - [description]

devices

getOs() ⇒ string

获取当前操作系统类型

Kind: Exported function
Returns: string - 'iOS | android | WindowsPhone | MacOS | Windows | Linux | unknown'

isiOS() ⇒ Boolean

判断是否处于 iOS 设备运行

Kind: Exported function
Returns: Boolean - true is running in iOS

isAndroid() ⇒ Boolean

判断是否处于 Android 设备运行

Kind: Exported function
Returns: Boolean - true is running in weixin

isWeiXinEnv() ⇒ Boolean

判断是否处于微信环境运行

Kind: Exported function
Returns: Boolean - true is running in weixin

screenWidth() ⇒ number

获取屏幕宽度

Kind: Exported function
Returns: number - screen width

screenHeight() ⇒ number

获取屏幕高度

Kind: Exported function
Returns: number - screen height

eventBus

emit(event) ⇒ void

发布事件

Kind: Exported function

Param Type Description
event string 事件名称

on(event, func) ⇒ void

订阅事件

Kind: Exported function

Param Type Description
event string 事件名称
func function 事件处理函数

off(event) ⇒ void

取消订阅 (不传事件名称,则取消所有订阅)

Kind: Exported function

Param Type Description
event string 事件名称

functions

throttle(func, delay, options) ⇒ function

节流函数 (在指定的时间内只会执行一次)

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)

debounce(func, delay, immediate) ⇒ function

防抖函数 (在指定的时间内,每次触发,都需重新等待指定的时间) 使用场景:提交表单(防止多次提交)

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();
}

images

isSupportWebP() ⇒ Boolean

判断浏览器是否支持 webP 格式

Kind: Exported function
Returns: Boolean - [description]

objects

isArray(obj) ⇒ Boolean

判断对象是否为数组

Kind: Exported function
Returns: Boolean - true if is array

Param Type Description
obj object object

deepClone(obj) ⇒ object

深拷贝对象

Kind: Exported function
Returns: object - the deep copy of the object

Param Type Description
obj object object

regexs

isEmail(str) ⇒ Boolean

是否是邮箱

Kind: Exported function
Returns: Boolean - true if is email

Param Type Description
str string [description]

isIdCard(str) ⇒ Boolean

是否是身份证

Kind: Exported function
Returns: Boolean - true if is id-card

Param Type Description
str string [description]

isPhoneNumber(str) ⇒ Boolean

是否是手机号

Kind: Exported function
Returns: Boolean - true if is phone number

Param Type Description
str string [description]

isUrl(str) ⇒ Boolean

是否是 url

Kind: Exported function
Returns: Boolean - true if is url

Param Type Description
str string [description]

urls

parseQueryParam(url) ⇒ object

解析 GET 请求 参数

Kind: Exported function
Returns: object - query param object or {}

Param Type Description
url string url

About


Languages

Language:JavaScript 97.7%Language:HTML 2.3%