Remove duplicate startsWith and endsWith functions

This commit is contained in:
Andy Hanson 2016-07-13 10:00:34 -07:00
parent e6e6a8b110
commit 8e679b7021
3 changed files with 7 additions and 33 deletions

View file

@ -900,7 +900,7 @@ namespace ts {
}
export function fileExtensionIs(path: string, extension: string): boolean {
return stringEndsWith(path, extension);
return path.length > extension.length && endsWith(path, extension);
}
export function fileExtensionIsAny(path: string, extensions: string[]): boolean {
@ -913,18 +913,6 @@ namespace ts {
return false;
}
// Should act like String.prototype.startsWith
export function stringStartsWith(s: string, start: string): boolean {
return s.length > start.length && s.substr(0, start.length) === start;
}
// Should act like String.prototype.endsWith
export function stringEndsWith(s: string, end: string): boolean {
const sLen = s.length;
const endLen = end.length;
return sLen > endLen && s.substr(sLen - endLen, endLen) === end;
}
// Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
// It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
// proof.

View file

@ -1377,31 +1377,27 @@ namespace Harness {
writeByteOrderMark: boolean;
}
function stringEndsWith(str: string, end: string) {
return str.substr(str.length - end.length) === end;
}
export function isTS(fileName: string) {
return stringEndsWith(fileName, ".ts");
return ts.endsWith(fileName, ".ts");
}
export function isTSX(fileName: string) {
return stringEndsWith(fileName, ".tsx");
return ts.endsWith(fileName, ".tsx");
}
export function isDTS(fileName: string) {
return stringEndsWith(fileName, ".d.ts");
return ts.endsWith(fileName, ".d.ts");
}
export function isJS(fileName: string) {
return stringEndsWith(fileName, ".js");
return ts.endsWith(fileName, ".js");
}
export function isJSX(fileName: string) {
return stringEndsWith(fileName, ".jsx");
return ts.endsWith(fileName, ".jsx");
}
export function isJSMap(fileName: string) {
return stringEndsWith(fileName, ".js.map") || stringEndsWith(fileName, ".jsx.map");
return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map");
}
/** Contains the code and errors of a compilation and some helper methods to check its status. */

View file

@ -514,16 +514,6 @@ namespace ts {
return str === str.toLowerCase();
}
function startsWith(string: string, search: string) {
for (let i = 0, n = search.length; i < n; i++) {
if (string.charCodeAt(i) !== search.charCodeAt(i)) {
return false;
}
}
return true;
}
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(string: string, value: string): number {
for (let i = 0, n = string.length - value.length; i <= n; i++) {