UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

53 lines (52 loc) 1.25 kB
/** * @ignore */ interface Options { length?: number; omission?: any; separator?: RegExp | string; } /** * @ignore */ interface ToStringAble { toString(): 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 "...". * * @since 5.6.0 * @category String * @param str The string to truncate. * @param options The options object. * @returns Returns the truncated string. * @see [[replace]] * @example * * ```js * truncate('hi-diddly-ho there, neighborino') * // => 'hi-diddly-ho there, neighbo...' * * truncate('hi-diddly-ho there, neighborino', { * 'length': 24, * 'separator': ' ' * }) * // => 'hi-diddly-ho there,...' * * truncate('hi-diddly-ho there, neighborino', { * 'length': 24, * 'separator': /,? +/ * }) * // => 'hi-diddly-ho there...' * * truncate('hi-diddly-ho there, neighborino', { * 'omission': ' [...]' * }) * // => 'hi-diddly-ho there, neig [...]' * ``` */ export declare function truncate(str: ToStringAble, options?: Options): string; export declare function truncate(str: string, options?: Options): string; export default truncate;