source: node_modules/es-toolkit/dist/compat/string/truncate.d.ts@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.7 KB
Line 
1type TruncateOptions = {
2 length?: number;
3 separator?: string | RegExp;
4 omission?: string;
5};
6/**
7 * This regex might more completely detect unicode, but it is slower and this project
8 * desires to mimic the behavior of lodash.
9 */
10/**
11 * Truncates `string` if it's longer than the given maximum string length.
12 * The last characters of the truncated string are replaced with the omission
13 * string which defaults to "...".
14 *
15 * @param {string} [string=''] The string to truncate.
16 * @param {Object} [options={}] The options object.
17 * @param {number} [options.length=30] The maximum string length.
18 * @param {string} [options.omission='...'] The string to indicate text is omitted.
19 * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
20 *
21 * @example
22 * const test = 'hi-diddly-ho there, neighborino';
23 * const truncatedStr1 = truncate(test) // returns 'hi-diddly-ho there, neighbo...'
24 * const truncatedStr2 = truncate(test, { length: 24, separator: ' ' }) // returns 'hi-diddly-ho there,...'
25 * const truncatedStr3 = truncate(test, { length: 24, separator: /,? +/ }) // returns 'hi-diddly-ho there...'
26 * const truncatedStr4 = truncate(test, { omission: ' [...]' }) // returns 'hi-diddly-ho there, neig [...]'
27 * const truncatedStr5 = truncate('ABC', { length: 3 }) // returns 'ABC'
28 * const truncatedStr6 = truncate('ABC', { length: 2 }) // returns '...'
29 * const truncatedStr7 = truncate('¥§✈✉🤓', { length: 5 }) // returns '¥§✈✉🤓'
30 * const truncatedStr8 = truncate('¥§✈✉🤓', { length: 4, omission: '…' }) // returns '¥§✈…'
31 */
32declare function truncate(string?: string, options?: TruncateOptions): string;
33
34export { truncate };
Note: See TracBrowser for help on using the repository browser.