var $ = require('buck'); // who needs buck anyway?
var $ = require'buck';
Parse, Manipulate, Create new HTML content with your favorite jQuery-flavored API.
// load an external documentvar parse = $fetchDocument"";parsedone// this is tied to the newly parsed documentconsole.log"Successfully parsed document " + thistitle;// the new $ var is tied to the document contextvar articleTitle = $"article h1"text;// (...);
Use Deferred and promises to handle asynchronous results.
// load multiple documents$when;
At the time of working on a side project (Temples) i had the need of a powerfull DOM manipulation engine usable in node.JS to parse/query/transform data in HTML files. It didn't take very much time neither to understand that in fact, i needed jQuery for this job.
So i was first induced into using one of the few jQuery wrappers for node.JS.
However, it quickly occured to me that all of these wrappers do the job at a fairly high price. And its not a surprise, but here are the facts. Currently, all of the wrapper solutions to parse a document inside node.JS use jsdom as the pure JS DOM implementation and to recreate the window + document environment, and whe the document is parsed, they have to reload the full jQuery's sources inside this context. Because jQuery is a browser library, and is so tied to the 'window' environment, it has to be recreated for each document.
Buck is basically a wrapper around three awesome libraries with some additional sugar..
(The MIT License)
Copyright (c) 2012 Eidolon Labs. http://eidolon-labs.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.