0.0.1 • Published 8 years ago
style-retriever v0.0.1
Parses html into AST then retrieves link and style tags, optionally retrieving remote css resources.
const StyleRetriever = require('style-retriever');
const retriever = new StyleRetriever('https://mysite.com');
retriever
.init('<!DOCTYPE html><head><link /></head>')
.then(parsed => retriever.getRemoteResources())
.then(resources => console.log(resources))
// => [ {url: 'https://cdn.com/bootstrap.css', body: 'html{color: blue;}'}, etc... ]
You can specify some options in the configuration hash to the constructor:
{string} href
- url of site to parse.{array} reducers
- array of reducer functions to apply to the html AST after it has been retrieved. Defaults to two basic reducers that look for<link />
and<style>
tags.{object} accumulator
- custom accumulator, only use this if you plan on adding custom reducers. Defaults to{ linkTags: [], styleTags: [] }
and isn't something you'd have to worry about in usage.