Merge pull request #7893 from chrootsu/lodash-string-funcs

lodash: updated string functions
This commit is contained in:
Masahiro Wakame
2016-02-03 00:15:33 +09:00
2 changed files with 428 additions and 289 deletions
+168 -89
View File
@@ -9202,7 +9202,7 @@ module TestValuesIn {
**********/
// _.camelCase
module TestCamelCase {
namespace TestCamelCase {
{
let result: string;
@@ -9218,7 +9218,7 @@ module TestCamelCase {
}
// _.capitalize
module TestCapitalize {
namespace TestCapitalize {
{
let result: string;
@@ -9234,7 +9234,7 @@ module TestCapitalize {
}
// _.deburr
module TestDeburr {
namespace TestDeburr {
{
let result: string;
@@ -9250,7 +9250,7 @@ module TestDeburr {
}
// _.endsWith
module TestEndsWith {
namespace TestEndsWith {
{
let result: boolean;
@@ -9270,7 +9270,7 @@ module TestEndsWith {
}
// _.escape
module TestEscape {
namespace TestEscape {
{
let result: string;
@@ -9286,7 +9286,7 @@ module TestEscape {
}
// _.escapeRegExp
module TestEscapeRegExp {
namespace TestEscapeRegExp {
{
let result: string;
@@ -9302,7 +9302,7 @@ module TestEscapeRegExp {
}
// _.kebabCase
module TestKebabCase {
namespace TestKebabCase {
{
let result: string;
@@ -9318,7 +9318,7 @@ module TestKebabCase {
}
// _.lowerCase
module TestLowerCase {
namespace TestLowerCase {
{
let result: string;
@@ -9334,7 +9334,7 @@ module TestLowerCase {
}
// _.lowerFirst
module TestLowerFirst {
namespace TestLowerFirst {
{
let result: string;
@@ -9350,11 +9350,11 @@ module TestLowerFirst {
}
// _.pad
module TestPad {
namespace TestPad {
{
let result: string;
result = _.pad('abd');
result = _.pad('abc');
result = _.pad('abc', 8);
result = _.pad('abc', 8, '_-');
@@ -9372,31 +9372,8 @@ module TestPad {
}
}
// _.padStart
module TestPadStart {
{
let result: string;
result = _.padStart('abc');
result = _.padStart('abc', 6);
result = _.padStart('abc', 6, '_-');
result = _('abc').padStart();
result = _('abc').padStart(6);
result = _('abc').padStart(6, '_-');
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('abc').chain().padStart();
result = _('abc').chain().padStart(6);
result = _('abc').chain().padStart(6, '_-');
}
}
// _.padEnd
module TestPadEnd {
namespace TestPadEnd {
{
let result: string;
@@ -9418,9 +9395,31 @@ module TestPadEnd {
}
}
// _.padStart
namespace TestPadStart {
{
let result: string;
result = _.padStart('abc');
result = _.padStart('abc', 6);
result = _.padStart('abc', 6, '_-');
result = _('abc').padStart();
result = _('abc').padStart(6);
result = _('abc').padStart(6, '_-');
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('abc').chain().padStart();
result = _('abc').chain().padStart(6);
result = _('abc').chain().padStart(6, '_-');
}
}
// _.parseInt
module TestParseInt {
namespace TestParseInt {
{
let result: number;
@@ -9440,7 +9439,7 @@ module TestParseInt {
}
// _.repeat
module TestRepeat {
namespace TestRepeat {
{
let result: string;
result = _.repeat('*');
@@ -9458,8 +9457,63 @@ module TestRepeat {
}
}
// _.replace
namespace TestReplace {
let replacer = (match: string, offset: number, string: string) => 'Barney';
{
let result: string;
result = _.replace('Hi Fred', 'Fred', 'Barney');
result = _.replace('Hi Fred', 'Fred', replacer);
result = _.replace('Hi Fred', /fred/i, 'Barney');
result = _.replace('Hi Fred', /fred/i, replacer);
result = _.replace('Fred');
result = _.replace('Fred', 'Barney');
result = _.replace('Fred', replacer);
result = _.replace(/fred/i);
result = _.replace(/fred/i, 'Barney');
result = _.replace(/fred/i, replacer);
result = _('Hi Fred').replace('Fred', 'Barney');
result = _('Hi Fred').replace('Fred', replacer);
result = _('Hi Fred').replace(/fred/i, 'Barney');
result = _('Hi Fred').replace(/fred/i, replacer);
result = _('Fred').replace();
result = _('Fred').replace('Barney');
result = _('Fred').replace(replacer);
result = _(/fred/i).replace();
result = _(/fred/i).replace('Barney');
result = _(/fred/i).replace(replacer);
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('Hi Fred').chain().replace('Fred', 'Barney');
result = _('Hi Fred').chain().replace('Fred', replacer);
result = _('Hi Fred').chain().replace(/fred/i, 'Barney');
result = _('Hi Fred').chain().replace(/fred/i, replacer);
result = _('Fred').chain().replace();
result = _('Fred').chain().replace('Barney');
result = _('Fred').chain().replace(replacer);
result = _(/fred/i).chain().replace();
result = _(/fred/i).chain().replace('Barney');
result = _(/fred/i).chain().replace(replacer);
}
}
// _.snakeCase
module TestSnakeCase {
namespace TestSnakeCase {
{
let result: string;
@@ -9474,8 +9528,35 @@ module TestSnakeCase {
}
}
// _.split
namespace TestSplit {
{
let result: string[];
result = _.split('a-b-c');
result = _.split('a-b-c', '-');
result = _.split('a-b-c', '-', 2);
}
{
let result: _.LoDashImplicitArrayWrapper<string>;
result = _('a-b-c').split();
result = _('a-b-c').split('-');
result = _('a-b-c').split('-', 2);
}
{
let result: _.LoDashExplicitArrayWrapper<string>;
result = _('a-b-c').chain().split();
result = _('a-b-c').chain().split('-');
result = _('a-b-c').chain().split('-', 2);
}
}
// _.startCase
module TestStartCase {
namespace TestStartCase {
{
let result: string;
@@ -9491,7 +9572,7 @@ module TestStartCase {
}
// _.startsWith
module TestStartsWith {
namespace TestStartsWith {
{
let result: boolean;
@@ -9511,7 +9592,7 @@ module TestStartsWith {
}
// _.template
module TestTemplate {
namespace TestTemplate {
interface TemplateExecutor {
(obj?: Object): string;
source: string;
@@ -9545,7 +9626,7 @@ module TestTemplate {
}
// _.toLower
module TestToLower {
namespace TestToLower {
{
let result: string;
@@ -9561,7 +9642,7 @@ module TestToLower {
}
// _.toUpper
module TestToUpper {
namespace TestToUpper {
{
let result: string;
@@ -9577,7 +9658,7 @@ module TestToUpper {
}
// _.trim
module TestTrim {
namespace TestTrim {
{
let result: string;
@@ -9597,29 +9678,8 @@ module TestTrim {
}
}
// _.trimStart
module TestTrimStart {
{
let result: string;
result = _.trimStart();
result = _.trimStart(' abc ');
result = _.trimStart('-_-abc-_-', '_-');
result = _('-_-abc-_-').trimStart();
result = _('-_-abc-_-').trimStart('_-');
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('-_-abc-_-').chain().trimStart();
result = _('-_-abc-_-').chain().trimStart('_-');
}
}
// _.trimEnd
module TestTrimEnd {
namespace TestTrimEnd {
{
let result: string;
@@ -9639,19 +9699,38 @@ module TestTrimEnd {
}
}
// _.trimStart
namespace TestTrimStart {
{
let result: string;
result = _.trimStart();
result = _.trimStart(' abc ');
result = _.trimStart('-_-abc-_-', '_-');
result = _('-_-abc-_-').trimStart();
result = _('-_-abc-_-').trimStart('_-');
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('-_-abc-_-').chain().trimStart();
result = _('-_-abc-_-').chain().trimStart('_-');
}
}
// _.truncate
module Testtruncate {
namespace TestTruncate {
{
let result: string;
result = _.truncate('hi-diddly-ho there, neighborino');
result = _.truncate('hi-diddly-ho there, neighborino', 24);
result = _.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
result = _.truncate('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
result = _.truncate('hi-diddly-ho there, neighborino', { 'omission': ' […]' });
result = _('hi-diddly-ho there, neighborino').truncate();
result = _('hi-diddly-ho there, neighborino').truncate(24);
result = _('hi-diddly-ho there, neighborino').truncate({ 'length': 24, 'separator': ' ' });
result = _('hi-diddly-ho there, neighborino').truncate({ 'length': 24, 'separator': /,? +/ });
result = _('hi-diddly-ho there, neighborino').truncate({ 'omission': ' […]' });
@@ -9661,15 +9740,31 @@ module Testtruncate {
let result: _.LoDashExplicitWrapper<string>;
result = _('hi-diddly-ho there, neighborino').chain().truncate();
result = _('hi-diddly-ho there, neighborino').chain().truncate(24);
result = _('hi-diddly-ho there, neighborino').chain().truncate({ 'length': 24, 'separator': ' ' });
result = _('hi-diddly-ho there, neighborino').chain().truncate({ 'length': 24, 'separator': /,? +/ });
result = _('hi-diddly-ho there, neighborino').chain().truncate({ 'omission': ' […]' });
}
}
// _.unescape
namespace TestUnescape {
{
let result: string;
result = _.unescape('fred, barney, &amp; pebbles');
result = _('fred, barney, &amp; pebbles').unescape();
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('fred, barney, &amp; pebbles').chain().unescape();
}
}
// _.upperCase
module TestUpperCase {
namespace TestUpperCase {
{
let result: string;
@@ -9685,7 +9780,7 @@ module TestUpperCase {
}
// _.upperFirst
module TestUpperFirst {
namespace TestUpperFirst {
{
let result: string;
@@ -9700,24 +9795,8 @@ module TestUpperFirst {
}
}
// _.unescape
module TestUnescape {
{
let result: string;
result = _.unescape('fred, barney, &amp; pebbles');
result = _('fred, barney, &amp; pebbles').unescape();
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('fred, barney, &amp; pebbles').chain().unescape();
}
}
// _.words
module TestWords {
namespace TestWords {
{
let result: string[];
+260 -200
View File
@@ -15527,6 +15527,12 @@ declare module _ {
//_.capitalize
interface LoDashStatic {
/**
* Converts the first character of string to upper case and the remaining to lower case.
*
* @param string The string to capitalize.
* @return Returns the capitalized string.
*/
capitalize(string?: string): string;
}
@@ -15610,16 +15616,16 @@ declare module _ {
// _.escape
interface LoDashStatic {
/**
* Converts the characters "&", "<", ">", '"', "'", and "`", in string to their corresponding HTML entities.
* Converts the characters "&", "<", ">", '"', "'", and "`" in string to their corresponding HTML entities.
*
* Note: No other characters are escaped. To escape additional characters use a third-party library like he.
*
* Though the ">" character is escaped for symmetry, characters like ">" and "/" dont need escaping in HTML
* hough the ">" character is escaped for symmetry, characters like ">" and "/" dont need escaping in HTML
* and have no special meaning unless they're part of a tag or unquoted attribute value. See Mathias Bynenss
* article (under "semi-related fun fact") for more details.
*
* Backticks are escaped because in Internet Explorer < 9, they can break out of attribute values or HTML
* comments. See #59, #102, #108, and #133 of the HTML5 Security Cheatsheet for more details.
* Backticks are escaped because in IE < 9, they can break out of attribute values or HTML comments. See #59,
* #102, #108, and #133 of the HTML5 Security Cheatsheet for more details.
*
* When working with HTML you should always quote attribute values to reduce XSS vectors.
*
@@ -15646,8 +15652,8 @@ declare module _ {
// _.escapeRegExp
interface LoDashStatic {
/**
* Escapes the RegExp special characters "\", "/", "^", "$", ".", "|", "?", "*", "+", "(", ")", "[", "]",
* "{" and "}" in string.
* Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]",
* "{", "}", and "|" in string.
*
* @param string The string to escape.
* @return Returns the escaped string.
@@ -15699,21 +15705,8 @@ declare module _ {
/**
* Converts `string`, as space separated words, to lower case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the lower cased string.
* @example
*
* _.lowerCase('--Foo-Bar');
* // => 'foo bar'
*
* _.lowerCase('fooBar');
* // => 'foo bar'
*
* _.lowerCase('__FOO_BAR__');
* // => 'foo bar'
* @param string The string to convert.
* @return Returns the lower cased string.
*/
lowerCase(string?: string): string;
}
@@ -15737,18 +15730,8 @@ declare module _ {
/**
* Converts the first character of `string` to lower case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the converted string.
* @example
*
* _.lowerFirst('Fred');
* // => 'fred'
*
* _.lowerFirst('FRED');
* // => 'fRED'
* @param string The string to convert.
* @return Returns the converted string.
*/
lowerFirst(string?: string): string;
}
@@ -15805,44 +15788,6 @@ declare module _ {
): LoDashExplicitWrapper<string>;
}
//_.padStart
interface LoDashStatic {
/**
* Pads string on the left side if its shorter than length. Padding characters are truncated if they exceed
* length.
*
* @param string The string to pad.
* @param length The padding length.
* @param chars The string used as padding.
* @return Returns the padded string.
*/
padStart(
string?: string,
length?: number,
chars?: string
): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.padStart
*/
padStart(
length?: number,
chars?: string
): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.padStart
*/
padStart(
length?: number,
chars?: string
): LoDashExplicitWrapper<string>;
}
//_.padEnd
interface LoDashStatic {
/**
@@ -15881,6 +15826,44 @@ declare module _ {
): LoDashExplicitWrapper<string>;
}
//_.padStart
interface LoDashStatic {
/**
* Pads string on the left side if its shorter than length. Padding characters are truncated if they exceed
* length.
*
* @param string The string to pad.
* @param length The padding length.
* @param chars The string used as padding.
* @return Returns the padded string.
*/
padStart(
string?: string,
length?: number,
chars?: string
): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.padStart
*/
padStart(
length?: number,
chars?: string
): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.padStart
*/
padStart(
length?: number,
chars?: string
): LoDashExplicitWrapper<string>;
}
//_.parseInt
interface LoDashStatic {
/**
@@ -15942,6 +15925,101 @@ declare module _ {
repeat(n?: number): LoDashExplicitWrapper<string>;
}
//_.replace
interface LoDashStatic {
/**
* Replaces matches for pattern in string with replacement.
*
* Note: This method is based on String#replace.
*
* @param string
* @param pattern
* @param replacement
* @return Returns the modified string.
*/
replace(
string: string,
pattern: RegExp|string,
replacement: Function|string
): string;
/**
* @see _.replace
*/
replace(
pattern?: RegExp|string,
replacement?: Function|string
): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.replace
*/
replace(
pattern?: RegExp|string,
replacement?: Function|string
): string;
/**
* @see _.replace
*/
replace(
replacement?: Function|string
): string;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.replace
*/
replace(
pattern?: RegExp|string,
replacement?: Function|string
): string;
/**
* @see _.replace
*/
replace(
replacement?: Function|string
): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.replace
*/
replace(
pattern?: RegExp|string,
replacement?: Function|string
): LoDashExplicitWrapper<string>;
/**
* @see _.replace
*/
replace(
replacement?: Function|string
): LoDashExplicitWrapper<string>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.replace
*/
replace(
pattern?: RegExp|string,
replacement?: Function|string
): LoDashExplicitWrapper<string>;
/**
* @see _.replace
*/
replace(
replacement?: Function|string
): LoDashExplicitWrapper<string>;
}
//_.snakeCase
interface LoDashStatic {
/**
@@ -15967,6 +16045,45 @@ declare module _ {
snakeCase(): LoDashExplicitWrapper<string>;
}
//_.split
interface LoDashStatic {
/**
* Splits string by separator.
*
* Note: This method is based on String#split.
*
* @param string
* @param separator
* @param limit
* @return Returns the new array of string segments.
*/
split(
string: string,
separator?: RegExp|string,
limit?: number
): string[];
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.split
*/
split(
separator?: RegExp|string,
limit?: number
): LoDashImplicitArrayWrapper<string>;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.split
*/
split(
separator?: RegExp|string,
limit?: number
): LoDashExplicitArrayWrapper<string>;
}
//_.startCase
interface LoDashStatic {
/**
@@ -16094,21 +16211,8 @@ declare module _ {
/**
* Converts `string`, as a whole, to lower case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the lower cased string.
* @example
*
* _.toLower('--Foo-Bar');
* // => '--foo-bar'
*
* _.toLower('fooBar');
* // => 'foobar'
*
* _.toLower('__FOO_BAR__');
* // => '__foo_bar__'
* @param string The string to convert.
* @return Returns the lower cased string.
*/
toLower(string?: string): string;
}
@@ -16132,21 +16236,8 @@ declare module _ {
/**
* Converts `string`, as a whole, to upper case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the upper cased string.
* @example
*
* _.toUpper('--foo-bar');
* // => '--FOO-BAR'
*
* _.toUpper('fooBar');
* // => 'FOOBAR'
*
* _.toUpper('__foo_bar__');
* // => '__FOO_BAR__'
* @param string The string to convert.
* @return Returns the upper cased string.
*/
toUpper(string?: string): string;
}
@@ -16194,35 +16285,6 @@ declare module _ {
trim(chars?: string): LoDashExplicitWrapper<string>;
}
//_.trimStart
interface LoDashStatic {
/**
* Removes leading whitespace or specified characters from string.
*
* @param string The string to trim.
* @param chars The characters to trim.
* @return Returns the trimmed string.
*/
trimStart(
string?: string,
chars?: string
): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.trimStart
*/
trimStart(chars?: string): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.trimStart
*/
trimStart(chars?: string): LoDashExplicitWrapper<string>;
}
//_.trimEnd
interface LoDashStatic {
/**
@@ -16252,6 +16314,35 @@ declare module _ {
trimEnd(chars?: string): LoDashExplicitWrapper<string>;
}
//_.trimStart
interface LoDashStatic {
/**
* Removes leading whitespace or specified characters from string.
*
* @param string The string to trim.
* @param chars The characters to trim.
* @return Returns the trimmed string.
*/
trimStart(
string?: string,
chars?: string
): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.trimStart
*/
trimStart(chars?: string): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.trimStart
*/
trimStart(chars?: string): LoDashExplicitWrapper<string>;
}
//_.truncate
interface TruncateOptions {
/** The maximum string length. */
@@ -16273,7 +16364,7 @@ declare module _ {
*/
truncate(
string?: string,
options?: TruncateOptions|number
options?: TruncateOptions
): string;
}
@@ -16281,14 +16372,43 @@ declare module _ {
/**
* @see _.truncate
*/
truncate(options?: TruncateOptions|number): string;
truncate(options?: TruncateOptions): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.truncate
*/
truncate(options?: TruncateOptions|number): LoDashExplicitWrapper<string>;
truncate(options?: TruncateOptions): LoDashExplicitWrapper<string>;
}
//_.unescape
interface LoDashStatic {
/**
* The inverse of _.escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, &#39;, and &#96;
* in string to their corresponding characters.
*
* Note: No other HTML entities are unescaped. To unescape additional HTML entities use a third-party library
* like he.
*
* @param string The string to unescape.
* @return Returns the unescaped string.
*/
unescape(string?: string): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.unescape
*/
unescape(): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.unescape
*/
unescape(): LoDashExplicitWrapper<string>;
}
//_.upperCase
@@ -16296,21 +16416,8 @@ declare module _ {
/**
* Converts `string`, as space separated words, to upper case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the upper cased string.
* @example
*
* _.upperCase('--foo-bar');
* // => 'FOO BAR'
*
* _.upperCase('fooBar');
* // => 'FOO BAR'
*
* _.upperCase('__foo_bar__');
* // => 'FOO BAR'
* @param string The string to convert.
* @return Returns the upper cased string.
*/
upperCase(string?: string): string;
}
@@ -16334,18 +16441,8 @@ declare module _ {
/**
* Converts the first character of `string` to upper case.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the converted string.
* @example
*
* _.upperFirst('fred');
* // => 'Fred'
*
* _.upperFirst('FRED');
* // => 'FRED'
* @param string The string to convert.
* @return Returns the converted string.
*/
upperFirst(string?: string): string;
}
@@ -16364,51 +16461,14 @@ declare module _ {
upperFirst(): LoDashExplicitWrapper<string>;
}
//_.unescape
interface LoDashStatic {
/**
* The inverse of _.escape; this method converts the HTML entities &amp;, &lt;, &gt;, &quot;, &#39;, and &#96;
* in string to their corresponding characters.
*
* @param string The string to unescape.
* @return Returns the unescaped string.
*/
unescape(string?: string): string;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.unescape
*/
unescape(): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.unescape
*/
unescape(): LoDashExplicitWrapper<string>;
}
//_.words
interface LoDashStatic {
/**
* Splits `string` into an array of its words.
*
* @static
* @memberOf _
* @category String
* @param {string} [string=''] The string to inspect.
* @param {RegExp|string} [pattern] The pattern to match words.
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
* @returns {Array} Returns the words of `string`.
* @example
*
* _.words('fred, barney, & pebbles');
* // => ['fred', 'barney', 'pebbles']
*
* _.words('fred, barney, & pebbles', /[^, ]+/g);
* // => ['fred', 'barney', '&', 'pebbles']
* @param string The string to inspect.
* @param pattern The pattern to match words.
* @return Returns the words of `string`.
*/
words(
string?: string,