Socket
Socket
Sign inDemoInstall

cheerio

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheerio - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

cheerio.tmproj

9

History.md

@@ -0,1 +1,8 @@

0.2.2 / 2011-11-9
=================
* Traversing will select `<script>` and `<style>` tags (Closes Issue: #8)
* .text(string) now working with empty elements (Closes Issue: #7)
* Fixed before(...) & after(...) again if there is no parent (Closes Issue: #2)
0.2.1 / 2011-11-5

@@ -8,5 +15,5 @@ =================

> 0.2.0 / 2011-10-31
< 0.2.0 / 2011-10-31
==================
* Initial release (untracked development)

6

lib/api/attributes.js

@@ -20,3 +20,3 @@ (function() {

elem = this[_i];
if (elem.type === "tag" && elem.attribs && (" " + elem.attribs["class"] + " ").replace(rclass, " ").indexOf(className) > -1) {
if ($.isTag(elem) && elem.attribs && (" " + elem.attribs["class"] + " ").replace(rclass, " ").indexOf(className) > -1) {
return true;

@@ -42,3 +42,3 @@ }

$elem = $(elem);
if (elem.type === "tag") {
if ($.isTag(elem)) {
if (!$elem.attr("class")) {

@@ -76,3 +76,3 @@ $elem.attr('class', classNames.join(' ').trim());

$elem = $(elem);
if (elem.type === 'tag' && $elem.attr('class')) {
if ($.isTag(elem) && $elem.attr('class')) {
if (value) {

@@ -79,0 +79,0 @@ ret = (" " + $elem.attr('class') + " ").replace(rclass, " ");

(function() {
var $, get, pushStack, size, toArray, underscore;
var $, get, pushStack, siblingsAndMe, size, toArray, underscore;
underscore = require('underscore');

@@ -41,3 +41,18 @@ $ = require('../cheerio');

};
siblingsAndMe = exports.siblingsAndMe = function() {
var element, raw, siblings;
siblings = [];
raw = this[0];
element = raw;
while (element.prev) {
element = element.prev;
}
siblings.push(element);
while (element.next) {
element = element.next;
siblings.push(element);
}
return siblings;
};
module.exports = $.fn.extend(exports);
}).call(this);

@@ -62,3 +62,3 @@ (function() {

var pos, siblings;
siblings = $.siblingsAndMe(this);
siblings = $(this).siblingsAndMe();
pos = $.inArray(this, siblings);

@@ -82,3 +82,3 @@ if (pos >= 0) {

var pos, siblings;
siblings = $.siblingsAndMe(this);
siblings = $(this).siblingsAndMe();
pos = $.inArray(this, siblings);

@@ -113,3 +113,3 @@ if (pos >= 0) {

if (domObject === void 0) {
if (this[0] && this[0].type === "tag") {
if (this[0] && $.isTag(this[0])) {
return $.dom(this[0]);

@@ -145,5 +145,3 @@ }

this.each(function(i) {
if (this.children) {
return this.children = textElement;
}
return this.children = textElement;
});

@@ -150,0 +148,0 @@ return this;

@@ -31,3 +31,3 @@ (function() {

while (nextSibling) {
if (nextSibling.type === "tag") {
if ($.isTag(nextSibling)) {
return $(nextSibling);

@@ -46,3 +46,3 @@ }

while (prevSibling) {
if (prevSibling.type === "tag") {
if ($.isTag(prevSibling)) {
return $(prevSibling);

@@ -59,6 +59,6 @@ }

} else {
sibs = $.siblingsAndMe(this);
sibs = this.siblingsAndMe();
}
siblings = _.filter(sibs, __bind(function(elem) {
return elem !== this[0] && elem.type === "tag";
return elem !== this[0] && $.isTag(elem);
}, this));

@@ -70,3 +70,3 @@ return $(siblings);

children = _.filter(this[0].children, function(elem) {
return elem.type === "tag";
return $.isTag(elem);
});

@@ -73,0 +73,0 @@ if (selector !== void 0) {

(function() {
var $, access, attr, class2type, dom, each, html, inArray, indexOf, isArray, load, makeArray, merge, parser, push, rboolean, removeAttr, renderer, siblingsAndMe, text, toString, type, updateDOM, _;
var $, access, attr, class2type, dom, each, html, inArray, indexOf, isArray, isTag, load, makeArray, merge, parser, push, rboolean, removeAttr, renderer, setRoot, tags, text, toString, type, updateDOM, _;
_ = require("underscore");

@@ -24,6 +24,23 @@ $ = require("../cheerio");

indexOf = Array.prototype.indexOf;
tags = {
'tag': 1,
'script': 1,
'style': 1
};
isTag = exports.isTag = function(type) {
if (type.type) {
type = type.type;
}
if (tags[type]) {
return true;
} else {
return false;
}
};
updateDOM = exports.updateDOM = function(arr, parent) {
var elem, i, _len;
if (parent) {
parent.children = $(arr).get();
arr = $(arr).get();
if (!parent) {
$.setRoot(arr);
parent = $.root;
}

@@ -36,3 +53,3 @@ for (i = 0, _len = arr.length; i < _len; i++) {

}
return arr;
parent.children = arr;
};

@@ -86,19 +103,2 @@ type = exports.type = function(obj) {

};
siblingsAndMe = exports.siblingsAndMe = function(elem) {
var element, raw, siblings;
siblings = [];
raw = $(elem)[0];
element = raw;
while (element.prev) {
element = element.prev;
}
siblings.push(element);
while (element.next) {
element = element.next;
if (element.type === "tag") {
siblings.push(element);
}
}
return $(null).pushStack(siblings);
};
each = exports.each = function(object, callback, args) {

@@ -166,3 +166,3 @@ var i, isObj, length, name;

type = elem.type;
if (!elem || elem.type !== "tag") {
if (!elem || !$.isTag(elem)) {
return;

@@ -200,2 +200,5 @@ }

ret = "";
if (!elems) {
return ret;
}
for (_i = 0, _len = elems.length; _i < _len; _i++) {

@@ -211,9 +214,21 @@ elem = elems[_i];

};
load = exports.load = function(html) {
var fn, root;
root = parser.parse(html);
setRoot = exports.setRoot = function(html) {
var root;
if (_.isString(html)) {
root = parser.parse(html);
} else if (html.length) {
root = html;
}
$.extend({
'root': root
});
fn = function(selector, context) {
return root;
};
load = exports.load = function(html) {
var fn, root;
root = setRoot(html);
fn = function(selector, context, r) {
if (r) {
root = setRoot(r);
}
return $(selector, context, root);

@@ -226,4 +241,4 @@ };

return renderer.render(dom);
} else if (this.root) {
return renderer.render(this.root);
} else if ($.root) {
return renderer.render($.root);
} else {

@@ -234,6 +249,8 @@ return "";

dom = exports.dom = function(dom) {
if (dom !== void 0 && dom.type) {
return dom;
} else if (this.root) {
return this.root;
if (dom !== void 0) {
if (dom.type) {
return dom;
}
} else if ($.root) {
return $.root;
} else {

@@ -240,0 +257,0 @@ return "";

@@ -16,3 +16,3 @@ (function() {

cheerio.fn = cheerio.prototype = {
cheerio: "0.2.1",
cheerio: "0.2.2",
constructor: cheerio,

@@ -19,0 +19,0 @@ init: function(selector, context, root) {

@@ -24,3 +24,3 @@ (function() {

print = exports.print = function(dom, attr, depth, out) {
var attrs, elem, passback, prop, str, val, _i, _j, _len, _len2;
var attrs, elem, passback, prop, str, type, val, _i, _j, _len, _len2;
if (attr == null) {

@@ -37,3 +37,4 @@ attr = null;

elem = dom[_i];
if (elem.type !== "tag") {
type = elem.type;
if (type === "tag" || type === "script" || type === "style") {
continue;

@@ -40,0 +41,0 @@ }

@@ -6,3 +6,3 @@ {

"keywords": ["htmlparser", "jquery", "selector", "scraper"],
"version": "0.2.1",
"version": "0.2.2",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

# cheerio
Tiny, fast, and elegant implementation of core jQuery designed specifically for the server.
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

@@ -5,0 +5,0 @@ ## Introduction

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc