Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common/web): delete replaceExtension in types/src/util/file-types.ts #12762

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions common/web/types/src/util/file-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
37 changes: 0 additions & 37 deletions common/web/types/tests/util/file-types.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
sourceTypeFromFilename,
binaryTypeFromFilename,
filenameIs,
replaceExtension,
} from '../../src/util/file-types.js';

describe('Test of File-Types', () => {
Expand Down Expand Up @@ -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);
// });
});
});
Loading