WIP: fixing tests

This commit is contained in:
Lin, Hung-Shin authored and wancat committed 2024-01-29 12:42:50 +08:00
1 parent 8eaec839d3
commit 2bdb804f24
10 files changed
+49 -29

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
/* eslint-disable lines-between-class-members */
import { basename } from './utils'
interface FileObject {
path: string
type: string
discovered: boolean
}
export default class File implements FileObject {
path: string
name: string
type: string
discovered: boolean
constructor(obj: FileObject) {
this.path = obj.path.trimEnd()
this.name = basename(obj.path)
this.type = obj.type
this.discovered = obj.discovered
}
isDirectory() {
return this.type === 'folder'
}
contains(file: FileObject) {
if (!this.isDirectory()) return false
if (this.path === file.path) return true
const parentPath = this.path.endsWith('/') ? this.path : `${this.path}/`
return file.path.startsWith(parentPath)
}
}