refactor: extract shared utilities (isMarkdownFile, isPlainObject, resolveSymlink) (#33)

This commit is contained in:
Junho Yeo
2025-12-13 14:23:04 +09:00
committed by GitHub
parent 60d9513d3a
commit 1323443c85
9 changed files with 42 additions and 49 deletions

26
src/shared/file-utils.ts Normal file
View File

@@ -0,0 +1,26 @@
import { lstatSync, readlinkSync } from "fs"
import { resolve } from "path"
export function isMarkdownFile(entry: { name: string; isFile: () => boolean }): boolean {
return !entry.name.startsWith(".") && entry.name.endsWith(".md") && entry.isFile()
}
export function isSymbolicLink(filePath: string): boolean {
try {
return lstatSync(filePath, { throwIfNoEntry: false })?.isSymbolicLink() ?? false
} catch {
return false
}
}
export function resolveSymlink(filePath: string): string {
try {
const stats = lstatSync(filePath, { throwIfNoEntry: false })
if (stats?.isSymbolicLink()) {
return resolve(filePath, "..", readlinkSync(filePath))
}
return filePath
} catch {
return filePath
}
}