-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Huy Vo <huyvo@var-meta.com>
- Loading branch information
Showing
4 changed files
with
26 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
export function getFileName(path: string): string { | ||
if (!path || path === '/') return ''; | ||
|
||
const sanitizedPath = path.endsWith('/') ? path.slice(0, -1) : path; | ||
|
||
const array = sanitizedPath.split('/'); | ||
return array[array.length - 1] || ''; | ||
} | ||
export function getFileName(path: string) { | ||
if (path == '/') return '' | ||
if (path[path.length - 1] !== '/') { | ||
const array = path.split('/') | ||
return array[array.length - 1] | ||
} else { | ||
const array = path.split('/') | ||
return array[array.length - 2] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
export function getParentPath(path: string): string { | ||
if (!path || path === '/') { | ||
console.log('sub path error'); | ||
return ''; | ||
export function getParentPath(path: string) { | ||
let array = path.split('/') | ||
if (array.length == 0) { | ||
console.log('sub path error') | ||
} | ||
|
||
const array = path.split('/').filter(Boolean); | ||
if (array.length === 0) { | ||
console.log('sub path error'); | ||
return ''; | ||
let dataReturn = '' | ||
for (let i = 0; i < array.length - 1; i++) { | ||
dataReturn += `${array[i]}/` | ||
} | ||
|
||
const parentPath = array.slice(0, -1).join('/'); | ||
return parentPath ? `/${parentPath}` : '/'; | ||
return dataReturn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters