diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 21c71e4..eeb8eb5 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -9,14 +9,14 @@ describe('lastPathComponent and extractParentFolderPath', () => { ['a/subfolder', 'a', 'subfolder'], ['parent/child', 'parent', 'child'], ['','',''], - [' ','',''], + [' ','',' '], ['/strange', '', 'strange'], ['a/b/c/', 'a/b/c', ''], ['d d d/e e e/f f f/ggg ggg', 'd d d/e e e/f f f', 'ggg ggg'], ['/','',''], - [' / ','',''], - [' /','',''], - ['/ ','',''] + [' / ',' ',' '], + [' /',' ',''], + ['/ ','',' '] ])('should from %s extract %s and %s', (path: string, parentPath: string, lastComponent: string) => { const extractedParentPath: string = extractParentFolderPath(path) const extractedLastComponent: string = lastPathComponent(path) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5afece4..4e767d5 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -9,10 +9,10 @@ export function last(o: Array): T | undefined { export function lastPathComponent(path: string): string { const lastPathSeparatorIdx = (path ?? '').lastIndexOf('/') - return lastPathSeparatorIdx >= 0 ? path.substring(lastPathSeparatorIdx + 1).trim() : path.trim() + return lastPathSeparatorIdx >= 0 ? path.substring(lastPathSeparatorIdx + 1) : path } export function extractParentFolderPath(path: string): string { const lastPathSeparatorIdx = (path ?? '').lastIndexOf('/') - return lastPathSeparatorIdx > 0 ? path.substring(0, lastPathSeparatorIdx).trim() : '' + return lastPathSeparatorIdx > 0 ? path.substring(0, lastPathSeparatorIdx) : '' }