Members
(constant) INFINITY
- Source:
Used as references for various Number
constants.
Methods
add(a, b) → {number}
两个数字相加.
Example
Biu.add(1, 2);
// returns 3
Parameters:
Name | Type | Description |
---|---|---|
a |
String | 参数a |
b |
String | 参数b |
Returns:
number - 返回结果
- Type
- number
getBrowser() → {string}
获取浏览器类型
Returns:
- Type
- string
getSessionStorage()
- Source:
获取sessionStorage
getStorage(key, exp) → {boolean|any}
- Source:
获取localStorage值
Example
Peanut.getStorage('name');
Parameters:
Name | Type | Description |
---|---|---|
key |
键值 |
|
exp |
过期时间 |
Returns:
返回结果
- Type
- boolean | any
isArray(object) → {bool}
判断对象是否数组
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isBoolean(object) → {bool}
判断是否布尔值
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isDate(object) → {bool}
判断对象是否日期
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isDom(obj) → {bool}
判断对象是否DOM元素
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | DOM对象 |
Returns:
是/否
- Type
- bool
isFunction(object) → {bool}
判断对象是否函数
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isNumber(object) → {bool}
判断对象是否数值
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isObject(object) → {bool}
判断对象是否对象
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isString(object) → {bool}
判断对象是否字符串
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
isUndefined(object) → {bool}
判断对象是否定义 其实只对对象中的元素判断有效,如是纯变量,此方法会无法调用,需要外面加try
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 对象 |
Returns:
是/否
- Type
- bool
ltrim(str) → {string}
去掉字符串左边的非空字符
Parameters:
Name | Type | Description |
---|---|---|
str |
string | 字符串 |
Returns:
- Type
- string
nest(array)
根据parent_id生成树结构
Example
const comments = [
{ id: 1, parent_id: null },
{ id: 2, parent_id: null },
{ id: 3, parent_id: 1 },
{ id: 4, parent_id: 2 },
{ id: 5, parent_id: 4 }
];
nest(comments);
Parameters:
Name | Type | Description |
---|---|---|
array |
* |
Returns:
Array
numFormat(s, n)
Parameters:
Name | Type | Description |
---|---|---|
s |
* | |
n |
* |
removeSessionStorage()
- Source:
删除sessionStorage
rtrim(str) → {string}
去掉字符串右边的非空字符
Parameters:
Name | Type | Description |
---|---|---|
str |
string | 字符串 |
Returns:
- Type
- string
setSessionStorage()
- Source:
存储sessionStorage
setStorage(key, value) → {number}
- Source:
设置localStorage
Example
Peanut.setStorage('name', 'peanut');
Parameters:
Name | Type | Description |
---|---|---|
key |
||
value |
Returns:
number - 返回结果
- Type
- number
shuffle(array)
数组洗牌,此代码段使用Fisher-Yates算法随机排序数组的元素。
Example
const foo = [1, 2, 3];
shuffle(foo); // [2, 3, 1], foo = [1, 2, 3]
Parameters:
Name | Type | Description |
---|---|---|
array |
* |
Returns:
Array
toString(value) → {string}
- Source:
- Since:
- 4.0.0
Converts value
to a string. An empty string is returned for null
and undefined
values. The sign of -0
is preserved.
Example
toString(null)
// => ''
toString(-0)
// => '-0'
toString([1, 2, 3])
// => '1,2,3'
Parameters:
Name | Type | Description |
---|---|---|
value |
* | The value to convert. |
Returns:
Returns the converted string.
- Type
- string
toThousandsFilter(num) → {String}
Parameters:
Name | Type | Description |
---|---|---|
num |
* |
Returns:
- Type
- String
trim(str) → {string}
去掉字符串左右两边的非空字符
Parameters:
Name | Type | Description |
---|---|---|
str |
string | 字符串 |
Returns:
- Type
- string
validate(value, type) → {*}
- Source:
正则校验
Parameters:
Name | Type | Description |
---|---|---|
value |
||
type |
Returns:
- Type
- *