-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (48 loc) · 1.21 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
var Filter = require('broccoli-filter');
var colorguard = require('colorguard');
/**
* Initialize `ColorguardFilter` with options
*
* @param {Object} inputTree
* @param {Object} opts
* @api public
*/
function ColorguardFilter(inputTree, opts) {
if (!(this instanceof ColorguardFilter)) {
return new ColorguardFilter(inputTree, opts);
}
this.inputTree = inputTree;
this.opts = opts || {};
}
/**
* Create object
*/
ColorguardFilter.prototype = Object.create(Filter.prototype);
ColorguardFilter.prototype.constructor = ColorguardFilter;
/**
* Extensions
*/
ColorguardFilter.prototype.extensions = ['css'];
ColorguardFilter.prototype.targetExtension = 'css';
/**
* Process CSS
*
* @param {String} str
* @api public
*/
ColorguardFilter.prototype.processString = function (str) {
var output = colorguard.inspect(str, this.opts);
if (output && output.collisions && output.collisions.length) {
var errors = output.collisions.map(function(collision) {
return 'Collision: ' + collision.message;
});
throw new Error('\n' + errors.join('\n'));
}
// In case some one does chain
return str;
};
/**
* Module exports
*/
module.exports = ColorguardFilter;