Methods
bind(obj) → {*}
方法创建一个新的函数,在 bind() 被调用时,这个新函数的 this 被指定为 bind() 的第一个参数
Parameters:
| Name | Type | Description |
|---|---|---|
|
||
obj |
* | 需要绑定的对象 |
Returns:
{(Function|void)} 返回一个原函数的拷贝,并拥有指定的 this 值和初始参数
- Type
- *
Example
bind(fn, {a:1})
debounce(delayopt) → {*}
函数防抖
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
|
||||
delay |
number |
<optional> |
500 | 延迟时间 默认500ms |
- Source:
Returns:
{Function} 返回防抖后的函数
- Type
- *
deepCopy(obj, cacheopt) → {*}
对象深拷贝
来源Vuex https://github.com/vuejs/vuex/blob/dev/src/util.js 解决了循环引用问题
对其深度拷贝进行二次优化, 添加Date其他类型的判断 {time:new Date(), regexp:/\w+/}
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
obj |
* | 要进行拷贝的源数据 | ||
cache |
Array.<any> |
<optional> |
[] | 利用数组存储已经拷贝过的数据, 每次拷贝会从cache中查询有没有拷贝过 |
- Source:
Returns:
{*} 返回拷贝的数据
- Type
- *
Example
deepCopy({age:12, time:new Date(), regexp:/\w+/, fn:function(){}}, [])
each(collection, iteratee)
迭代器
Parameters:
| Name | Type | Description |
|---|---|---|
collection |
* | |
iteratee |
function |
Example
each([1,2,3], (v, i, arr) = {
})
empty(v) → {*}
判断是否为空 {}|""|[]|null|undefined
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
empty("") => true empty(null) => true empty(undefined) => true empty({}) => true empty([]) => true empty(0) => false
extend(thisArgs, target)
把一个对象上的属性拷贝到另个对象上
Parameters:
| Name | Type | Description |
|---|---|---|
thisArgs |
* | 拷贝对象 |
target |
* | 需要被拷贝的对象 |
Example
extend({a:1}, {b:1})
getBrowserType() → {*}
获取浏览器类型
- Source:
Returns:
{browserType} | 'IE7'| 'IE8'| 'IE9'| 'IE10'| 'IE11'| 'Edge'| 'FireFox'| 'Opera'| 'Chrome'| 'Safari'| null
- Type
- *
Example
getBrowserType() => 'Chrome'
getUID() → {*}
生成唯一的UID
Returns:
{string} 返回生成的UID字符串
- Type
- *
Example
createUID() => 5d33b0fc-692d-41eb-e703-4aa76a8f
getVerifyCode(lenopt) → {*}
获取随机验证码
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
len |
number |
<optional> |
4 | 默认长度是4位 |
- Source:
Returns:
{string} 返回一个[len]长度的随机字符串
- Type
- *
Example
getVerifyCode(4) => 4sGa
has(obj, v) → {*}
判断属性是否存在
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
* | 任意类型, 不是obejct返回false |
v |
string | number | 需要查找的属性名 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
has({a:1}, "a") => true
includes(data, ele, fromIndexopt) → {*}
判断一个数组里或者字符串是否包含一个指定的值
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
data |
Array.<any> | string | 需要查找的数组或者字符串 | |
ele |
never | 指定的值, 可以是数字,字符串,对象 | |
fromIndex |
number | undefined |
<optional> |
从指定位置开始查找 可选 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
includes([1,2,3], 1) => true
indexOf(data, ele, fromIndexopt) → {*}
indexOf 从头到尾地检索 如果有返回索引值
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
data |
Array.<any> | string | 需要查找的数组或者字符串 | |
ele |
any | 指定的值, 可以是数字,字符串,对象 | |
fromIndex |
number | undefined |
<optional> |
从指定位置开始查找 可选 |
- Source:
Returns:
{number} 返回第一次出现的索引, 如果没有找到, 则返回-1
- Type
- *
Example
indexOf([1,2,3], 1) => 0 indexOf([{c:1}, {a:1,b:2}], {a:1}) => -1 indexOf([[1], [2,3]], [2,3]) => 1
isAndroid() → {*}
是否Android
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isAndroid() => true|false
isArray(v) → {*}
判断是否数组
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isArray([]) => true
isBool(v) → {*}
是否boolean
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isBool(true) => true
isDate(v) → {*}
是否日期
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isDate("123") => false
isFn(v) → {*}
是否函数
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isFn(function(){}) => true
isIOS() → {*}
是否IOS
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isIOS() => false|true
isiPad() → {*}
是否iPad
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isiPad() => true|false
isMap(v) → {*}
是否Map
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isMap(new Map()) => true
isNaN(v) → {*}
是否NaN
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isNaN(NaN) => true
isNull(v) → {*}
是否Null
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isNull(null) => true
isNumber(v) → {*}
是否数字
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isNumber(12) => true
isObj(v) → {*}
判断是否Object
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isObj({}) => true
isPC() → {*}
是否PC端
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isPC() => true|false
isPrimitive(v)
是否基本数据类型
Parameters:
| Name | Type | Description |
|---|---|---|
v |
any 任意类型 |
- Source:
Returns:
boolean 返回一个boolean值
Example
isPrimitive(1) => true isPrimitive({}) => false
isPromise(v) → {*}
是否Promise
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isPromise() => true|false
isRegExp(v) → {*}
是否函数
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isFn(function(){}) => true
isSet(v) → {*}
是否Set
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isSet() => true|false
isString(v) → {*}
是否字符串
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isString("12") => true
isSymbol(v) → {*}
是否Symbol
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isSymbol() => false|true
isUndefined(v) → {*}
是否 undefined
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isUndefined(null) => false
isWPhone() → {*}
是否WPhone设备
- Source:
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
isWPhone() => false|true
ltrim(str) → {*}
对字符串左边去空格
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 传入一个字符串 |
Returns:
{string} 返回一个左边没有空格的新的字符串
- Type
- *
Example
ltrim(" abc ") => "abc "
noop()
返回一个空函数
random(loweropt, upperopt) → {*}
生成简单随机数
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
lower |
number |
<optional> |
0 | 最小范围 |
upper |
number |
<optional> |
1 | 最大范围 |
Returns:
{number} 返回一个[lower, upper]之间的数字
- Type
- *
Example
random(0, 4) => 3
remove(arr, iteratee) → {*}
删除数组元素
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<any> | 需要操作的数组 |
iteratee |
function | number | 回调 |
Returns:
{Array} 返回新的数组 注意并不是原数组的引用
- Type
- *
Example
remove([1,2,3], (v, i, arr) => v === 1) => [2,3];
reverse(v) → {*}
将字符串, 数字或者数组进行反序输出
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 要返回其自身反序的操作 |
- Source:
Returns:
{(Array | string | number | null)} 返回一个数组,或字符串,数字
- Type
- *
Example
reverse("abcdef") => "fedcba"
rtrim(str) → {*}
对字符串右边去空格
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 传入一个字符串 |
Returns:
{string} 返回一个右边没有空格的新的字符串
- Type
- *
Example
rtrim(" bac ") => " bac"
throttle(delayopt) → {*}
函数节流
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
|
||||
delay |
number |
<optional> |
500 | 延迟时间 默认500ms |
- Source:
Returns:
{Function} 返回节流后的函数
- Type
- *
toFirstLower(str) → {*}
首字母小写
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 传入一个字符串 |
- Source:
Returns:
{string} 返回一个新的首字母小写的字符串
- Type
- *
Example
toFirstUpper("abc") => abc toFirstUpper("ABC") => aBC
toFirstUpper(str) → {*}
首字母大写
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 传入一个字符串 |
- Source:
Returns:
{string} 返回一个新的首字母大写的字符串
- Type
- *
Example
toFirstUpper("abc") => Abc toFirstUpper("ABC") => ABC
toKeys(obj) → {*}
返回object自身可枚举属性
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
* | 要返回可枚举属性的对象 |
Returns:
{Array} 返回一个给定对象自身的所有可枚举属性的数组
- Type
- *
Example
toKeys({a:1,b:2}) => ["a", "b"]
toLowerCase(str) → {*}
大写转换成小写
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 需要被转换的字符串 |
- Source:
Returns:
{string} 一个新的字符串, 转换为小写的字符串
- Type
- *
Example
toLowerCase("ABC") => "abc"
toParam(obj) → {*}
将object对象转成url参数
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
* | 需要被转化Url参数的对象 |
- Source:
Returns:
{string} 返回一个不包含 ? 的Url参数的字符串
- Type
- *
Example
a=1&b=2&c=3
toQuery(url) → {*}
对url做简单解析成object
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | 需要被解析的Url地址 |
- Source:
Returns:
{*} 返回一个对象
- Type
- *
Example
urlParse("http:127.0.0.1:8080?type=1&id=123&name=zhangsan") => {url: "http:127.0.0.1:8080", type: "1", id: "123", name: "zhangsan"}
toUpperCase(str) → {*}
小写转换成大写
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 需要被转换的字符串 |
- Source:
Returns:
{string} 一个新的字符串, 转换为大写的字符串
- Type
- *
Example
toUpperCase("abc") => "ABC"
toValues(obj) → {*}
返回object自身可枚举属性值
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
* | 要返回可枚举属性值的对象 |
- Source:
Returns:
{Array} 返回一个给定对象自身的所有可枚举属性值的数组
- Type
- *
Example
toValues({a:1,b:2}) => [1, 2]
trim(str) → {*}
对字符串两边去空格
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 需要去空格的字符串 |
Returns:
{string} 返回没有空格的字符串
- Type
- *
Example
trim(" bac ") => "bac"
typeOf(v, t) → {*}
判断数据类型
Parameters:
| Name | Type | Description |
|---|---|---|
v |
* | 任意值 |
t |
Types | 传入类型 'string'| 'number'| 'object'| 'function'| 'boolean'| 'undefined'| 'symbol'| 'bigint' |
Returns:
{boolean} 返回一个布尔值
- Type
- *
Example
typeOf(true, "boolean") = true
unique(data) → {*}
对一个集合去重
Parameters:
| Name | Type | Description |
|---|---|---|
data |
* | 任意值 |
Returns:
{*} 返回没有重复的数据
- Type
- *
Example
unique([1,2,3,3]) => [1,2,3] unique([{age:1}, {age:2}, {age:1}]) => [{age:1}, {age:2}]
uniqueToArray(arr) → {*}
对数组去重 只对string[]|number[]去重 不使用new Set()
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<(string|number)> | 需要去重的数组 |
Returns:
{(Array)} 返回一个没有重复数据的数组
- Type
- *
Example
uniqueToArray([1,2,3,3,2]) => [1,2,3]
uniqueToNumber(num) → {*}
对数字去重
Parameters:
| Name | Type | Description |
|---|---|---|
num |
number | 需要去重的数字 |
Returns:
{number} 返回没有重复的数字
- Type
- *
Example
uniqueToNumber(111123) => 123
uniqueToSizzArray(arr) → {*}
对多种类型或者混合数组去重
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array.<any> | 需要去重的数组 |
Returns:
{Array} 返回一个没有重复数据的数组
- Type
- *
Example
uniqueToSizzArray([{age:12},{age:13}]) uniqueToSizzArray(["a","b","b"])
uniqueToSttring(str) → {*}
对字符串去重
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | 需要去重的字符串 |
Returns:
{string} 返回新的字符串
- Type
- *
Example
uniqueToSttring("abcbbbc") => abc