Skip to content

Commit f327621

Browse files
author
Johnie Hjelm
committed
Added options
1 parent fea7d92 commit f327621

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

index.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
var postcss = require('postcss');
22

3-
module.exports = postcss.plugin('postcss-crip', function () {
3+
/**
4+
* Merge two objects into one object.
5+
*
6+
* @param {object} obj1
7+
* @param {object} obj2
8+
*
9+
* @return {object}
10+
*/
411

5-
var PROPS = {
12+
function merge(obj1, obj2) {
13+
for (var key in obj1) {
14+
if (obj2[key] === undefined) {
15+
obj2[key] = obj1[key];
16+
} else if (obj2[key] instanceof Array) {
17+
for (var child in obj1[key]) {
18+
if (obj2[key].indexOf(obj1[key][child]) !== -1) {
19+
obj2[key].push(obj1[key][child]);
20+
}
21+
}
22+
} else if (typeof obj2[key] === 'string') {
23+
obj2[key] = [obj2[key]];
24+
for (var kid in obj1[key]) {
25+
if (obj2[key].indexOf(obj1[key][kid]) !== -1) {
26+
obj2[key].push(obj1[key][kid]);
27+
}
28+
}
29+
}
30+
}
31+
32+
return obj2;
33+
}
34+
35+
module.exports = postcss.plugin('postcss-crip', function (options) {
36+
37+
options = options || {};
38+
39+
var DEFAULTS = {
640
'bg': ['background'],
741
'bgc': ['background-color'],
842
'bgz': ['background-size'],
@@ -48,6 +82,8 @@ module.exports = postcss.plugin('postcss-crip', function () {
4882
'zi': ['z-index']
4983
};
5084

85+
var PROPS = merge(DEFAULTS, options);
86+
5187
return function (css) {
5288

5389
css.eachRule(function (rule) {

0 commit comments

Comments
 (0)