super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
41 lines (40 loc) • 1.03 kB
TypeScript
/**
* 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
* @returns The truncated string
*
* @example
* ```ts
* truncate('hi-diddly-ho there, neighborino');
* // => 'hi-diddly-ho there, neighbo...'
*
* truncate('hi-diddly-ho there, neighborino', {
* length: 24,
* omission: ' [...]'
* });
* // => 'hi-diddly-ho there [...]'
*
* truncate('hi-diddly-ho there, neighborino', {
* length: 24,
* omission: ' [...]',
* separator: ' '
* });
* // => 'hi-diddly-ho there [...]'
*
* truncate('hi-diddly-ho there, neighborino', {
* length: 24,
* omission: ' [...]',
* separator: /,? +/
* });
* // => 'hi-diddly-ho there [...]'
* ```
*/
export declare function truncate(string: string, options?: {
length?: number;
omission?: string;
separator?: string | RegExp;
}): string;