A micro-library for collecting stylesheet data from link and style nodes
npm install get-css-data





A micro-library for collecting stylesheet data from link and style nodes.
- Collects CSS data from and nodes
- Collects static Node.textContent or live CSS Object Model (CSSOM) data
- Returns CSS data as a concatenated string and a DOM-ordered array of strings
- Allows document, iframe, and shadow DOM traversal
- Handles @import rules
- Handles absolute and relative URLs
- Inspect, modify and/or filter CSS data from each node
- Modify XHR object before each request
- UMD and ES6 modules available
- Compatible with modern and legacy browsers (IE9+)
- Lightweight (less than 1.5k min+gzip) and dependency-free
NPM:
``shell`
npm install get-css-data --save
`javascript
// file.js
import getCssData from 'get-css-data';
getCssData({
onComplete: function(cssText, cssArray, nodeArray) {
// Do stuff...
}
});
`
Git:
`bash`
git clone https://github.com/jhildenbiddle/get-css-data.git
CDN (jsdelivr.com shown, also on unpkg.com):
`html`
`html`
HTML:
`html`
CSS:
`css`
/ style1.css /
p { color: red; }
`css`
/ style2.css /
p { color: green; }
JavaScript (see Options for details)
`javascript
getCssData({
onComplete: function(cssText, cssArray, nodeArray) {
console.log(cssText); // 1
console.log(cssArray); // 2
console.log(nodeArray); // 3
}
});
// 1 => 'p { color: red; } p { color: green; } p { color: blue; }'
// 2 => ['p { color: red; }', 'p { color: green; } p { color: blue; }']
// 3 => [
`
- rootElement
- include
- exclude
- filter
- skipDisabled
- useCSSOM
- onBeforeSend
- onSuccess
- onError
- onComplete
Example
`javascript`
// Default values shown
getCssData({
rootElement : document,
include : 'link[rel=stylesheet],style',
exclude : '',
filter : '',
skipDisabled: true,
useCSSOM : false,
onBeforeSend: function(xhr, node, url) {
// ...
},
onSuccess: function(cssText, node, url) {
// ...
},
onError: function(xhr, node, url) {
// ...
},
onComplete: function(cssText, cssArray, nodeArray) {
// ...
}
});
- Type: objectdocument
- Default:
Root element to traverse for and