-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (28 loc) · 830 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*jshint node: true, strict: false*/
var css = require('css');
var RULE = 'rule';
module.exports = function(source) {
if (this.cacheable) {
this.cacheable();
}
var stylesheet = css.parse(source).stylesheet;
if (stylesheet.parsingErrors.length) {
throw new Error('Parsing Error occured.');
}
var rules = {},
inline;
stylesheet.rules.forEach(function(rule) {
inline = '';
if (rule.type === RULE) {
inline = rule.declarations.map(function(declaration) {
return declaration.property + ': ' + declaration.value;
}).join('; ');
}
if(rule.selectors) {
rule.selectors.forEach(function(selector) {
rules[selector] = inline;
});
}
});
return rules;
};