The fast, flexible, and elegant library for parsing and manipulating HTML and XML.
Bugfix release. Fixed issues:
prop
undefined handling with jQuery by @fb55 in https://github.com/cheeriojs/cheerio/pull/2557
cheerio/lib/utils
by @blixt in https://github.com/cheeriojs/cheerio/pull/2601
Full Changelog: https://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.11...v1.0.0-rc.12
[email protected]
is hopefully the last RC before the 1.0.0 release of Cheerio. There are two APIs that will be added for the next major release: An exract
method (https://github.com/cheeriojs/cheerio/issues/2523) and NodeJS specific loader methods (https://github.com/cheeriojs/cheerio/issues/2051). These are still in flux and I'd appreciate feedback on the proposals.
A big thank you to everyone that contributed to this release! This includes code contributors, as well as the amazing financial support on GitHub Sponsors!
Under the hood, a lot of work for this release went into updating parse5, cheerio's default HTML parser. Have a look at parse5's release notes to see what has changed there.
script
and style
contents are added again in .text()
https://github.com/cheeriojs/cheerio/pull/2509
.text()
to .prop('innerText')
cheerio-select
https://github.com/cheeriojs/cheerio/pull/2511
pseudos
option..prop()
method:
textContent
and innerText
props https://github.com/cheeriojs/cheerio/pull/2214
baseURI
option, which will lead to href
and src
props to be resolved as URLs. https://github.com/cheeriojs/cheerio/pull/2510
slim
export, which will always use htmlparser2 https://github.com/cheeriojs/cheerio/pull/1960
text
turn passed values to strings https://github.com/cheeriojs/cheerio/pull/2047
undefined
in the return type of get
by @glen-84 in https://github.com/cheeriojs/cheerio/pull/2392
undefined
return value https://github.com/cheeriojs/cheerio/pull/2505
domutils
module directly https://github.com/cheeriojs/cheerio/pull/1928
isHTML
https://github.com/cheeriojs/cheerio/pull/1935
load
https://github.com/cheeriojs/cheerio/pull/1951
closest
https://github.com/cheeriojs/cheerio/pull/2057
Full Changelog: https://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.10...v1.0.0-rc.11
Fixes:
.html(node)
now moves passed nodes (#1923, fixes #940) 258b26bfilter
work on all collections (#1870, fixes #1867) fb8d31eDocumentation:
require
5dfbd35Refactors:
traversing
(#1909) 58e090ais
to traversing
, optimize (#1908) 1c6fa3edomEach
(#1892) feda230load
export a function (#1869) c370f4ehttps://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.9...v1.0.0-rc.10
Port to TypeScript
Cheerio has been ported entirely to TypeScript (in #1816)! This eliminates a lot of edge-cases within Cheerio and will allow you to use Cheerio with confidence. This release also features a new documentation website based on TypeDoc, allowing you to quickly navigate all available methods: https://cheerio.js.org
Breaking change: If you were using the function exported by Cheerio directly instead of first load()
ing a document, you will now have to update the require
to use the default
export.
- const cheerio = require("cheerio");
+ const cheerio = require("cheerio").default;
cheerio('div', dom)
Please note that this way of using Cheerio is deprecated and might be removed in a future version. Please consider updating your code to:
const cheerio = require("cheerio");
const $ = cheerio.load(dom)
$('div')
Note: Cheerio uses template literal types to determine return types. These are available starting with TypeScript 4.1, so you might have to bump your TypeScript version.
For TypeScript types, Cheerio now implements the ArrayLike<T>
interface. That means that Cheerio instances can contain objects of arbitrary types, but not all methods can be called on them.
The TypeScript compiler will figure out what structures you are operating on:
$('<div>')
, it will product a Cheerio<Node>
type.
Node
is the base class for DOM elements and includes eg. comment and text nodes.$('.foo')
, it will produce a Cheerio<Element>
, as only Element
s can be part of the result set.
Element
is the class representing tags.$('...').map()
to map to arbitrary values, and will get a compiler error when trying to call method that are not supported.
$('.foo').map((i, el) => $(el).text()).attr('test')
will no longer be possible, as .attr
is not allowed to be called on a Cheerio<string>
.This release does not contain other changes to functionality. Feedback is greatly appreciated; if you encounter a problem, please file an issue!
https://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.6...v1.0.0-rc.9
Second botched release. Please use v1.0.0-rc.9
instead.
Published without a lib
directory — please ignore.
Breaking:
prevAll
, prevUntil
and parentsUntil
. The new order matches jQuery.This release contains three breaking changes inherited from dependencies.
type: 'tag'
.New features:
.unwrap
(#1651 by @5saviahv) 2037d83.wrapAll
(#1590 by @5saviahv) cd4a4d9prop('innerHTML')
(#1578 by @fb55) c58258fscriptingEnabled
parse5 option (#1707 by @5saviahv) 7eb4cc4
scriptingEnabled
to false
, it is now possible to parse the contents of <noscript>
tags.Types:
.load
type (#1584 by @f0x52) 6a90bda.get
(#1759 by @karlhorky) d706976.wrapAll
(#1740 by @5saviahv) b360762for of
loops (#1704 by @mcpiroman) 8fef5aaAttrFunction
arguments (#1669 by @maxma241) 5f2e9c3Bug fixes:
undefined
as value in .attr()
(#1757 by @5saviahv) 98186e8{prev,next}Until
(#1728 by @fb55) f2615d2find
function (#1680 by @5saviahv) 9b28b49.add
modifying previous selections (#1656 by @5saviahv) 9f9b493.find
siblings (#1583 by @fb55) 1062a6creplaceWith
replacing element with itself (#1581 by @fb55) 88ae636attr
handling of undefined
as value (#1582 by @fb55) 3b35ae4load
(#1580 by @fb55) 0855be6.prop
(#1579 by @fb55) db3fce7Documentation updates:
after
, before
, slice
arguments, improve handling (#1721 by @5saviahv) 732d539package.json
(#1609 by @XhmikosR) ad3e30bRefactors:
quickExpr
(#1716 by @fb55) 4aa3d39wrapAll
, add some tests (#1640 by @5saviahv) b6d3840eqeqeq
eslint rule except for null (#1638 by @XhmikosR) 52f37a1block-scoped-var
eslint rule (#1631 by @XhmikosR) b072df8no-unused-expressions
eslunt rule (#1630 by @XhmikosR) fc2c7d5--ignore-path
(#1612 by @XhmikosR) 17f0d08CI:
actions-gh-pages
(#1626 by @fb55) 9ee60ccversioning-strategy: increase
for dependabot, format 71d2aafTest changes:
.map
test was actually calling .each
(#1711 by @Pustur) 456fbe5.toBeUndefined()
(#1659 by @XhmikosR) 5aa4272Commit Range: https://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.5...v1.0.0-rc.6
Hotfix release
cheerio-select-tmp
until naming issue is resolved 3751929https://github.com/cheeriojs/cheerio/compare/v1.0.0-rc.4...v1.0.0-rc.5
Welcome to [email protected]
! This is the last pre-release before a full 1.0.0
release — please make sure to test this release and report any issues you might find.
This release was made possible by our supporters on Open Collective. If you want to support this project going forward, have a look at sponsorship options!
Breaking:
parse5
, cheerio temporarily has a minimum Node version of Node 6. See #1585 for details.root
reference. The root node is now referenced by the parent
property.New Features:
for...of
iterator via Symbol.iterator
(#1197 by @papandreou)wrapInner
(9ffc557 by @fb55, based on work by @tomjw64 and @warrengm)removeAttr
accept a list of attributes to remove (#1561 by @fb55)prop(‘outerHTML’)
implementation (#945 by @bill-bishop)Bug Fixes:
.prev()
after replaceWith()
(#1254 by @Gei0r).xml
calls on HTML documents (#1572 by @fb55)cheerio.load()
(#1087 by @zeke)locationInfo
option to parse5 (#1155 by @trevorhreed)Other notable changes:
domhandler
nodes directly (#1564 by @fb55)https://github.com/cheeriojs/cheerio/compare/1.0.0-rc.2...v1.0.0-rc.4