@wener/console
Version:
Base console UI toolkit
32 lines (31 loc) • 961 B
JavaScript
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
import { FileExtIcon } from "./FileExtIcon.js";
import { FileTypeIcon } from "./FileTypeIcon.js";
export function getFileIcon(needle) {
if (!needle)
return FileTypeIcon.file;
var fn;
if ((typeof needle === "undefined" ? "undefined" : _type_of(needle)) === "object" && needle) {
if (needle.kind === "directory") {
return FileTypeIcon.directory;
}
fn = needle.name;
}
else if (typeof needle === "string") {
fn = needle;
}
if (fn) {
var ext;
if (fn.includes(".")) {
ext = extname(fn).slice(1);
}
return FileExtIcon[ext || fn] || FileTypeIcon.file;
}
return FileTypeIcon.file;
}
function extname(fn) {
return fn.includes(".") ? fn.slice(fn.lastIndexOf(".") + 1) : "";
}