Files
ragflow/web/src/lib/utils.ts
Jimmy Ben Klieve 1a4dee4313 refactor(ui): unify top level pages structure, use standard language codes and time zones (#13573)
### What problem does this PR solve?

- Unify top level pages structure
- Standardize locale language codes (BCP 47) and time zones (IANA tz)


> **Note:** 
> Newly created user info brings non-standard default values `timezone:
"UTC+8\tAsia/Shanghai"` and `language: "English"`.


### Type of change

- [x] Refactoring
2026-03-12 21:01:09 +08:00

40 lines
1010 B
TypeScript

import { clsx, type ClassValue } from 'clsx';
import React from 'react';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function formatBytes(
bytes: number,
opts: {
decimals?: number;
sizeType?: 'accurate' | 'normal';
} = {},
) {
const { decimals = 0, sizeType = 'normal' } = opts;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const accurateSizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
if (bytes === 0) return '0 Byte';
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return `${(bytes / Math.pow(1024, i)).toFixed(decimals)} ${
sizeType === 'accurate'
? (accurateSizes[i] ?? 'Bytes')
: (sizes[i] ?? 'Bytes')
}`;
}
export function combineRefs<T>(...refs: React.ForwardedRef<T>[]) {
return (node: T) => {
refs.forEach((ref) => {
if (typeof ref === 'function') {
ref(node);
} else if (ref) {
ref.current = node;
}
});
};
}