Skip to content

Releases: oe/truncate-html

custom truncate strategy

Choose a tag to compare

@oe oe released this 20 Jan 15:28

A new option customNodeStrategy has been added. Check readme for details.

For your requirements, the following code may achieve your needs:

import truncate, { type IOptions, type ICustomNodeStrategy } from 'truncate-html'

// argument node is a cheerio instance
const customNodeStrategy: ICustomNodeStrategy = node => {
  // keep details and treat it as nothing inside
  if (node.is('details')) {
    return 'keep'
  }
}

const html = '<div><details><summary>Click me</summary><p>Some details</p></details>other things</div>'

const options: IOptions = {
  length: 3,
  customNodeStrategy
}

truncate(html, options)
// => <div><details><summary>Click me</summary><p>Some details</p></details>oth...</div>

ref: #41

Fix Cheerio's break changes

Choose a tag to compare

@oe oe released this 15 Aug 17:36

Cheerio released stable v1.0 a few days ago, but its APIs are very different from the latest beta version 1.0.0-rc.12, which breaks this lib.

The v1.1.2 release has pinned the cheerio version to 1.0.0-rc.12 to fix the cheerio problem.

Reference:

  1. Cheerio 1.0 released, batteries included 🔋
  2. cheerio#4024, more issues about cheerio

Cheerio spent years on beta version of 1.0, and then bring so many break changes in stable version? Unbelievable!

update cheerio to v1.0.0-rc.12

Choose a tag to compare

@oe oe released this 02 Mar 15:12
8958596

There are several changes:

  1. no vulnerabilities
    CleanShot 2023-06-17 at 20 37 48
  2. cheerio can now handle CJK characters correctly
  3. if you are using custom cheerio instance with this library, you should set the third parameter of cheerio.load to false to get rid of extra wrappers, see load for details.
  4. better support for typescript

v1.0.0 has been released🎉

Choose a tag to compare

@oe oe released this 18 Mar 15:51

After a hard work, thanks to @calebeno v1.0.0 has been released

  1. added test cases, covered all statements/lines/branches, fixed some bugs, you can use truncate-html with faith
  2. added new option reserveLastWord to deal with when truncate in the middle of a word
  3. supports ES6 Modules, optimized for webpack/rollup
  4. upgraded cheerio to v0.22.0

Added test cases and `options.reserveLastWord`

Choose a tag to compare

@oe oe released this 03 Feb 16:46
  1. added test cases, covered all statements/lines/branches, fixed some bugs.
  2. added new option reserveLastWord to deal with when truncate in the middle of a word
  3. supports ES6 Modules, optimized for webpack/rollup

Thanks to @cenoicc 's help

truncating by words just supported

Choose a tag to compare

@oe oe released this 03 Mar 15:41

By setting option byWords to true, then option length means word count.

extra whitespaces can be reserved now

Choose a tag to compare

@oe oe released this 21 Jul 08:25

By setting option keepWhitespaces to true, you can keep the extra whitespaces when dealing with tags like pre.

By default continuous whitespace will be replaced to one space, setting keepWhitespaces to true can disable it.

fixed the issue when handing CJK characters

Choose a tag to compare

@oe oe released this 26 Nov 07:49
v0.0.6