From 12f77994af5a4b61bcec352f679706d753374692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20von=20Wyss?= Date: Sun, 29 Jan 2017 12:47:34 +0100 Subject: [PATCH 1/2] Join some overloads of string methods to union parameters Fixes the string methods which accept either a string or RegExp as pattern. Also, some help texts were fixed to represent the actual behavior as per spec. See #5766 --- lib/lib.d.ts | 55 +++++++++++----------------------------------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/lib/lib.d.ts b/lib/lib.d.ts index 6a4e8ec52160c..5e4138aff65ca 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -349,55 +349,29 @@ interface String { /** * Matches a string with a regular expression, and returns an array containing the results of that search. - * @param regexp A variable name or string literal containing the regular expression pattern and flags. + * @param regexp A string containing the regular expression pattern or a regular expression object. */ - match(regexp: string): RegExpMatchArray | null; + match(regexp: RegExp | string): RegExpMatchArray | null; /** - * Matches a string with a regular expression, and returns an array containing the results of that search. - * @param regexp A regular expression object that contains the regular expression pattern and applicable flags. - */ - match(regexp: RegExp): RegExpMatchArray | null; - - /** - * Replaces text in a string, using a regular expression or search string. - * @param searchValue A string that represents the regular expression. + * Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences. + * @param searchValue A literal search string or a regular expression object. * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. */ - replace(searchValue: string, replaceValue: string): string; + replace(searchValue: RegExp | string, replaceValue: string): string; /** - * Replaces text in a string, using a regular expression or search string. + * Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences. * @param searchValue A string that represents the regular expression. * @param replacer A function that returns the replacement text. */ - replace(searchValue: string, replacer: (substring: string, ...args: any[]) => string): string; - - /** - * Replaces text in a string, using a regular expression or search string. - * @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags. - * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. - */ - replace(searchValue: RegExp, replaceValue: string): string; - - /** - * Replaces text in a string, using a regular expression or search string. - * @param searchValue A Regular Expression object containing the regular expression pattern and applicable flags - * @param replacer A function that returns the replacement text. - */ - replace(searchValue: RegExp, replacer: (substring: string, ...args: any[]) => string): string; - - /** - * Finds the first substring match in a regular expression search. - * @param regexp The regular expression pattern and applicable flags. - */ - search(regexp: string): number; + replace(searchValue: RegExp | string, replacer: (substring: string, ...args: any[]) => string): string; /** * Finds the first substring match in a regular expression search. - * @param regexp The regular expression pattern and applicable flags. + * @param regexp The regular expression pattern or object. */ - search(regexp: RegExp): number; + search(regexp: RegExp | string): number; /** * Returns a section of a string. @@ -409,17 +383,10 @@ interface String { /** * Split a string into substrings using the specified separator and return them as an array. - * @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. - * @param limit A value used to limit the number of elements returned in the array. - */ - split(separator: string, limit?: number): string[]; - - /** - * Split a string into substrings using the specified separator and return them as an array. - * @param separator A Regular Express that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. + * @param separator A literal string or a regular expression object that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned. * @param limit A value used to limit the number of elements returned in the array. */ - split(separator: RegExp, limit?: number): string[]; + split(separator: RegExp | string, limit?: number): string[]; /** * Returns the substring at the specified location within a String object. From 1562b3de29b97ae50cf3daf0500e373f17b528f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ars=C3=A8ne=20von=20Wyss?= Date: Mon, 6 Feb 2017 11:46:49 +0100 Subject: [PATCH 2/2] Adjusted string.replace help text wording --- lib/lib.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lib.d.ts b/lib/lib.d.ts index 5e4138aff65ca..5e984b5bb6bf9 100644 --- a/lib/lib.d.ts +++ b/lib/lib.d.ts @@ -354,14 +354,14 @@ interface String { match(regexp: RegExp | string): RegExpMatchArray | null; /** - * Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences. + * Replaces text in a string, using a regular expression or search string. When given a regular expression with its global flag set, this method replaces all occurrences. Otherwise, only the first match is replaced. * @param searchValue A literal search string or a regular expression object. * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string. */ replace(searchValue: RegExp | string, replaceValue: string): string; /** - * Replaces text in a string, using a regular expression or search string. Only regular expression with global flag replaces all occurrences. + * Replaces text in a string, using a regular expression or search string. When given a regular expression with its global flag set, this method replaces all occurrences. Otherwise, only the first match is replaced. * @param searchValue A string that represents the regular expression. * @param replacer A function that returns the replacement text. */