-
-
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.
refactor(utils): expose
formatExt
as utility
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
dabb689
commit e58f9e2
Showing
6 changed files
with
58 additions
and
44 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
/** | ||
* @file Unit Tests - formatExt | ||
* @module pathe/utils/tests/unit/formatExt | ||
*/ | ||
|
||
import type { Ext } from '#src/types' | ||
import testSubject from '../format-ext' | ||
|
||
describe('unit:utils/formatExt', () => { | ||
let ext: Ext | ||
|
||
beforeEach(() => { | ||
ext = '.mjs' | ||
}) | ||
|
||
it('should return empty string if ext is empty string', () => { | ||
expect(testSubject('')).to.equal('') | ||
}) | ||
|
||
it('should return ext without modifications if ext starts with dot', () => { | ||
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,23 @@ | ||
/** | ||
* @file Utilities - formatExt | ||
* @module pathe/utils/formatExt | ||
*/ | ||
|
||
import type { Ext } from '#src/types' | ||
import type { EmptyString } from '@flex-development/tutils' | ||
|
||
/** | ||
* Formats a file extension. | ||
* | ||
* This includes: | ||
* | ||
* - Prepending a `.` (dot) character if not already present | ||
* | ||
* @param {string} [ext=''] - File extension to format | ||
* @return {EmptyString | Ext} Formatted file extension or empty string | ||
*/ | ||
const formatExt = (ext: string = ''): EmptyString | Ext => { | ||
return ext.trim().replace(/^([^.])/, '.$1') as EmptyString | Ext | ||
} | ||
|
||
export default formatExt |
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,6 @@ | ||
/** | ||
* @file Entry Point - Utilities | ||
* @module pathe/utils | ||
*/ | ||
|
||
export { default as formatExt } from './format-ext' |