-
-
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.
feat: add file-name extension helper
- Loading branch information
Showing
3 changed files
with
57 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 |
---|---|---|
|
@@ -62,5 +62,10 @@ | |
}, | ||
"dependencies": { | ||
"glob": "^8.0.3" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "@commitlint/cz-commitlint" | ||
} | ||
} | ||
} |
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,28 @@ | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
export function removeFileNameExtension( | ||
input: string, | ||
extensions?: string[], | ||
) { | ||
if (input.includes('.')) { | ||
const position = input.lastIndexOf('.'); | ||
const extension = input.substring( | ||
position, | ||
input.length, | ||
); | ||
|
||
if ( | ||
typeof extensions === 'undefined' || | ||
extensions.indexOf(extension) !== -1 | ||
) { | ||
input = input.substring(0, position); | ||
} | ||
} | ||
|
||
return input; | ||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { removeFileNameExtension } from "../../src/utils/file-name"; | ||
|
||
describe('src/utils/*.ts', function () { | ||
it('should remove file name extension', () => { | ||
let data = removeFileNameExtension('test.js', ['.js', '.ts']); | ||
expect(data).toEqual('test'); | ||
|
||
data = removeFileNameExtension('test.mts', ['.js', '.ts']); | ||
expect(data).toEqual('test.mts'); | ||
|
||
data = removeFileNameExtension('test.js', []); | ||
expect(data).toEqual('test.js'); | ||
|
||
data = removeFileNameExtension('test.js'); | ||
expect(data).toEqual('test'); | ||
}) | ||
}); |