mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
refactor utils
This commit is contained in:
1 parent
23f9023f8b
commit
e91774fe3b
6 files changed
+93
-80
No files matched your search
@@ -0,0 +1,23 @@
|
||||
const fileTypes = {
|
||||
file: '-f',
|
||||
folder: '-d',
|
||||
link: '-L',
|
||||
socket: '-S',
|
||||
unknown: '-e',
|
||||
}
|
||||
|
||||
export type FileType = keyof typeof fileTypes
|
||||
|
||||
export type File = {
|
||||
path: string
|
||||
type: FileType
|
||||
}
|
||||
|
||||
function sanitizePath(path: string): string {
|
||||
return path.replace(/[^a-zA-Z0-9._/-]/g, '')
|
||||
}
|
||||
|
||||
export function buildFileCheckCmd(file: File): string[] {
|
||||
const { path, type } = file
|
||||
return ['test', fileTypes[type] || '-e', sanitizePath(path)]
|
||||
}
|
||||
Reference in new issue
Block a user