@aird/common

Node.js 通用类

Usage no npm install needed!

<script type="module">
  import airdCommon from 'https://cdn.skypack.dev/@aird/common';
</script>

README

Dwing Common

npm npm codecov Travis-CI codebeat badge API Doc

安装

npm install @dwing/common --save

使用

ES7:

const {md5} = require('@dwing/common');

console.log(md5('1'));

具体参数

Members

isNumber

判断是否为数字

Source:

isObject

判断是否为对象

Source:

uuid

生成GUID

Source:

Methods

formatDate(inputPattern, inputDate) → {string}

格式化时间

Parameters:
Name Type Description
`inputPattern` string

时间格式,默认为'yyyy-MM-dd hh:mm:ss'

`inputDate` any

输入时间,默认为当前

Source:
Returns:

格式化的时间

Type
string

getDefer() → {Promise.defer}

getDefer

Source:
Returns:

defer对象

Type
Promise.defer

getMobile(mobile) → {string}

获取手机号码

Parameters:
Name Type Description
`mobile` string

手机号字符串

Source:
Returns:

非手机号返回空字符串,否则返回去掉+86的手机号码

Type
string

getTimestamp() → {int}

获取UNIX标准时间戳

Source:
Returns:

UNIX标准时间戳

Type
int

hmac(str, type, key) → {string}

Hmac

Parameters:
Name Type Description
`str` string

待加密字符串

`type` string

sha1或sha256

`key` string

密钥

Source:
Returns:
Type
string

int2ip(num) → {string}

INT2IP

Parameters:
Name Type Description
`num` int

IP数值

Source:
Returns:

IP地址,如1.2.3.4

Type
string

ip2int(ip) → {number}

IP2INT

Parameters:
Name Type Description
`ip` str

IP地址,如1.2.3.4

Source:
Returns:

IP数值

Type
number

isEmpty(obj) → {boolean}

判断是否为空

Parameters:
Name Type Description
`obj` *

任意

Source:
Returns:

真为空,假为非空

Type
boolean

isNumberString(obj) → {boolean}

判断是否为数字字符串

Parameters:
Name Type Description
`obj` *

任意

Source:
Returns:

是否为数字字符串

Type
boolean

JSONparse(str) → {object}

安全处理 JSON

Parameters:
Name Type Description
`str` string

JSON字符串

Source:
Returns:

JSON对象

Type
object

md5(str) → {string}

MD5

Parameters:
Name Type Description
`str` string
Source:
Returns:
Type
string

pad(n, len, char) → {string}

Pad Numbers

Parameters:
Name Type Description
`n` int

数值

`len` int

补位长度

`char` char

补位字符,默认:0

Source:
Returns:

IP地址,如1.2.3.4

Type
string

randNumber(m, n) → {int}

随机数

Parameters:
Name Type Description
`m` int

m

`n` int

n

Source:
Returns:

生成 m 到 n 的随机整数

Type
int

randNumberStr(len) → {string}

随机数字字符串

Parameters:
Name Type Description
`len` int

字符串长度

Source:
Returns:

const { randNumberStr } = require('@dwing/common'); const str = randNumberStr(6); console.log(str);

Type
string

randStr(len) → {string}

随机字符串

Parameters:
Name Type Description
`len` int

字符串长度

Source:
Returns:
Type
string

sha1(str) → {string}

SHA1

Parameters:
Name Type Description
`str` string
Source:
Returns:
Type
string

sha256(str) → {string}

SHA256

Parameters:
Name Type Description
`str` string
Source:
Returns:
Type
string

validPassword(password) → {boolean}

validPassword

Parameters:
Name Type Description
`password` string

输入密码

Source:
Returns:

isValid

Type
boolean

License

MIT