Skip to content

Commit

Permalink
Merge pull request #12762 from keymanapp/fix/common/web/types/12761-d…
Browse files Browse the repository at this point in the history
…elete-replaceExtension

fix(common/web): delete replaceExtension in types/src/util/file-types.ts
  • Loading branch information
markcsinclair authored Dec 9, 2024
2 parents a77b20f + da50cec commit b8cd016
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
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);
// });
});
});

0 comments on commit b8cd016

Please sign in to comment.