Spatula
Spatula is a light weight and reliable binding of htmlparser2, css-select and dom-serializer.
It's inspired by Cheerio with a focus on dom traversal using css-select.
The biggest improvement is in the consistency - spatula is re-wrappable. All functions (expect html() and text()) return a spatula instance meaning that you can traverse the dom using a consistent programatic style.
installation
$ npm install good-spatula
usage
const expect = expect;const spatula = ; const markup = '<div data-name="bowser" class="surprise-father">' '<div data-name="mario" class="player player-one">Mario</div>' '<div data-name="luigi" class="player player-two">Luigi</div>' '</div>'; const parent = ;const selection = parent; selection; todeep; to;
Loading
Spatula can be loaded with markup, text, nothing, a dom element, an array of these things, or another spatula instance.
Spatula uses the lighting fast and forgiving htmlparser2.
You'll probably just want to parse some markup
;
but you can also pull in all kinds of other stuff
invalid elements (like undefined) will be gracefully trimmed out, while your other elements will be pulled into the result.
select
Spatula uses a passthrough to css-select which means that you get some awesome css selection. Make sure you checkout their documentation for the full list of supported selectors.
const node = ; // use the select method directlyconst title = nodetext;// or use it implicitlyconst content = ;// a select always returns a spatula instanceconst items = ;
forEach, map
Use spatula's forEach and map implementations to traverse a spatula instance. The item passed in is always an spatula instance of the child element.
const node = ; const values = ;// ['Item One', 'Item Two']
text, html, attr
Spatula allows you to pull values our a spatula instance.
const node = ; const item1 = text;// 'Item One'const item1Class = ;// 'item item-1'const item1Html = ;// '<div class="item item-1">Item One</div>