1 | import { CheerioAPI } from "cheerio";
|
2 | /**
|
3 | * truncate-html full options object
|
4 | */
|
5 | export interface IFullOptions {
|
6 | /**
|
7 | * remove all tags, default false
|
8 | */
|
9 | stripTags: boolean;
|
10 | /**
|
11 | * ellipsis sign, default '...'
|
12 | */
|
13 | ellipsis: string;
|
14 | /**
|
15 | * decode html entities(e.g. convert `&` to `&`) before counting length, default false
|
16 | */
|
17 | decodeEntities: boolean;
|
18 | /**
|
19 | * elements' selector you want ignore
|
20 | */
|
21 | excludes: string | string[];
|
22 | /**
|
23 | * how many letters(words if `byWords` is true) you want reserve
|
24 | */
|
25 | length: number;
|
26 | /**
|
27 | * if true, length means how many words to reserve
|
28 | */
|
29 | byWords: boolean;
|
30 | /**
|
31 | * how to deal with when truncate in the middle of a word
|
32 | * 1. by default, just cut at that position.
|
33 | * 2. set it to true, with max exceed 10 letters can exceed to reserver the last word
|
34 | * 3. set it to a positive number decide how many letters can exceed to reserve the last word
|
35 | * 4. set it to negetive number to remove the last word if cut in the middle.
|
36 | */
|
37 | reserveLastWord: boolean | number;
|
38 | /**
|
39 | * if reserveLastWord set to negetive number, and there is only one word in the html string, when trimTheOnlyWord set to true, the extra letters will be cutted if word's length longer than `length`.
|
40 | * see issue #23 for more details
|
41 | */
|
42 | trimTheOnlyWord: boolean;
|
43 | /**
|
44 | * keep whitespaces, by default continuous paces will
|
45 | * be replaced with one space, set it true to keep them
|
46 | */
|
47 | keepWhitespaces: boolean;
|
48 | }
|
49 | /**
|
50 | * options interface for function
|
51 | */
|
52 | export type IOptions = Partial<IFullOptions>;
|
53 | /**
|
54 | * truncate html interface
|
55 | */
|
56 | interface ITruncateHtml {
|
57 | (html: string | CheerioAPI, length?: number, options?: IOptions): string;
|
58 | (html: string | CheerioAPI, options?: IOptions): string;
|
59 | setup: (option: IOptions) => void;
|
60 | }
|
61 | /**
|
62 | * truncate html
|
63 | * @method truncate(html, [length], [options])
|
64 | * @param {String} html html string to truncate
|
65 | * @param {Object|number} length how many letters(words if `byWords` is true) you want reserve
|
66 | * @param {Object|null} options
|
67 | * @return {String}
|
68 | */
|
69 | declare const truncate: ITruncateHtml;
|
70 | export default truncate;
|