README
Dwing Common
安装
npm install @dwing/common --save
使用
ES7:
const {md5} = require('@dwing/common');
console.log(md5('1'));
具体参数
Members
isNumber
判断是否为数字
isObject
判断是否为对象
uuid
生成GUID
Methods
formatDate(inputPattern, inputDate) → {string}
格式化时间
Parameters:
| Name | Type | Description |
|---|---|---|
| `inputPattern` | string |
时间格式,默认为'yyyy-MM-dd hh:mm:ss' |
| `inputDate` | any |
输入时间,默认为当前 |
Returns:
格式化的时间
- Type
- string
getDefer() → {Promise.defer}
getDefer
Returns:
defer对象
- Type
- Promise.defer
getMobile(mobile) → {string}
获取手机号码
Parameters:
| Name | Type | Description |
|---|---|---|
| `mobile` | string |
手机号字符串 |
Returns:
非手机号返回空字符串,否则返回去掉+86的手机号码
- Type
- string
getTimestamp() → {int}
获取UNIX标准时间戳
Returns:
UNIX标准时间戳
- Type
- int
hmac(str, type, key) → {string}
Hmac
Parameters:
| Name | Type | Description |
|---|---|---|
| `str` | string |
待加密字符串 |
| `type` | string |
sha1或sha256 |
| `key` | string |
密钥 |
Returns:
- Type
- string
int2ip(num) → {string}
INT2IP
Parameters:
| Name | Type | Description |
|---|---|---|
| `num` | int |
IP数值 |
Returns:
IP地址,如1.2.3.4
- Type
- string
ip2int(ip) → {number}
IP2INT
Parameters:
| Name | Type | Description |
|---|---|---|
| `ip` | str |
IP地址,如1.2.3.4 |
Returns:
IP数值
- Type
- number
isEmpty(obj) → {boolean}
判断是否为空
Parameters:
| Name | Type | Description |
|---|---|---|
| `obj` | * |
任意 |
Returns:
真为空,假为非空
- Type
- boolean
isNumberString(obj) → {boolean}
判断是否为数字字符串
Parameters:
| Name | Type | Description |
|---|---|---|
| `obj` | * |
任意 |
Returns:
是否为数字字符串
- Type
- boolean
JSONparse(str) → {object}
安全处理 JSON
Parameters:
| Name | Type | Description |
|---|---|---|
| `str` | string |
JSON字符串 |
Returns:
JSON对象
- Type
- object
md5(str) → {string}
MD5
Parameters:
| Name | Type | Description |
|---|---|---|
| `str` | string |
Returns:
- Type
- string
pad(n, len, char) → {string}
Pad Numbers
Parameters:
| Name | Type | Description |
|---|---|---|
| `n` | int |
数值 |
| `len` | int |
补位长度 |
| `char` | char |
补位字符,默认:0 |
Returns:
IP地址,如1.2.3.4
- Type
- string
randNumber(m, n) → {int}
随机数
Parameters:
| Name | Type | Description |
|---|---|---|
| `m` | int |
m |
| `n` | int |
n |
Returns:
生成 m 到 n 的随机整数
- Type
- int
randNumberStr(len) → {string}
随机数字字符串
Parameters:
| Name | Type | Description |
|---|---|---|
| `len` | int |
字符串长度 |
Returns:
const { randNumberStr } = require('@dwing/common'); const str = randNumberStr(6); console.log(str);
- Type
- string
randStr(len) → {string}
随机字符串
Parameters:
| Name | Type | Description |
|---|---|---|
| `len` | int |
字符串长度 |
Returns:
- Type
- string
sha1(str) → {string}
SHA1
Parameters:
| Name | Type | Description |
|---|---|---|
| `str` | string |
Returns:
- Type
- string
sha256(str) → {string}
SHA256
Parameters:
| Name | Type | Description |
|---|---|---|
| `str` | string |
Returns:
- Type
- string
validPassword(password) → {boolean}
validPassword
Parameters:
| Name | Type | Description |
|---|---|---|
| `password` | string |
输入密码 |
Returns:
isValid
- Type
- boolean
License
MIT