css-revealer
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -5,29 +5,17 @@ 'use strict'; | ||
var css = require('css'); | ||
var split = require('./util').split; | ||
var head = require('./util').head; | ||
var test = require('./util').test; | ||
var concat = require('./util').concat; | ||
var prop = require('./util').prop; | ||
var propEq = require('./util').propEq; | ||
var match = require('./util').match; | ||
module.exports = function parse(stylesheet) { | ||
var ast = css.parse(stylesheet); | ||
var astRules = ast.stylesheet.rules; | ||
return _.chain(astRules) | ||
return _.chain(css.parse(stylesheet)) | ||
.at('stylesheet') | ||
.map(prop('rules')) | ||
.flatten() | ||
.filter(propEq('type', 'rule')) | ||
.map(prop('selectors')) | ||
.reduce(concat, []) | ||
.map(split(' ')) | ||
.reduce(function(memo, array){ | ||
return memo.concat( | ||
array | ||
.filter(test(/^[#.]/)) | ||
.map(_.compose(head, split(':'))) | ||
.map(split(/([.#][^.#]+)/g)) | ||
.reduce(concat, []) | ||
.filter(test(/[^\s]/)) | ||
); | ||
}, []) | ||
.flatten() | ||
.map(match(/([.#][^.#: ]+)/g)) | ||
.flatten() | ||
.uniq() | ||
@@ -34,0 +22,0 @@ .value(); |
@@ -6,16 +6,4 @@ 'use strict'; | ||
exports.readFile = _.partial(fs.readFile, _, { encoding: 'utf-8' }); | ||
exports.readFile = _.curry(fs.readFile, _, { encoding: 'utf-8' }); | ||
exports.split = _.curry(function(pattern, string){ | ||
return string.split(pattern); | ||
}); | ||
exports.head = _.curry(function(list){ | ||
return list[0]; | ||
}); | ||
exports.test = _.curry(function(pattern, string){ | ||
return pattern.test(string); | ||
}); | ||
exports.concat = _.curry(function(listA, listB){ | ||
@@ -36,1 +24,5 @@ return listA.concat(listB); | ||
}); | ||
exports.match = _.curry(function(pattern, string){ | ||
return string.match(pattern); | ||
}); |
{ | ||
"name": "css-revealer", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Reveal CSS selector usage within HTML templates.", | ||
@@ -5,0 +5,0 @@ "bin": { |
21960
561