获取随机16进制颜色
// * 获取随机16进制颜色
const getRandomColor = () =>
'#' + Math.random().toString(16).substring(2,8).padEnd(6,'0');
获取随机RGB
const getRandomRGB = () => {
let c = () => parseInt(Math.random()*255);
return `rgb(${c()},${c()},${c()})`
}
获取随机RGBA
const getRandomRGBA = () => {
let c = () => parseInt(Math.random()*255);
let a = () => Math.random().toFixed(1);
return `rgba(${c()},${c()},${c()},${a()})`
}
炒鸡好用的图片压缩网站,一用一个不吱声!
TinyPNG – Compress WebP, PNG and JPEG images intelligently
对象复制
const deepClone = (obj) => {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (Array.isArray(obj)) {
const newArray = [];
for (let i = 0; i < obj.length; i++) {
newArray[i] = this.deepClone(obj[i]);
}
return newArray;
}
const newObj = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
newObj[key] = this.deepClone(obj[key]);
}
}
return newObj;
}
数字转金额显示
const numToPrice = (num) => {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
判断是否是对象
const isObject = e => e !== null && typeof e === 'object' && !Array.isArray(e);
NB大佬的个人主页
Ovilia