import dayjs from 'dayjs' export function hasIntersection(arr1: string[], arr2: string[]) { const ret = arr2.some(item => arr1.includes(item)) return ret } export function formatBytes(value: number | string): string { let bytes: number = 0 if (typeof value === 'string') bytes = Number.parseFloat(value) else if (typeof value === 'number') bytes = value if (bytes < 0) return '-' else if (bytes < 1024) return `${bytes} B` else if (bytes < 1048576) return `${(bytes / 1024).toFixed(0)} KB` else if (bytes < 1073741824) return `${(bytes / 1048576).toFixed(1)} MB` else return `${(bytes / 1073741824).toFixed(2)} GB` } export function formatDate(date?: dayjs.ConfigType): string { return dayjs(date).format('YYYY-MM-DD HH:mm:ss') } export function timestampToTime(timestamp: number): string { const date = new Date(timestamp) // 时间戳为10位需*1000,时间戳为13位的话不需乘1000 const Y = `${date.getFullYear()}-` const M = `${date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1}-` const D = `${date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()} ` const h = `${date.getHours() < 10 ? `0${date.getHours()}` : date.getHours()}:` const m = `${date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes()}:` const s = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds() return Y + M + D + h + m + s } export function getFileExtension(filename: string) { return filename.slice(((filename.lastIndexOf('.') - 1) >>> 0) + 2) }