From a0143072d67e316c8d2f1ceac4ab246e156d7c92 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 21 Aug 2015 06:07:26 +0500 Subject: [PATCH] lodash: changed _.trunc() method --- lodash/lodash-tests.ts | 6 ++++++ lodash/lodash.d.ts | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2cbec6853..a63e308ac 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1706,11 +1706,17 @@ result = _.trimRight('-_-abc-_-', '_-'); result = _('-_-abc-_-').trimRight(); result = _('-_-abc-_-').trimRight('_-'); +// _.trunc result = _.trunc('hi-diddly-ho there, neighborino'); result = _.trunc('hi-diddly-ho there, neighborino', 24); result = _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': ' ' }); result = _.trunc('hi-diddly-ho there, neighborino', { 'length': 24, 'separator': /,? +/ }); result = _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' […]' }); +result = _('hi-diddly-ho there, neighborino').trunc(); +result = _('hi-diddly-ho there, neighborino').trunc(24); +result = _('hi-diddly-ho there, neighborino').trunc({ 'length': 24, 'separator': ' ' }); +result = _('hi-diddly-ho there, neighborino').trunc({ 'length': 24, 'separator': /,? +/ }); +result = _('hi-diddly-ho there, neighborino').trunc({ 'omission': ' […]' }); // _.unescape result = _.unescape('fred, barney, & pebbles'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c088f5459..e9248577a 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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 it’s 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 { + /** + * @see _.trunc + */ + trunc(options?: TruncOptions|number): string; } //_.unescape