mirror of
https://github.com/motajs/template.git
synced 2026-11-01 14:14:30 +08:00
init: 2.B
This commit is contained in:
commit
6bf32174d8
610 files changed
+151444
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
export function uniqueSymbol() {
|
||||
return Math.ceil(Math.random() * 0xefffffff + 0x10000000).toString(16);
|
||||
}
|
||||
|
||||
export function fileHash(
|
||||
content: string | Buffer | Uint8Array,
|
||||
length: number = 8
|
||||
) {
|
||||
return createHash('sha256').update(content).digest('hex').slice(0, length);
|
||||
}
|
||||
|
||||
export function formatSize(size: number) {
|
||||
if (size < 1 << 10) {
|
||||
return `${size.toFixed(2)}B`;
|
||||
} else if (size < 1 << 20) {
|
||||
return `${(size / (1 << 10)).toFixed(2)}KB`;
|
||||
} else if (size < 1 << 30) {
|
||||
return `${(size / (1 << 20)).toFixed(2)}MB`;
|
||||
} else {
|
||||
return `${(size / (1 << 30)).toFixed(2)}GB`;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user