除类型转换以外的转换 vjspUtils.converter

输入掩码转成正则对象

(static).inputMaskToRegExp(imstr) → {RegExp}

示例

//return /^\d{1}\d{1}\d?\d?[A-Za-z0-9]{1}[A-Za-z0-9]{1}$/
vjspUtils.converter.inputMaskToRegExp('0099AA');

参数:

NameTypeDescription
imstrString输入掩码

返回: 转换后的正则对象

Type RegExp

字节数转带单位字符串

(static).bytesToSize(bytes, fixedopt) → {String}

示例

//return "117.74 MB"
vjspUtils.converter.bytesToSize(123456789);

参数:

NameTypeAttributesDefaultDescription
bytesString|Integer字节数
fixedIntegeroptional2小数位数

返回: 转换后字符串

Type String

带单位字符串转字节数

(static).sizeToBytes(size) → {Integer}

示例

//return 123459338
vjspUtils.converter.sizeToBytes("117.74 MB");

参数:

NameTypeDescription
sizeString字节数

返回: 转换后字节数,有任何错误或者失败则返回 -1

Type Integer

毫秒转换成特定单位时间

(static).millisecondToUnitTime(val, unit) → {Number}

示例

//return 1.428898125
vjspUtils.converter.millisecondToUnitTime(123456798,'d');

参数:

NameTypeDescription
valNumber待转换时间
unitString时间单位(d:天,h:小时,m:分钟,s:秒,ms:毫秒)

返回: 转换后时间

Type Number

特定单位时间转换成毫秒

(static).unitTimeTomillisecond(val, unit) → {Number}

示例

//return 123456797.99999999
vjspUtils.converter.unitTimeTomillisecond(1.428898125,'d');

参数:

NameTypeDescription
valNumber待转换时间
unitString时间单位(d:天,h:小时,m:分钟,s:秒,ms:毫秒)

返回: 转换后时间

Type Number