npm install @xibang/node-common --save
ES7:
const { md5 } = require('@xibang/node-common');
console.log(md5('1'));
判断是否为数字
判断是否为对象
生成GUID
格式化时间
Name | Type | Description |
---|---|---|
`inputPattern` | string |
时间格式,默认为'yyyy-MM-dd hh:mm:ss' |
`inputDate` | any |
输入时间,默认为当前 |
格式化的时间
- Type
- string
getDefer
defer对象
- Type
- Promise.defer
获取UNIX标准时间戳
UNIX标准时间戳
- Type
- int
Hmac
Name | Type | Description |
---|---|---|
`str` | string |
待加密字符串 |
`type` | string |
sha1或sha256 |
`key` | string |
密钥 |
- Type
- string
INT2IP
Name | Type | Description |
---|---|---|
`num` | int |
IP数值 |
IP地址,如1.2.3.4
- Type
- string
IP2INT
Name | Type | Description |
---|---|---|
`ip` | str |
IP地址,如1.2.3.4 |
IP数值
- Type
- number
判断是否为空
Name | Type | Description |
---|---|---|
`obj` | * |
任意 |
真为空,假为非空
- Type
- boolean
判断是否为数字字符串
Name | Type | Description |
---|---|---|
`obj` | * |
任意 |
是否为数字字符串
- Type
- boolean
安全处理 JSON
Name | Type | Description |
---|---|---|
`str` | string |
JSON字符串 |
`default` | object |
默认值 {} |
JSON对象
- Type
- object
MD5
Name | Type | Description |
---|---|---|
`str` | string |
- Type
- string
Pad Numbers
Name | Type | Description |
---|---|---|
`n` | int |
数值 |
`len` | int |
补位长度 |
`char` | char |
补位字符,默认:0 |
补位后的字符串
- Type
- string
随机数
Name | Type | Description |
---|---|---|
`m` | int |
m |
`n` | int |
n |
生成 m 到 n 的随机整数
- Type
- int
随机数字字符串
Name | Type | Description |
---|---|---|
`len` | int |
字符串长度 |
const { randNumberStr } = require('@xibang/common'); const str = randNumberStr(6); console.log(str);
- Type
- string
随机字符串
Name | Type | Description |
---|---|---|
`len` | int |
字符串长度 |
- Type
- string
SHA1
Name | Type | Description |
---|---|---|
`str` | string |
- Type
- string
SHA256
Name | Type | Description |
---|---|---|
`str` | string |
- Type
- string
Apache 2.0
通过支付宝捐赠: