@xibang/node-common

1.0.3 • Public • Published

Xibang Common

github npm npm codebeat badge codecov Build Status

安装

npm install @xibang/node-common --save

使用

ES7:

const { md5 } = require('@xibang/node-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

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, default) → {object}

安全处理 JSON

Parameters:
Name Type Description
`str` string

JSON字符串

`default` object

默认值 {}

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:

补位后的字符串

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('@xibang/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

License

Apache 2.0

通过支付宝捐赠:

qr

Dependents (3)

Package Sidebar

Install

npm i @xibang/node-common

Weekly Downloads

0

Version

1.0.3

License

Apache-2.0

Unpacked Size

40.3 kB

Total Files

13

Last publish

Collaborators

  • willin