Socket
Socket
Sign inDemoInstall

cheerio

Package Overview
Dependencies
4
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.10.7 to 0.10.8

5

History.md
0.10.8 / 2013-03-11
==================
* Add slice method (SBoudrias)
0.10.7 / 2013-02-10

@@ -3,0 +8,0 @@ ==================

4

lib/api/traversing.js

@@ -113,1 +113,5 @@ var _ = require('underscore'),

};
var slice = exports.slice = function() {
return this.make([].slice.apply(this, arguments));
};

2

package.json

@@ -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');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc