Comparing version 0.10.7 to 0.10.8
0.10.8 / 2013-03-11 | ||
================== | ||
* Add slice method (SBoudrias) | ||
0.10.7 / 2013-02-10 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -113,1 +113,5 @@ var _ = require('underscore'), | ||
}; | ||
var slice = exports.slice = function() { | ||
return this.make([].slice.apply(this, arguments)); | ||
}; |
@@ -6,3 +6,3 @@ { | ||
"keywords": ["htmlparser", "jquery", "selector", "scraper"], | ||
"version": "0.10.7", | ||
"version": "0.10.8", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -229,2 +229,13 @@ # cheerio [![Build Status](https://secure.travis-ci.org/MatthewMueller/cheerio.png?branch=master)](http://travis-ci.org/MatthewMueller/cheerio) | ||
#### .slice( start, [end] ) | ||
Gets the elements matching the specified range | ||
```js | ||
$('li').slice(1).eq(0).text() | ||
//=> 'Orange' | ||
$('li').slice(1, 2).length | ||
//=> 1 | ||
``` | ||
#### .siblings() | ||
@@ -231,0 +242,0 @@ Gets the first selected element's siblings, excluding itself. |
@@ -226,2 +226,30 @@ var expect = require('expect.js'), | ||
describe('.slice', function() { | ||
function getText(el) { | ||
if(!el.length) return ''; | ||
return el[0].children[0].data; | ||
} | ||
it('(start) : should return all elements after the given index', function() { | ||
var sliced = $('li', fruits).slice(1); | ||
expect(sliced).to.have.length(2); | ||
expect(getText(sliced.eq(0))).to.equal('Orange'); | ||
expect(getText(sliced.eq(1))).to.equal('Pear'); | ||
}); | ||
it('(start, end) : should return all elements matching the given range', function() { | ||
var sliced = $('li', fruits).slice(1, 2); | ||
expect(sliced).to.have.length(1); | ||
expect(getText(sliced.eq(0))).to.equal('Orange'); | ||
}); | ||
it('(-start) : should return element matching the offset from the end', function() { | ||
var sliced = $('li', fruits).slice(-1); | ||
expect(sliced).to.have.length(1); | ||
expect(getText(sliced.eq(0))).to.equal('Pear'); | ||
}); | ||
}); | ||
}); |
95474
1958
588