Skip to content

@vtj / Modules / base

Module: base

Table of contents

Variables

Functions

Variables

rCar

Const rCar: RegExp

车牌号码表达式

Defined in

packages/base/src/regex.ts:25


rEmail

Const rEmail: RegExp

邮箱地址表达式

Defined in

packages/base/src/regex.ts:9


rID

Const rID: RegExp

身份证号码表达式

Defined in

packages/base/src/regex.ts:14


rMobile

Const rMobile: RegExp

手机号码表达式

Defined in

packages/base/src/regex.ts:20


rURL

Const rURL: RegExp

url表达式

Defined in

packages/base/src/regex.ts:4

Functions

AES

AES(content, key): string

对称加密

Parameters

NameType
contentstring
keystring

Returns

string

Defined in

packages/base/src/crypto.ts:78


MD5

MD5(content): string

MD5加密

Parameters

NameType
contentstring

Returns

string

Defined in

packages/base/src/crypto.ts:24


RSA

RSA(content, key?): string | false

非对称加密

Parameters

NameTypeDefault valueDescription
contentstringundefined内容
keystringRSA_PUBLIC_KEY公钥

Returns

string | false

Description

RSA密钥对生成工具

Defined in

packages/base/src/crypto.ts:54


arrayToMap

arrayToMap<T>(data, prop): Map<any, T>

数组转Map

Type parameters

Name
T

Parameters

NameType
dataT[]
propkeyof T

Returns

Map<any, T>

Defined in

packages/base/src/data.ts:7


base64

base64(content): string

Base64编码

Parameters

NameType
contentstring

Returns

string

Defined in

packages/base/src/crypto.ts:33


dateFormat

dateFormat(date, format?): string

Parameters

NameTypeDefault value
datestring | number | Dateundefined
formatstring'YYYY-MM-DD HH:mm:ss'

Returns

string

Defined in

packages/base/src/day.ts:6


dedupArray

dedupArray<T>(array, prop?): T[]

数组去重

Type parameters

NameType
Tany

Parameters

NameType
arrayT[]
prop?keyof T

Returns

T[]

Defined in

packages/base/src/data.ts:33


delay

delay(val?): Promise<unknown>

延时函数

Parameters

NameTypeDefault value
valnumber0

Returns

Promise<unknown>

Defined in

packages/base/src/util.ts:76


isCarNo

isCarNo(content): boolean

检查车牌号码

Parameters

NameType
contentstring

Returns

boolean

Defined in

packages/base/src/regex.ts:69


isDef

isDef(val): boolean

已定义

Parameters

NameType
valunknown

Returns

boolean

Defined in

packages/base/src/util.ts:18


isEmail

isEmail(content): boolean

检查邮箱地址

Parameters

NameType
contentstring

Returns

boolean

Defined in

packages/base/src/regex.ts:42


isIdCardNo

isIdCardNo(content): boolean

检查身份证号码

Parameters

NameType
contentstring

Returns

boolean

Defined in

packages/base/src/regex.ts:51


isMobilePhone

isMobilePhone(content): boolean

检查手机号码

Parameters

NameType
contentstring

Returns

boolean

Defined in

packages/base/src/regex.ts:60


isUrl

isUrl(content): boolean

检查url

Parameters

NameType
contentstring

Returns

boolean

Defined in

packages/base/src/regex.ts:33


mapToObject

mapToObject<V>(map): Record<any, V>

Map转键值对

Type parameters

NameType
Vany

Parameters

NameType
mapMap<any, V>

Returns

Record<any, V>

Defined in

packages/base/src/data.ts:20


now

now(): number

当前时间

Returns

number

Defined in

packages/base/src/util.ts:24


numberFormat

numberFormat(value, format?): string

数字格式化,默认2位小数

Parameters

NameTypeDefault value
valuenumberundefined
formatstring'0.00'

Returns

string

Defined in

packages/base/src/numeral.ts:9


omit

omit<T, K>(target, keys): K

对象排除属性

Type parameters

NameType
Textends Record<string, any>
Kextends Record<string, any>

Parameters

NameTypeDescription
targetT需要处理的对象
keysstring[] | (k: string, v: any) => boolean需要排除的属性名称

Returns

K

Defined in

packages/base/src/data.ts:75


pick

pick<T, K>(target, keys): K

对象提取属性

Type parameters

NameType
Textends Record<string, any>
Kextends Record<string, any>

Parameters

NameType
targetT
keysstring[] | (k: string, v: any) => boolean

Returns

K

Defined in

packages/base/src/data.ts:103


random

random(min, max): number

生成一个随机数

Parameters

NameType
minnumber
maxnumber

Returns

number

Defined in

packages/base/src/util.ts:38


timestamp

timestamp(): number

时间戳

Returns

number

Defined in

packages/base/src/util.ts:30


toArray

toArray<T>(maybeArray?): T[]

转换数组

Type parameters

NameType
Tany

Parameters

NameType
maybeArray?T | T[]

Returns

T[]

Defined in

packages/base/src/data.ts:47


toFixed

toFixed(value, number?, round): number

保留小数点,默认2位

Parameters

NameTypeDefault valueDescription
valuenumberundefined数值
numbernumber2小数位数
roundbooleanundefined是否四舍五入

Returns

number

Defined in

packages/base/src/numeral.ts:20


toRawType

toRawType(value): string

获取原生数据类型

Parameters

NameType
valueunknown

Returns

string

Defined in

packages/base/src/util.ts:9


toTypeString

toTypeString(value): string

Parameters

NameType
valueunknown

Returns

string

Defined in

packages/base/src/util.ts:1


trim

trim(obj): any

递归对象或数组清除文本类型值的两边空格

Parameters

NameType
objany

Returns

any

Defined in

packages/base/src/data.ts:130


uid

uid(): string

唯一id

Returns

string

Defined in

packages/base/src/util.ts:48


unAES

unAES(content, key): string

对称解密

Parameters

NameType
contentstring
keystring

Returns

string

Defined in

packages/base/src/crypto.ts:88


unBase64

unBase64(content): string

Base64解码

Parameters

NameType
contentstring

Returns

string

Defined in

packages/base/src/crypto.ts:43


unRSA

unRSA(content, key?): string | false

非对称解密

Parameters

NameTypeDefault valueDescription
contentstringundefined内容
keystringRSA_PRIVATE_KEY私匙

Returns

string | false

Defined in

packages/base/src/crypto.ts:66


upperFirstCamelCase

upperFirstCamelCase(name): string

Parameters

NameType
namestring

Returns

string

Defined in

packages/base/src/lodash.ts:32


uuid

uuid(split?): string

生成一个 UUID 或 GUID, 默认GUID

Parameters

NameTypeDefault valueDescription
splitbooleantruetrue为GUID,fasle为UUID

Returns

string

Defined in

packages/base/src/util.ts:59


zipObject

zipObject(obj): Record<string, any>

压缩对称,清除值为undefined或null的属性

Parameters

NameType
objRecord<string, any>

Returns

Record<string, any>

Defined in

packages/base/src/data.ts:56

Released under the MIT License.