Skip to content

Commit 8e679b7

Browse files
author
Andy Hanson
committed
Remove duplicate startsWith and endsWith functions
1 parent e6e6a8b commit 8e679b7

3 files changed

Lines changed: 7 additions & 33 deletions

File tree

src/compiler/core.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ namespace ts {
900900
}
901901

902902
export function fileExtensionIs(path: string, extension: string): boolean {
903-
return stringEndsWith(path, extension);
903+
return path.length > extension.length && endsWith(path, extension);
904904
}
905905

906906
export function fileExtensionIsAny(path: string, extensions: string[]): boolean {
@@ -913,18 +913,6 @@ namespace ts {
913913
return false;
914914
}
915915

916-
// Should act like String.prototype.startsWith
917-
export function stringStartsWith(s: string, start: string): boolean {
918-
return s.length > start.length && s.substr(0, start.length) === start;
919-
}
920-
921-
// Should act like String.prototype.endsWith
922-
export function stringEndsWith(s: string, end: string): boolean {
923-
const sLen = s.length;
924-
const endLen = end.length;
925-
return sLen > endLen && s.substr(sLen - endLen, endLen) === end;
926-
}
927-
928916
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
929917
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
930918
// proof.

src/harness/harness.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,31 +1377,27 @@ namespace Harness {
13771377
writeByteOrderMark: boolean;
13781378
}
13791379

1380-
function stringEndsWith(str: string, end: string) {
1381-
return str.substr(str.length - end.length) === end;
1382-
}
1383-
13841380
export function isTS(fileName: string) {
1385-
return stringEndsWith(fileName, ".ts");
1381+
return ts.endsWith(fileName, ".ts");
13861382
}
13871383

13881384
export function isTSX(fileName: string) {
1389-
return stringEndsWith(fileName, ".tsx");
1385+
return ts.endsWith(fileName, ".tsx");
13901386
}
13911387

13921388
export function isDTS(fileName: string) {
1393-
return stringEndsWith(fileName, ".d.ts");
1389+
return ts.endsWith(fileName, ".d.ts");
13941390
}
13951391

13961392
export function isJS(fileName: string) {
1397-
return stringEndsWith(fileName, ".js");
1393+
return ts.endsWith(fileName, ".js");
13981394
}
13991395
export function isJSX(fileName: string) {
1400-
return stringEndsWith(fileName, ".jsx");
1396+
return ts.endsWith(fileName, ".jsx");
14011397
}
14021398

14031399
export function isJSMap(fileName: string) {
1404-
return stringEndsWith(fileName, ".js.map") || stringEndsWith(fileName, ".jsx.map");
1400+
return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map");
14051401
}
14061402

14071403
/** Contains the code and errors of a compilation and some helper methods to check its status. */

src/services/patternMatcher.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,6 @@ namespace ts {
514514
return str === str.toLowerCase();
515515
}
516516

517-
function startsWith(string: string, search: string) {
518-
for (let i = 0, n = search.length; i < n; i++) {
519-
if (string.charCodeAt(i) !== search.charCodeAt(i)) {
520-
return false;
521-
}
522-
}
523-
524-
return true;
525-
}
526-
527517
// Assumes 'value' is already lowercase.
528518
function indexOfIgnoringCase(string: string, value: string): number {
529519
for (let i = 0, n = string.length - value.length; i <= n; i++) {

0 commit comments

Comments
 (0)