Skip to content

Commit

Permalink
feat: implement stripRoot function
Browse files Browse the repository at this point in the history
* fix(join): handle absolute segments

* feat: stripRoot

* revert: "fix(join): handle absolute segments"

This reverts commit 85a3784.

* chore: re-export
  • Loading branch information
P0lip committed Oct 11, 2019
1 parent ed5c8b0 commit 59b9235
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/__tests__/stripRoot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { stripRoot } from '../stripRoot';

describe('stripRoot', () => {
it.each(['foo', 'test/a', 'a/b'])('does not alter "%s" path', (path) => {
expect(stripRoot(path)).toEqual(path);
});

it.each`
actual | expected
${'/foo'} | ${'foo'}
${'c:\\foo'} | ${'foo'}
${'\\foo'} | ${'foo'}
${'////a'} | ${'a'}
${'/\\///a'} | ${'a'}
`('strip root from "$actual" path', ({ actual, expected }) => {
expect(stripRoot(actual)).toEqual(expected);
});
});
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './relative';
export * from './resolve';
export * from './sep';
export * from './startsWithWindowsDrive';
export * from './stripRoot';
export * from './toFSPath';
export * from './types';
export * from './srn';
export * from './srn';
7 changes: 7 additions & 0 deletions src/stripRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { parse } from './parse';
import { sep } from './sep';

export const stripRoot = (path: string) =>
parse(path)
.path.filter(Boolean)
.join(sep);

0 comments on commit 59b9235

Please sign in to comment.