Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@dwing/common

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dwing/common

Node.js 通用类

Source
npmnpm
Version
1.2.7
Version published
Weekly downloads
4
-60%
Maintainers
2
Weekly downloads
 
Created
Source

Dwing Common

github 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:
  • index.js, line 94

isObject

判断是否为对象

Source:

uuid

生成GUID

Source:

Methods

formatDate(inputPattern, inputDate) → {string}

格式化时间

Parameters:
NameTypeDescription
`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:
NameTypeDescription
`mobile`string

手机号字符串

Source:
Returns:

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

Type
string

getTimestamp() → {int}

获取UNIX标准时间戳

Source:
Returns:

UNIX标准时间戳

Type
int

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

Hmac

Parameters:
NameTypeDescription
`str`string

待加密字符串

`type`string

sha1或sha256

`key`string

密钥

Source:
Returns:
Type
string

int2ip(num) → {string}

INT2IP

Parameters:
NameTypeDescription
`num`int

IP数值

Source:
Returns:

IP地址,如1.2.3.4

Type
string

ip2int(ip) → {number}

IP2INT

Parameters:
NameTypeDescription
`ip`str

IP地址,如1.2.3.4

Source:
Returns:

IP数值

Type
number

isEmpty(obj) → {boolean}

判断是否为空

Parameters:
NameTypeDescription
`obj`*

任意

Source:
Returns:

真为空,假为非空

Type
boolean

isNumberString(obj) → {boolean}

判断是否为数字字符串

Parameters:
NameTypeDescription
`obj`*

任意

Source:
Returns:

是否为数字字符串

Type
boolean

JSONparse(str) → {object}

安全处理 JSON

Parameters:
NameTypeDescription
`str`string

JSON字符串

Source:
Returns:

JSON对象

Type
object

md5(str) → {string}

MD5

Parameters:
NameTypeDescription
`str`string
Source:
Returns:
Type
string

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

Pad Numbers

Parameters:
NameTypeDescription
`n`int

数值

`len`int

补位长度

`char`char

补位字符,默认:0

Source:
Returns:

IP地址,如1.2.3.4

Type
string

randNumber(m, n) → {int}

随机数

Parameters:
NameTypeDescription
`m`int

m

`n`int

n

Source:
Returns:

生成 m 到 n 的随机整数

Type
int

randNumberStr(len) → {string}

随机数字字符串

Parameters:
NameTypeDescription
`len`int

字符串长度

Source:
Returns:

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

Type
string

randStr(len) → {string}

随机字符串

Parameters:
NameTypeDescription
`len`int

字符串长度

Source:
Returns:
Type
string

sha1(str) → {string}

SHA1

Parameters:
NameTypeDescription
`str`string
Source:
Returns:
Type
string

sha256(str) → {string}

SHA256

Parameters:
NameTypeDescription
`str`string
Source:
Returns:
Type
string

validPassword(password) → {boolean}

validPassword

Parameters:
NameTypeDescription
`password`string

输入密码

Source:
Returns:

isValid

Type
boolean

License

MIT

通过支付宝捐赠:

qr

Keywords

api

FAQs

Package last updated on 04 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts