// 正则表达式
export const regex = {
    password: /^[a-zA-Z0-9@#$%^&*_\-+=]{6,16}$////^[a-zA-Z0-9]{6,16}$/,// 密码
};

// 下载文件
export const downloadFile = (blob: Blob, fileName: string) => {
    const url = window.URL.createObjectURL(blob);
    const link = document.createElement("a");
    link.href = url;
    link.download = fileName;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    window.URL.revokeObjectURL(url);
};
export const getContrastColor = (hex: string) => {
    // remove #
    const c = hex.replace('#', '');
    const r = parseInt(c.substring(0, 2), 16);
    const g = parseInt(c.substring(2, 4), 16);
    const b = parseInt(c.substring(4, 6), 16);
    // relative luminance
    const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
    return luminance > 0.6 ? '#000' : '#fff';
}
export function resolveAlias(aliasPath: string): string {
  const alias = '@/';
  const realRoot = './src/';
  return aliasPath.startsWith(alias) ? aliasPath.replace(alias, realRoot) : aliasPath;
}