-
-
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
6fb7173
commit 6287a90
Showing
2 changed files
with
42 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @file Unit Tests - formatExt | ||
* @module pathe/internal/tests/unit/formatExt | ||
*/ | ||
|
||
import testSubject from '../format-ext' | ||
|
||
describe('unit:internal/formatExt', () => { | ||
let ext: string | ||
|
||
beforeEach(() => { | ||
ext = '.mjs' | ||
}) | ||
|
||
it('should do nothing if value begins with dot character', () => { | ||
expect(testSubject(ext)).to.equal(ext) | ||
}) | ||
|
||
it('should return formatted file extension', () => { | ||
expect(testSubject(ext.slice(1))).to.equal(ext) | ||
}) | ||
}) |
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,20 @@ | ||
/** | ||
* @file Internal - formatExt | ||
* @module pathe/internal/formatExt | ||
*/ | ||
|
||
import type { Ext } from '#src/types' | ||
import validateString from './validate-string' | ||
|
||
/** | ||
* File extension formatter. | ||
* | ||
* @param {string} ext - File extension to format | ||
* @return {Ext} `ext` formatted | ||
*/ | ||
const formatExt = (ext: string): Ext => { | ||
validateString(ext, 'ext') | ||
return ext.replace(/^([^.])/, '.$1') as Ext | ||
} | ||
|
||
export default formatExt |