nyc-bookstores/node_modules/cheerio/package.json
2013-05-27 13:45:59 -07:00

46 lines
18 KiB
JSON

{
"author": {
"name": "Matt Mueller",
"email": "mattmuelle@gmail.com",
"url": "mattmueller.me"
},
"name": "cheerio",
"description": "Tiny, fast, and elegant implementation of core jQuery designed specifically for the server",
"keywords": [
"htmlparser",
"jquery",
"selector",
"scraper"
],
"version": "0.10.8",
"repository": {
"type": "git",
"url": "git://github.com/MatthewMueller/cheerio.git"
},
"main": "./index.js",
"engines": {
"node": ">= 0.6"
},
"dependencies": {
"cheerio-select": "*",
"htmlparser2": "2.x",
"underscore": "~1.4",
"entities": "0.x"
},
"devDependencies": {
"mocha": "*",
"expect.js": "*"
},
"scripts": {
"test": "make test"
},
"readme": "# cheerio [![Build Status](https://secure.travis-ci.org/MatthewMueller/cheerio.png?branch=master)](http://travis-ci.org/MatthewMueller/cheerio)\n\nFast, flexible, and lean implementation of core jQuery designed specifically for the server.\n\n## Introduction\nTeach your server HTML.\n\n```js\nvar cheerio = require('cheerio'),\n $ = cheerio.load('<h2 class = \"title\">Hello world</h2>');\n\n$('h2.title').text('Hello there!');\n$('h2').addClass('welcome');\n\n$.html();\n//=> <h2 class = \"title welcome\">Hello there!</h2>\n```\n\n## Installation\n`npm install cheerio`\n\n## Features\n__&#10084; Familiar syntax:__\nCheerio implements a subset of core jQuery. Cheerio removes all the DOM inconsistencies and browser cruft from the jQuery library, revealing its truly gorgeous API.\n\n__&#991; Blazingly fast:__\nCheerio works with a very simple, consistent DOM model. As a result parsing, manipulating, and rendering are incredibly efficient. Preliminary end-to-end benchmarks suggest that cheerio is about __8x__ faster than JSDOM.\n\n__&#10049; Insanely flexible:__\nCheerio wraps around @FB55's forgiving htmlparser. Cheerio can parse nearly any HTML or XML document.\n\n## What about JSDOM?\nI wrote cheerio because I found myself increasingly frustrated with JSDOM. For me, there were three main sticking points that I kept running into again and again:\n\n__&#8226; JSDOM's built-in parser is too strict:__\n JSDOM's bundled HTML parser cannot handle many popular sites out there today.\n\n__&#8226; JSDOM is too slow:__\nParsing big websites with JSDOM has a noticeable delay.\n\n__&#8226; JSDOM feels too heavy:__\nThe goal of JSDOM is to provide an identical DOM environment as what we see in the browser. I never really needed all this, I just wanted a simple, familiar way to do HTML manipulation.\n\n## When I would use JSDOM\n\nCheerio will not solve all your problems. I would still use JSDOM if I needed to work in a browser-like environment on the server, particularly if I wanted to automate functional tests.\n\n## API\n\n### Markup example we'll be using:\n\n```html\n<ul id=\"fruits\">\n <li class=\"apple\">Apple</li>\n <li class=\"orange\">Orange</li>\n <li class=\"pear\">Pear</li>\n</ul>\n```\n\nThis is the HTML markup we will be using in all of the API examples.\n\n### Loading\nFirst you need to load in the HTML. This step in jQuery is implicit, since jQuery operates on the one, baked-in DOM. With Cheerio, we need to pass in the HTML document.\n\nThis is the _preferred_ method:\n\n```js\nvar cheerio = require('cheerio'),\n $ = cheerio.load('<ul id = \"fruits\">...</ul>');\n```\n\nOptionally, you can also load in the HTML by passing the string as the context:\n\n```js\n$ = require('cheerio');\n$('ul', '<ul id = \"fruits\">...</ul>');\n```\n\nOr as the root:\n\n```js\n$ = require('cheerio');\n$('li', 'ul', '<ul id = \"fruits\">...</ul>');\n```\n\nYou can also pass an extra object to `.load()` if you need to modify any\nof the default parsing options:\n\n```js\n$ = cheerio.load('<ul id = \"fruits\">...</ul>', {\n ignoreWhitespace: true,\n xmlMode: true\n});\n```\n\nThese parsing options are taken directly from htmlparser, therefore any options that can be used in htmlparser\nare valid in cheerio as well. The default options are:\n\n```js\n{\n ignoreWhitespace: false,\n xmlMode: false,\n lowerCaseTags: false\n}\n```\n\nFor a list of options and their effects, see [this](https://github.com/FB55/node-htmlparser/wiki/DOMHandler) and\n[this](https://github.com/FB55/node-htmlparser/wiki/Parser-options).\n\n### Selectors\n\nCheerio's selector implementation is nearly identical to jQuery's, so the API is very similar.\n\n#### $( selector, [context], [root] )\n`selector` searches within the `context` scope which searches within the `root` scope. `selector` and `context` can be an string expression, DOM Element, array of DOM elements, or cheerio object. `root` is typically the HTML document string.\n\nThis selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document, but unlike jQuery it's built on top of the CSSSelect library, which implements most of the Sizzle selectors.\n\n```js\n$('.apple', '#fruits').text()\n//=> Apple\n\n$('ul .pear').attr('class')\n//=> pear\n\n$('li[class=orange]').html()\n//=> <li class = \"orange\">Orange</li>\n```\n\n### Attributes\nMethods for getting and modifying attributes.\n\n#### .attr( name, value )\nMethod for getting and setting attributes. Gets the attribute value for only the first element in the matched set. If you set an attribute's value to `null`, you remove that attribute. You may also pass a `map` and `function` like jQuery.\n\n```js\n$('ul').attr('id')\n//=> fruits\n\n$('.apple').attr('id', 'favorite').html()\n//=> <li class = \"apple\" id = \"favorite\">Apple</li>\n```\n\n> See http://api.jquery.com/attr/ for more information\n\n#### .removeAttr( name )\nMethod for removing attributes by `name`.\n\n```js\n$('.pear').removeAttr('class').html()\n//=> <li>Pear</li>\n```\n\n#### .hasClass( className )\nCheck to see if *any* of the matched elements have the given `className`.\n\n```js\n$('.pear').hasClass('pear')\n//=> true\n\n$('apple').hasClass('fruit')\n//=> false\n\n$('li').hasClass('pear')\n//=> true\n```\n\n#### .addClass( className )\nAdds class(es) to all of the matched elements. Also accepts a `function` like jQuery.\n\n```js\n$('.pear').addClass('fruit').html()\n//=> <li class = \"pear fruit\">Pear</li>\n\n$('.apple').addClass('fruit red').html()\n//=> <li class = \"apple fruit red\">Apple</li>\n```\n\n> See http://api.jquery.com/addClass/ for more information.\n\n#### .removeClass( [className] )\nRemoves one or more space-separated classes from the selected elements. If no `className` is defined, all classes will be removed. Also accepts a `function` like jQuery.\n\n```js\n$('.pear').removeClass('pear').html()\n//=> <li class = \"\">Pear</li>\n\n$('.apple').addClass('red').removeClass().html()\n//=> <li class = \"\">Apple</li>\n```\n\n> See http://api.jquery.com/removeClass/ for more information.\n\n\n### Traversing\n\n#### .find(selector)\nGet a set of descendants filtered by `selector` of each element in the current set of matched elements.\n\n```js\n$('#fruits').find('li').length\n//=> 3\n```\n\n#### .parent()\nGets the parent of the first selected element.\n\n```js\n$('.pear').parent().attr('id')\n//=> fruits\n```\n\n#### .next()\nGets the next sibling of the first selected element.\n\n```js\n$('.apple').next().hasClass('orange')\n//=> true\n```\n\n#### .prev()\nGets the previous sibling of the first selected element.\n\n```js\n$('.orange').prev().hasClass('apple')\n//=> true\n```\n\n#### .slice( start, [end] )\nGets the elements matching the specified range\n\n```js\n$('li').slice(1).eq(0).text()\n//=> 'Orange'\n\n$('li').slice(1, 2).length\n//=> 1\n```\n\n#### .siblings()\nGets the first selected element's siblings, excluding itself.\n\n```js\n$('.pear').siblings().length\n//=> 2\n```\n\n#### .children( selector )\nGets the children of the first selected element.\n\n```js\n$('#fruits').children().length\n//=> 3\n\n$('#fruits').children('.pear').text()\n//=> Pear\n```\n\n#### .each( function(index, element) )\nIterates over a cheerio object, executing a function for each matched element. When the callback is fired, the function is fired in the context of the DOM element, so `this` refers to the current element, which is equivalent to the function parameter `element`. To break out of the `each` loop early, return with `false`.\n\n```js\nvar fruits = [];\n\n$('li').each(function(i, elem) {\n fruits[i] = $(this).text();\n});\n\nfruits.join(', ');\n//=> Apple, Orange, Pear\n```\n\n#### .map( function(index, element) )\nIterates over a cheerio object, executing a function for each selected element. Map will return an `array` of return values from each of the functions it iterated over. The function is fired in the context of the DOM element, so `this` refers to the current element, which is equivalent to the function parameter `element`.\n\n```js\n$('li').map(function(i, el) {\n // this === el\n return $(this).attr('class');\n}).join(', ');\n//=> apple, orange, pear\n```\n\n#### .filter( selector ) <br /> .filter( function(index) )\n\nIterates over a cheerio object, reducing the set of selector elements to those that match the selector or pass the function's test. If using the function method, the function is executed in the context of the selected element, so `this` refers to the current element.\n\nSelector:\n\n```js\n$('li').filter('.orange').attr('class');\n//=> orange\n```\n\nFunction:\n\n```js\n$('li').filter(function(i, el) {\n // this === el\n return $(this).attr('class') === 'orange';\n}).attr('class')\n//=> orange\n```\n\n#### .first()\nWill select the first element of a cheerio object\n\n```js\n$('#fruits').children().first().text()\n//=> Apple\n```\n\n#### .last()\nWill select the last element of a cheerio object\n\n```js\n$('#fruits').children().last().text()\n//=> Pear\n```\n\n#### .eq( i )\nReduce the set of matched elements to the one at the specified index. Use `.eq(-i)` to count backwards from the last selected element.\n\n```js\n$('li').eq(0).text()\n//=> Apple\n\n$('li').eq(-1).text()\n//=> Pear\n```\n\n### Manipulation\nMethods for modifying the DOM structure.\n\n#### .append( content, [content, ...] )\nInserts content as the *last* child of each of the selected elements.\n\n```js\n$('ul').append('<li class = \"plum\">Plum</li>')\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"pear\">Pear</li>\n// <li class = \"plum\">Plum</li>\n// </ul>\n```\n\n#### .prepend( content, [content, ...] )\nInserts content as the *first* child of each of the selected elements.\n\n```js\n$('ul').prepend('<li class = \"plum\">Plum</li>')\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"plum\">Plum</li>\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"pear\">Pear</li>\n// </ul>\n```\n\n#### .after( content, [content, ...] )\nInsert content next to each element in the set of matched elements.\n\n```js\n$('.apple').after('<li class = \"plum\">Plum</li>')\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"apple\">Apple</li>\n// <li class = \"plum\">Plum</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"pear\">Pear</li>\n// </ul>\n```\n\n#### .before( content, [content, ...] )\nInsert content previous to each element in the set of matched elements.\n\n```js\n$('.apple').before('<li class = \"plum\">Plum</li>')\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"plum\">Plum</li>\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"pear\">Pear</li>\n// </ul>\n```\n\n#### .remove( [selector] )\nRemoves the set of matched elements from the DOM and all their children. `selector` filters the set of matched elements to be removed.\n\n```js\n$('.pear').remove()\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// </ul>\n```\n\n#### .replaceWith( content )\nReplaces matched elements with `content`.\n\n```js\nvar plum = $('<li class = \"plum\">Plum</li>')\n$('.pear').replaceWith(plum)\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"plum\">Plum</li>\n// </ul>\n```\n\n#### .empty()\nEmpties an element, removing all it's children.\n\n```js\n$('ul').empty()\n$.html()\n//=> <ul id = \"fruits\"></ul>\n```\n\n#### .html( [htmlString] )\nGets an html content string from the first selected element. If `htmlString` is specified, each selected element's content is replaced by the new content.\n\n```js\n$('.orange').html()\n//=> Orange\n\n$('#fruits').html('<li class = \"mango\">Mango</li>').html()\n//=> <li class=\"mango\">Mango</li>\n```\n\n#### .text( [textString] )\nGet the combined text contents of each element in the set of matched elements, including their descendants.. If `textString` is specified, each selected element's content is replaced by the new text content.\n\n```js\n$('.orange').text()\n//=> Orange\n\n$('ul').text()\n//=> Apple\n// Orange\n// Pear\n```\n\n### Rendering\nWhen you're ready to render the document, you can use `html` utility function:\n\n```js\n$.html()\n//=> <ul id = \"fruits\">\n// <li class = \"apple\">Apple</li>\n// <li class = \"orange\">Orange</li>\n// <li class = \"pear\">Pear</li>\n// </ul>\n```\n\nIf you want to return the outerHTML you can use `$.html(selector)`:\n\n```js\n$.html('.pear')\n//=> <li class = \"pear\">Pear</li>\n```\n\n### Miscellaneous\nDOM element methods that don't fit anywhere else\n\n#### .toArray()\nRetrieve all the DOM elements contained in the jQuery set, as an array.\n\n```js\n$('li').toArray()\n//=> [ {...}, {...}, {...} ]\n```\n\n#### .clone() ####\nClone the cheerio object.\n\n```js\nvar moreFruit = $('#fruits').clone()\n```\n\n### Utilities\n\n#### $.root\n\nSometimes you need to work with the top-level root element. To query it, you can use `$.root()`.\n\n```js\n$.root().append('<ul id=\"vegetables\"></ul>').html();\n//=> <ul id=\"fruits\">...</ul><ul id=\"vegetables\"></ul>\n```\n\n#### $.contains( container, contained )\nChecks to see if the `contained` DOM element is a descendent of the `container` DOM element.\n\n## Screencasts\n\nhttp://vimeo.com/31950192\n\n> This video tutorial is a follow-up to Nettut's \"How to Scrape Web Pages with Node.js and jQuery\", using cheerio instead of JSDOM + jQuery. This video shows how easy it is to use cheerio and how much faster cheerio is than JSDOM + jQuery.\n\n## Test Coverage\n\nCheerio has high-test coverage, you can view the report [here](https://s3.amazonaws.com/MattMueller/Coverage/cheerio.html).\n\n## Testing\n\nTo run the test suite, download the repository, then within the cheerio directory, run:\n\n```shell\nmake setup\nmake test\n```\n\nThis will download the development packages and run the test suite.\n\n## Contributors\n\nThese are some of the contributors that have made cheerio possible:\n\n```\nproject : cheerio\nrepo age : 1 year, 4 months ago\ncommits : 416\nactive : 118 days\nfiles : 26\nauthors :\n 278 Matt Mueller 66.8%\n 68 Matthew Mueller 16.3%\n 27 David Chambers 6.5%\n 15 Siddharth Mahendraker 3.6%\n 7 ironchefpython 1.7%\n 5 Jos Shepherd 1.2%\n 5 Ben Sheldon 1.2%\n 2 alexbardas 0.5%\n 2 Rob Ashton 0.5%\n 1 mattym 0.2%\n 1 Chris O'Hara 0.2%\n 1 Mike Pennisi 0.2%\n 1 Rob \"Hurricane\" Ashton 0.2%\n 1 Sindre Sorhus 0.2%\n 1 Wayne Larsen 0.2%\n 1 Ben Atkin 0.2%\n```\n\n## Special Thanks\n\nThis library stands on the shoulders of some incredible developers. A special thanks to:\n\n__&#8226; @FB55 for node-htmlparser2 & CSSSelect:__\nFelix has a knack for writing speedy parsing engines. He completely re-wrote both @tautologistic's `node-htmlparser` and @harry's `node-soupselect` from the ground up, making both of them much faster and more flexible. Cheerio would not be possible without his foundational work\n\n__&#8226; @jQuery team for jQuery:__\nThe core API is the best of it's class and despite dealing with all the browser inconsistencies the code base is extremely clean and easy to follow. Much of cheerio's implementation and documentation is from jQuery. Thanks guys.\n\n__&#8226; @visionmedia:__\nThe style, the structure, the open-source\"-ness\" of this library comes from studying TJ's style and using many of his libraries. This dude consistently pumps out high-quality libraries and has always been more than willing to help or answer questions. You rock TJ.\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012 Matt Mueller &lt;mattmuelle@gmail.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"readmeFilename": "Readme.md",
"_id": "cheerio@0.10.8",
"dist": {
"shasum": "26a09542c471f91af93fc568079a95f9601d3545"
},
"_from": "cheerio@",
"_resolved": "https://registry.npmjs.org/cheerio/-/cheerio-0.10.8.tgz"
}