@shelf/trim-around-tag
v3.1.0
Published
Trims text to max length around custom HTML tag
Downloads
824
Maintainers
Keywords
Readme
trim-around-tag
Trims text to max length around custom HTML tag
Lives in this monorepo now; previously published from the standalone shelfio/trim-around-tag repo. The npm package name stays @shelf/trim-around-tag so external consumers keep working.
Usage
import {trimTextAroundTag} from '@shelf/trim-around-tag';
trimTextAroundTag({
// Long text to trim around HTML tag
// There is <em> text somewhere inside
text: 'Long text with a <em>highlighted</em> term somewhere inside...',
// Max length of chars to leave around HTML tag
maxLengthAround: 200,
// Max total length of resulting string
maxTotalLength: 500,
// HTML tag to trim text around
tag: 'em',
// (Optional) add '...' from cut side
omission: '...',
});
//=> text trimmed to ~200 chars around each <em>highlighted</em> term