lodash: changed _.trunc() method

This commit is contained in:
Ilya Mochalov
2015-08-21 06:07:26 +05:00
parent bb45306d0f
commit a0143072d6
2 changed files with 31 additions and 2 deletions
+6
View File
@@ -1706,11 +1706,17 @@ result = <string>_.trimRight('-_-abc-_-', '_-');
result = <string>_('-_-abc-_-').trimRight();
result = <string>_('-_-abc-_-').trimRight('_-');
// _.trunc
result = <string>_.trunc('hi-diddly-ho there, neighborino');
result = <string>_.trunc('hi-diddly-ho there, neighborino', 24);
result = <string>_.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' });
result = <string>_.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ });
result = <string>_.trunc('hi-diddly-ho there, neighborino', { 'omission': ' […]' });
result = <string>_('hi-diddly-ho there, neighborino').trunc();
result = <string>_('hi-diddly-ho there, neighborino').trunc(24);
result = <string>_('hi-diddly-ho there, neighborino').trunc({ 'length': 24, 'separator': ' ' });
result = <string>_('hi-diddly-ho there, neighborino').trunc({ 'length': 24, 'separator': /,? +/ });
result = <string>_('hi-diddly-ho there, neighborino').trunc({ 'omission': ' […]' });
// _.unescape
result = <string>_.unescape('fred, barney, &amp; pebbles');
+25 -2
View File
@@ -7587,9 +7587,32 @@ declare module _ {
trimRight(chars?: string): string;
}
//_.trunc
interface TruncOptions {
/** The maximum string length. */
length?: number;
/** The string to indicate text is omitted. */
omission?: string;
/** The separator pattern to truncate to. */
separator?: string|RegExp;
}
interface LoDashStatic {
trunc(str?: string, len?: number): string;
trunc(str?: string, options?: { length?: number; omission?: string; separator?: string|RegExp }): string;
/**
* Truncates string if its longer than the given maximum string length. The last characters of the truncated
* string are replaced with the omission string which defaults to "…".
* @param string The string to truncate.
* @param options The options object or maximum string length.
* @return Returns the truncated string.
*/
trunc(string?: string, options?: TruncOptions|number): string;
}
interface LoDashWrapper<T> {
/**
* @see _.trunc
*/
trunc(options?: TruncOptions|number): string;
}
//_.unescape