diff --git a/common/web/types/src/util/file-types.ts b/common/web/types/src/util/file-types.ts index eabcb21b523..d00f9daff12 100644 --- a/common/web/types/src/util/file-types.ts +++ b/common/web/types/src/util/file-types.ts @@ -166,19 +166,3 @@ export function filenameIs(filename: string, fileType: Source | Binary) { } return filename.toLowerCase().endsWith(fileType); } - -/** - * Replaces a filename extension with the new extension. Returns `null` if the - * filename does not end with oldExtension. - * @param filename - * @param oldExtension - * @param newExtension - * @returns - */ -export function replaceExtension(filename: string, oldExtension: string, newExtension: string): string { - const ext = filename.substring(filename.length - oldExtension.length); - if(ext !== oldExtension) { - return null; - } - return filename.substring(0, filename.length - oldExtension.length) + newExtension; -} \ No newline at end of file diff --git a/common/web/types/tests/util/file-types.tests.ts b/common/web/types/tests/util/file-types.tests.ts index 3f4d6870918..f1f841dcccb 100644 --- a/common/web/types/tests/util/file-types.tests.ts +++ b/common/web/types/tests/util/file-types.tests.ts @@ -19,7 +19,6 @@ import { sourceTypeFromFilename, binaryTypeFromFilename, filenameIs, - replaceExtension, } from '../../src/util/file-types.js'; describe('Test of File-Types', () => { @@ -195,40 +194,4 @@ describe('Test of File-Types', () => { assert.isTrue(actual); }); }); - describe('Test of replaceExtension()', () => { - it('can replace an extension', () => { - const oldExt = ".cpp"; - const newExt = ".js"; - const oldFilename = `file${oldExt}`; - const newFilename = `file${newExt}`; - const actual = replaceExtension(oldFilename, oldExt, newExt); - assert.deepEqual(actual, newFilename); - }); - it('should return null for incorrect old extension (too short)', () => { - const oldExt = ".ts"; - const newExt = ".js"; - const oldFilename = `file.c`; - const actual = replaceExtension(oldFilename, oldExt, newExt); - assert.isNull(actual); - }); - it('should return null for incorrect old extension (too long)', () => { - const oldExt = ".ts"; - const newExt = ".js"; - const oldFilename = `file.cpp`; - const actual = replaceExtension(oldFilename, oldExt, newExt); - assert.isNull(actual); - }); - // it('should return null for null old extension', () => { - // const newExt = ".js"; - // const oldFilename = `file.ts`; - // const actual = replaceExtension(oldFilename, null, newExt); - // assert.isNull(actual); - // }); - // it('should return null for null new extension', () => { - // const oldExt = ".ts"; - // const oldFilename = `file.ts`; - // const actual = replaceExtension(oldFilename, oldExt, null); - // assert.isNull(actual); - // }); - }); });