This repository has been archived by the owner on Aug 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
70 lines (58 loc) · 1.97 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
64
65
66
67
68
69
70
let _ = require('lodash');
module.exports = function (options = {}) {
return function ({ addUtilities, e }) {
const defaultOptions = {
range: {
from: -1,
to: 5,
},
values: false,
variants: ['responsive'],
};
options = _.defaults(options, defaultOptions);
if (_.isEmpty(options.range) || ! _.isPlainObject(options.range)) {
options.range = false;
}
if (
_.isEmpty(options.values)
&& (
! _.isPlainObject(options.values)
|| ! _.isArray(options.values)
)
) {
options.values = false;
}
if (
_.has(options.range, 'from')
&& _.has(options.range, 'to')
&& options.range.from < options.range.to
) {
const range = _.map(_.range(options.range.from, ++options.range.to), value => {
return generateOutput(value);
});
addUtilities(range, options.variants);
}
if (_.isPlainObject(options.values)) {
const values = _.map(options.values, (value, key) => {
return generateOutput(value, key);
});
addUtilities(values, options.variants);
} else if (_.isArray(options.values)) {
const values = _.map(options.values, value => {
return generateOutput(value);
});
addUtilities(values, options.variants);
}
function generateOutput(value, key) {
value = _.toSafeInteger(value);
if (key === undefined) {
key = value;
return (value < 0)
? { [`.-order-${-key}`]: { order: value } }
: { [`.order-${key}`]: { order: value } };
} else {
return { [`.${e('order-'+key)}`]: { order: value } };
}
}
};
}