获取文件后缀名
const getExt = (filename) => {
if (typeof filename == 'string') {
return filename.split('.').pop().toLowerCase()
} else {
throw new Error('filename must be a string type')
}
}
生成随机字符串
const uuid = (length, chars) => {
chars =
chars ||
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
length = length || 8
let result = ''
for (let i = length; i > 0; --i) {
result +=
// chars[Math.floor(Math.random() * chars.length)]
chars[(Math.random() * chars.length) | 0]
}
return result
}
保留小数点后n位
const cutNumber = (num, no) => {
if (typeof num != 'number') {
num = Number(num)
}
return Number(num.toFixed(no))
}
const a = 38 / 3
console.log(cutNumber(a, 2))//12.67