Comparing version 0.10.0 to 0.10.1
@@ -0,1 +1,6 @@ | ||
0.10.1 / 2012-10-04 | ||
=================== | ||
* Fixed regression, filtering with a context (#106) | ||
0.10.0 / 2012-09-24 | ||
@@ -2,0 +7,0 @@ =================== |
@@ -1,2 +0,6 @@ | ||
exports = module.exports = process.env.EXPRESS_COV | ||
/** | ||
* Export cheerio (with ) | ||
*/ | ||
exports = module.exports = process.env.CHEERIO_COV | ||
? require('./lib-cov/cheerio') | ||
@@ -8,2 +12,3 @@ : require('./lib/cheerio'); | ||
*/ | ||
exports.version = require('./package').version; |
@@ -52,3 +52,3 @@ var _ = require('underscore'), | ||
return this; | ||
} else if(elem.attribs[name]) { | ||
} else if(Object.hasOwnProperty.call(elem.attribs, name)) { | ||
// Get the (decoded) attribute | ||
@@ -64,3 +64,3 @@ return decode(elem.attribs[name]); | ||
function removeAttribute(elem, name) { | ||
if (!isTag(elem.type) || !elem.attribs || !elem.attribs[name]) | ||
if (!isTag(elem.type) || !elem.attribs || !Object.hasOwnProperty.call(elem.attribs, name)) | ||
return; | ||
@@ -67,0 +67,0 @@ |
@@ -19,43 +19,22 @@ var _ = require('underscore'), | ||
var append = exports.append = function() { | ||
var elems = slice.call(arguments), | ||
dom = makeCheerioArray(elems); | ||
var _insert = function(concatenator) { | ||
return function() { | ||
var elems = slice.call(arguments), | ||
dom = makeCheerioArray(elems); | ||
this.each(function(i, el) { | ||
if (_.isFunction(elems[0])) { | ||
// No yet supported | ||
return this; | ||
} else { | ||
if (!el.children) el.children = []; | ||
el.children = el.children.concat(dom); | ||
updateDOM(el.children, el); | ||
} | ||
}); | ||
return this; | ||
return this.each(function(i, el) { | ||
if (_.isFunction(elems[0])) return el; // not yet supported | ||
updateDOM(concatenator(dom, el.children || (el.children = [])), el); | ||
}); | ||
}; | ||
}; | ||
var append = exports.append = _insert(function(dom, children) { | ||
return children.concat(dom); | ||
}); | ||
/* | ||
TODO: Refactor, only one line difference between, | ||
this function and append | ||
*/ | ||
var prepend = exports.prepend = function() { | ||
var elems = slice.call(arguments), | ||
dom = makeCheerioArray(elems); | ||
var prepend = exports.prepend = _insert(function(dom, children) { | ||
return dom.concat(children); | ||
}); | ||
this.each(function(i, el) { | ||
if (_.isFunction(elems[0])) { | ||
// No yet supported | ||
return this; | ||
} else { | ||
if (!el.children) el.children = []; | ||
el.children = dom.concat(el.children); | ||
updateDOM(el.children, el); | ||
} | ||
}); | ||
return this; | ||
}; | ||
var after = exports.after = function() { | ||
@@ -62,0 +41,0 @@ var elems = slice.call(arguments), |
@@ -58,8 +58,15 @@ /* | ||
// Normalize the context | ||
if(context) { | ||
if( typeof context === 'string' ) context = parse(context).children; | ||
context = this.make(context, this); | ||
} else { | ||
// If we don't have a context, maybe we have a root, from loading | ||
if(!context) { | ||
context = this._root; | ||
} else if(typeof context === 'string') { | ||
if(isHtml(context)) { | ||
// $('li', '<ul>...</ul>') | ||
context = parse(context).children; | ||
context = this.make(context, this); | ||
} else { | ||
// $('li', 'ul') | ||
selector = [context, selector].join(' '); | ||
context = this._root; | ||
} | ||
} | ||
@@ -66,0 +73,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"keywords": ["htmlparser", "jquery", "selector", "scraper"], | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -446,21 +446,2 @@ # cheerio [![Build Status](https://secure.travis-ci.org/MatthewMueller/cheerio.png?branch=master)](http://travis-ci.org/MatthewMueller/cheerio) | ||
#### .get( [index] ) | ||
Retrieve the DOM elements matched by the cheerio object. If no index is specified, it will get an array of all matched elements. | ||
```js | ||
$('li').get(0) | ||
//=> { raw: 'li class="apple"', ... } | ||
$('li').get() | ||
//=> [ {...}, {...}, {...} ] | ||
``` | ||
#### .size() | ||
Return the number of elements in the cheerio object. Same as `length`. | ||
```js | ||
$('li').size() | ||
//=> 3 | ||
``` | ||
#### .toArray() | ||
@@ -467,0 +448,0 @@ Retrieve all the DOM elements contained in the jQuery set, as an array. |
@@ -13,3 +13,3 @@ var expect = require('expect.js'), | ||
it('should get the version', function() { | ||
expect(/\d\.\d\.\d/.test($.version)).to.be.ok(); | ||
expect(/\d+\.\d+\.\d+/.test($.version)).to.be.ok(); | ||
}); | ||
@@ -82,2 +82,11 @@ | ||
it('should be able to filter down using the context', function() { | ||
var q = $.load(fruits), | ||
apple = q('.apple', 'ul'), | ||
lis = q('li', 'ul'); | ||
expect(apple).to.have.length(1); | ||
expect(lis).to.have.length(3); | ||
}); | ||
it('should be able to select multiple tags', function() { | ||
@@ -84,0 +93,0 @@ var $fruits = $('li', null, fruits); |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
88478
1834
600