Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: cheerio
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with a single custom sponsorship URL
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ node_js:
- "unstable"
- "6"
- "4"
- "0.12"
script: make travis-test
matrix:
fast_finish: true
Expand Down
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cheerio.js.org
27 changes: 24 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ $.html()
//=> <h2 class="title welcome">Hello there!</h2>
```

## Note

We are currently working on the 1.0.0 release of cheerio on the `master` branch. The source code for the last published version, `0.22.0`, can be found [here](https://github.com/cheeriojs/cheerio/tree/aa90399c9c02f12432bfff97b8f1c7d8ece7c307).

## Installation
`npm install react-native-cheerio`

Expand Down Expand Up @@ -44,6 +48,7 @@ $.html()
<details>
<summary>Forms</summary>

- [.serialize()](#serialize)
- [.serializeArray()](#serializearray)
</details>
<details>
Expand Down Expand Up @@ -198,6 +203,13 @@ $('li[class=orange]').html()
//=> Orange
```

##### XML Namespaces
You can select with XML Namespaces but [due to the CSS specification](https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#attribute-selectors), the colon (`:`) needs to be escaped for the selector to be valid.

```js
$('[xml\\:id="main"');
```

### Attributes
Methods for getting and modifying attributes.

Expand Down Expand Up @@ -324,6 +336,15 @@ Checks the current list of elements and returns `true` if _any_ of the elements

### Forms

#### .serialize()

Encodes a set of form elements as a URL query string.

```js
$('<form><input name="foo" value="bar" checked /><input name="foo" value="qux" checked /></form>').serialize()
//=> foo=bar&foo=qux
```

#### .serializeArray()

Encode a set of form elements as an array of names and values.
Expand Down Expand Up @@ -856,7 +877,7 @@ $('li').wrap(healthy)
// </ul>
```

#### .css( [propertName] ) <br /> .css( [ propertyNames] ) <br /> .css( [propertyName], [value] ) <br /> .css( [propertName], [function] ) <br /> .css( [properties] )
#### .css( [propertyName] ) <br /> .css( [ propertyNames] ) <br /> .css( [propertyName], [value] ) <br /> .css( [propertyName], [function] ) <br /> .css( [properties] )

Get the value of a style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.

Expand Down Expand Up @@ -941,7 +962,7 @@ $.root().append('<ul id="vegetables"></ul>').html();
Checks to see if the `contained` DOM element is a descendant of the `container` DOM element.

#### $.parseHTML( data [, context ] [, keepScripts ] )
Parses a string into an array of DOM nodes. The `context` argument has no meaning for Cheerio, but it is maintained for API compatability.
Parses a string into an array of DOM nodes. The `context` argument has no meaning for Cheerio, but it is maintained for API compatibility.

#### $.load( html[, options ] )
Load in the HTML. (See the previous section titled "Loading" for more information.)
Expand All @@ -961,7 +982,7 @@ $('body').logHtml(); // logs "Hello, <b>world</b>!" to the console

### The "DOM Node" object

Cheerio collections are made up of objects that bear some resemblence to [browser-based DOM nodes](https://developer.mozilla.org/en-US/docs/Web/API/Node). You can expect them to define the following properties:
Cheerio collections are made up of objects that bear some resemblance to [browser-based DOM nodes](https://developer.mozilla.org/en-US/docs/Web/API/Node). You can expect them to define the following properties:

- `tagName`
- `parentNode`
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
25 changes: 12 additions & 13 deletions benchmark/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ Suites.prototype.add = function(name, fileName, options) {
Suites.prototype._benchJsDom = function(suite, markup, options) {
var testFn = options.test;

jsdom.env({
html: markup,
scripts: jQuerySrc,
done: function(err, window) {
var setupData;
if (options.setup) {
setupData = options.setup.call(null, window.$);
}
suite.add('jsdom', function() {
testFn.call(null, window.$, setupData);
});
suite.run();
}
var { JSDOM } = jsdom;
var { window } = new JSDOM(markup);
window.$ = require(jQuerySrc)(window);

var setupData;
if (options.setup) {
setupData = options.setup.call(null, window.$);
}
suite.add('jsdom', function() {
testFn.call(null, window.$, setupData);
});
suite.run();

};

Suites.prototype._benchCheerio = function(suite, markup, options) {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exports.attr = function(name, value) {
var getProp = function (el, name) {
if (!el || !isTag(el)) return;

return el.hasOwnProperty(name)
return name in el
? el[name]
: rboolean.test(name)
? getAttr(el, name) !== undefined
Expand Down
4 changes: 4 additions & 0 deletions lib/api/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function setCss(el, prop, val, idx) {
*/

function getCss(el, prop) {
if(!el || !el.attribs) {
return undefined;
}

var styles = parse(el.attribs.style);
if (typeof prop === 'string') {
return styles[prop];
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
"node": ">= 0.6"
},
"dependencies": {
"css-select": "~1.2.0",
"dom-serializer": "~0.1.0",
"entities": "~1.1.1",
"htmlparser2-without-node-native": "^3.9.0",
"lodash": "^4.15.0"
"htmlparser2-without-node-native": "^3.9.2",
"css-select": "~2.0.2",
"dom-serializer": "~0.1.1",
"entities": "~1.1.2",
"lodash": "^4.17.11"
},
"devDependencies": {
"benchmark": "^2.1.0",
"coveralls": "^2.11.9",
"benchmark": "^2.1.4",
"coveralls": "^3.0.2",
"expect.js": "~0.3.1",
"istanbul": "^0.4.3",
"jsdom": "^9.2.1",
"jquery": "^3.0.0",
"jshint": "^2.9.2",
"mocha": "^3.1.2",
"xyz": "~1.1.0"
"istanbul": "^0.4.5",
"jquery": "^3.3.1",
"jsdom": "^13.2.0",
"jshint": "^2.10.1",
"mocha": "^5.2.0",
"xyz": "~3.0.0"
},
"scripts": {
"test": "make test"
"test": "jshint lib/ test/ && mocha --recursive --reporter dot"
}
}
7 changes: 6 additions & 1 deletion test/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ describe('$(...)', function() {
});

describe('.prop', function () {
var checkbox;
var checkbox, selectMenu;

beforeEach(function () {
$ = cheerio.load(inputs);
selectMenu = $('select');
checkbox = $('input[name=checkbox_on]');
});

Expand Down Expand Up @@ -186,6 +187,10 @@ describe('$(...)', function() {
expect($(undefined).prop('prop')).to.be(undefined);
expect($(null).prop('prop')).to.be(undefined);
});

it('(inherited properties) : prop should support inherited properties', function() {
expect(selectMenu.prop('childNodes')).to.equal(selectMenu[0].childNodes);
});
});

describe('.data', function() {
Expand Down
10 changes: 10 additions & 0 deletions test/api/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ describe('$(...)', function() {
expect(el.css()).to.eql({position:'absolute'});
});

it('(prop): should return undefined for unmatched elements', function() {
var $ = cheerio.load('<li style="color:;position:absolute;">');
expect($('ul').css('background-image')).to.eql(undefined);
});

it('(prop): should return undefined for unmatched styles', function() {
var el = cheerio('<li style="color:;position:absolute;">');
expect(el.css('margin')).to.eql(undefined);
});

describe('(prop, function):', function() {
beforeEach(function() {
this.$el = cheerio('<div style="margin: 0px;"></div><div style="margin: 1px;"></div><div style="margin: 2px;">');
Expand Down
8 changes: 2 additions & 6 deletions test/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ describe('$(...)', function() {
it('should throw a SyntaxError if given an invalid selector', function() {
expect(function() {
$('#fruits').find(':bah');
}).to.throwException(function(err) {
expect(err).to.be.a(SyntaxError);
});
}).to.throwException(/unmatched pseudo-class/);
});

describe('(cheerio object) :', function() {
Expand Down Expand Up @@ -456,9 +454,7 @@ describe('$(...)', function() {
it('(selector) : should throw a SyntaxError if given an invalid selector', function() {
expect(function() {
$('.orange').siblings(':bah');
}).to.throwException(function(err) {
expect(err).to.be.a(SyntaxError);
});
}).to.throwException(/unmatched pseudo-class/);
});

it('(selector) : does not consider the contents of siblings when filtering (GH-374)', function() {
Expand Down
8 changes: 6 additions & 2 deletions test/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ describe('cheerio', function() {
// });

it('(buffer) : should accept a buffer', function() {
var $html = cheerio.load(new Buffer('<div>foo</div>'));
expect($html.html()).to.be('<div>foo</div>');
var html = '<div>foo</div>';
var buf = Buffer.from && Buffer.from !== Uint8Array.from
? Buffer.from(html)
: new Buffer(html);
var $html = cheerio.load(buf);
expect($html.html()).to.be(html);
});

});
Expand Down
8 changes: 1 addition & 7 deletions test/cheerio.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ describe('cheerio', function() {
expect($fruits[0].attribs.id).to.equal('fruits');
});

it('should select first element $(:first)');
// var $elem = $(':first', fruits);
// var $h2 = $('<h2>fruits</h2>');
// console.log($elem.before('hi'));
// console.log($elem.before($h2));

it('should be able to select immediate children: $("#fruits > .pear")', function() {
var $food = $(food);
$('.pear', $food).append('<li class="pear">Another Pear!</li>');
Expand Down Expand Up @@ -368,7 +362,7 @@ describe('cheerio', function() {
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>',
// since parsing done without xmlMode flag, all tags converted to lowercase
expectedXml = '<mixedcasetag uppercaseattribute=""/>',
expectedNoXml = '<mixedcasetag uppercaseattribute=""></mixedcasetag>',
expectedNoXml = '<mixedcasetag uppercaseattribute></mixedcasetag>',
dom = $.load(str);

expect(dom('MixedCaseTag').get(0).tagName).to.equal('mixedcasetag');
Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--reporter list
--growl