All files / src/app/contents/shared helper.ts

100% Statements 16/16
100% Branches 14/14
100% Functions 4/4
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x         1x 18x 18x   1x 20x 20x   1x 13x 13x 13x 13x   1x 10x 10x 10x  
import fs from "node:fs";
import bytes from "bytes";
import type { Path } from "glob";
import { getDirSize } from "../../../utils/directories";
 
export function getHref(path: Path) {
	return path.isDirectory() ? `${path.name}/` : path.name;
}
 
export function getExt(path: Path) {
	return path.isDirectory() ? "dir" : (path.name.split(".").pop() ?? "");
}
 
export function getSize(path: Path) {
	const file = fs.statSync(path.fullpath());
	const size = file.isFile() ? file.size : file.isDirectory() ? getDirSize(path.fullpath()) : 0;
	return bytes(size) ?? "-";
}
 
export function getLastModified(path: Path) {
	const file = fs.statSync(path.fullpath());
	return file.mtime.toLocaleString();
}