truncate-html
- Version 1.1.2
- Published
- 32.3 kB
- 1 dependency
- MIT license
Install
npm i truncate-html
yarn add truncate-html
pnpm add truncate-html
Overview
Truncate HTML and Keep Tags
Index
Variables
variable truncate
const truncate: ITruncateHtml;
truncate html truncate(html, [length], [options])
Parameter html
html string to truncate
Parameter length
how many letters(words if
byWords
is true) you want reserveParameter options
{String}
Interfaces
interface IFullOptions
interface IFullOptions {}
truncate-html full options object
property byWords
byWords: boolean;
if true, length means how many words to reserve
property decodeEntities
decodeEntities: boolean;
decode html entities(e.g. convert
&
to&
) before counting length, default false
property ellipsis
ellipsis: string;
ellipsis sign, default '...'
property excludes
excludes: string | string[];
elements' selector you want ignore
property keepWhitespaces
keepWhitespaces: boolean;
keep whitespaces, by default continuous paces will be replaced with one space, set it true to keep them
property length
length: number;
how many letters(words if
byWords
is true) you want reserve
property reserveLastWord
reserveLastWord: boolean | number;
how to deal with when truncate in the middle of a word 1. by default, just cut at that position. 2. set it to true, with max exceed 10 letters can exceed to reserver the last word 3. set it to a positive number decide how many letters can exceed to reserve the last word 4. set it to negetive number to remove the last word if cut in the middle.
property stripTags
stripTags: boolean;
remove all tags, default false
property trimTheOnlyWord
trimTheOnlyWord: boolean;
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
. see issue #23 for more details
Type Aliases
type IOptions
type IOptions = Partial<IFullOptions>;
options interface for function
Package Files (1)
Dependencies (1)
Dev Dependencies (13)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/truncate-html
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/truncate-html)
- HTML<a href="https://www.jsdocs.io/package/truncate-html"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2562 ms. - Missing or incorrect documentation? Open an issue for this package.