fix: String.split(str, n) stops after n separator (#10408)

This commit is contained in:
Victor Berchet
2016-08-01 11:33:35 -07:00
committed by GitHub
parent e73d0511cf
commit 13c8211065
8 changed files with 49 additions and 35 deletions

View File

@ -21,8 +21,9 @@ export function camelCaseToDashCase(input: string): string {
}
export function splitAtColon(input: string, defaultValues: string[]): string[] {
var parts = input.split(':', 2).map((s: string) => s.trim());
return parts.length > 1 ? parts : defaultValues;
const colonIndex = input.indexOf(':');
if (colonIndex == -1) return defaultValues;
return [input.slice(0, colonIndex).trim(), input.slice(colonIndex + 1).trim()];
}
export function sanitizeIdentifier(name: string): string {