forked from hudochenkov/postcss-sorting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (35 loc) · 1.02 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
'use strict';
const postcss = require('postcss');
const _ = require('lodash');
const order = require('./lib/order');
const propertiesOrder = require('./lib/properties-order');
const validateOptions = require('./lib/validateOptions');
module.exports = postcss.plugin('postcss-sorting', function(opts) {
return function(css) {
plugin(css, opts);
};
});
function plugin(css, opts) {
const validatedOptions = validateOptions(opts);
if (validatedOptions !== true) {
const throwValidateErrors = _.get(opts, 'throw-validate-errors', false);
if (throwValidateErrors) {
if (_.isString(validatedOptions)) {
throw new Error(validatedOptions);
}
throw new Error(`postcss-sorting: Invalid config.`);
} else {
// eslint-disable-next-line no-console
if (console && console.warn && _.isString(validatedOptions)) {
console.warn(validatedOptions); // eslint-disable-line no-console
}
return;
}
}
if (opts.order) {
order(css, opts);
}
if (opts['properties-order']) {
propertiesOrder(css, opts);
}
}