-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
c08ae10
commit 587e890
Showing
9 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ pathe | |
pkgs | ||
posix | ||
preid | ||
remarkrc | ||
shfmt | ||
tscu | ||
unstub | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`unit:lib/extnames > should return list of extensions ("") 1`] = `[]`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions (".") 1`] = `[]`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions (".remarkignore") 1`] = `[]`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions (".remarkrc.mjs") 1`] = ` | ||
[ | ||
".mjs", | ||
] | ||
`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions ("/") 1`] = `[]`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions ("eslint.base.config.mjs") 1`] = ` | ||
[ | ||
".base", | ||
".config", | ||
".mjs", | ||
] | ||
`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions ("grease.config.mjs") 1`] = ` | ||
[ | ||
".config", | ||
".mjs", | ||
] | ||
`; | ||
|
||
exports[`unit:lib/extnames > should return list of extensions ("src/lib/extnames.ts") 1`] = ` | ||
[ | ||
".ts", | ||
] | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @file Unit Tests - extnames | ||
* @module pathe/lib/tests/unit/extnames | ||
*/ | ||
|
||
import testSubject from '../extnames' | ||
|
||
describe('unit:lib/extnames', () => { | ||
it.each<Parameters<typeof testSubject>>([ | ||
[''], | ||
['.'], | ||
['.remarkignore'], | ||
['.remarkrc.mjs'], | ||
['/'], | ||
['eslint.base.config.mjs'], | ||
['grease.config.mjs'], | ||
['src/lib/extnames.ts'] | ||
])('should return list of extensions (%j)', path => { | ||
expect(testSubject(path)).toMatchSnapshot() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @file extnames | ||
* @module pathe/lib/extnames | ||
*/ | ||
|
||
import validateString from '#internal/validate-string' | ||
import type { EmptyString, Ext } from '@flex-development/pathe' | ||
import dot from './dot' | ||
import extname from './extname' | ||
import toPosix from './to-posix' | ||
|
||
/** | ||
* Get a list of file extensions for `path`. | ||
* | ||
* @see {@linkcode Ext} | ||
* @see {@linkcode extname} | ||
* | ||
* @param {string} path | ||
* Path to handle | ||
* @return {Ext[]} | ||
* List of extensions | ||
*/ | ||
function extnames(path: string): Ext[] { | ||
validateString(path, 'path') | ||
|
||
/** | ||
* List of extensions. | ||
* | ||
* @const {Ext[]} extensions | ||
*/ | ||
const extensions: Ext[] = [] | ||
|
||
/** | ||
* Current path. | ||
* | ||
* @var {string} subpath | ||
*/ | ||
let subpath: string = toPosix(path) | ||
|
||
while (subpath.includes(dot)) { | ||
/** | ||
* Current extension. | ||
* | ||
* @const {EmptyString | Ext} ext | ||
*/ | ||
const ext: EmptyString | Ext = extname(subpath) | ||
|
||
if (ext === '') break | ||
|
||
extensions.unshift(ext) | ||
subpath = subpath.slice(0, subpath.lastIndexOf(ext)) | ||
} | ||
|
||
return extensions | ||
} | ||
|
||
export default extnames |
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