mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: update contains and add test cases
This commit is contained in:
1 parent
3b8264e39e
commit
728399938a
2 files changed
+54
-2
No files matched your search
@@ -2,7 +2,7 @@ import { basename } from './utils.js'
|
||||
|
||||
export default class File {
|
||||
constructor({ path, type, discovered }) {
|
||||
this.path = path
|
||||
this.path = path.trimEnd('/')
|
||||
this.name = basename(path)
|
||||
this.type = type
|
||||
this.discovered = discovered
|
||||
@@ -13,6 +13,9 @@ export default class File {
|
||||
}
|
||||
|
||||
contains(file) {
|
||||
return this.isDirectory() && file.path.startsWith(this.path)
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user