Skip to content

Commit ac15723

Browse files
committed
Remove lodash from dependencies
1 parent 2979f82 commit ac15723

8 files changed

Lines changed: 53 additions & 56 deletions

File tree

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const _ = require('lodash');
2-
31
const order = require('./lib/order');
42
const propertiesOrder = require('./lib/properties-order');
53
const validateOptions = require('./lib/validateOptions');
4+
const isString = require('./lib/isString');
65

76
module.exports = (opts) => {
87
return {
@@ -19,17 +18,17 @@ function plugin(css, opts) {
1918
const validatedOptions = validateOptions(opts);
2019

2120
if (validatedOptions !== true) {
22-
const throwValidateErrors = _.get(opts, 'throw-validate-errors', false);
21+
const throwValidateErrors = (opts && opts['throw-validate-errors']) || false;
2322

2423
if (throwValidateErrors) {
25-
if (_.isString(validatedOptions)) {
24+
if (isString(validatedOptions)) {
2625
throw new Error(validatedOptions);
2726
}
2827

2928
throw new Error(`postcss-sorting: Invalid config.`);
3029
} else {
3130
// eslint-disable-next-line no-console
32-
if (console && console.warn && _.isString(validatedOptions)) {
31+
if (console && console.warn && isString(validatedOptions)) {
3332
console.warn(validatedOptions); // eslint-disable-line no-console
3433
}
3534

lib/checkOption.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/createExpectedOrder.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const _ = require('lodash');
1+
const isString = require('./isString');
22

33
module.exports = function createExpectedOrder(input) {
44
const order = {};
@@ -9,7 +9,7 @@ module.exports = function createExpectedOrder(input) {
99

1010
position += 1;
1111

12-
if (_.isString(item) && item !== 'at-rules' && item !== 'rules') {
12+
if (isString(item) && item !== 'at-rules' && item !== 'rules') {
1313
order[item] = {
1414
position,
1515
};
@@ -35,7 +35,7 @@ module.exports = function createExpectedOrder(input) {
3535
if (item.selector) {
3636
nodeData.selector = item.selector;
3737

38-
if (_.isString(item.selector)) {
38+
if (isString(item.selector)) {
3939
nodeData.selector = new RegExp(item.selector);
4040
}
4141
}
@@ -67,12 +67,12 @@ module.exports = function createExpectedOrder(input) {
6767
if (item.parameter) {
6868
nodeData.parameter = item.parameter;
6969

70-
if (_.isString(item.parameter)) {
70+
if (isString(item.parameter)) {
7171
nodeData.parameter = new RegExp(item.parameter);
7272
}
7373
}
7474

75-
if (!_.isUndefined(item.hasBlock)) {
75+
if (item.hasBlock !== undefined) {
7676
nodeData.hasBlock = item.hasBlock;
7777
}
7878

lib/isString.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function isString(str) {
2+
return str && typeof str.valueOf() === 'string';
3+
};

lib/sorting.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const _ = require('lodash');
21
const shorthandData = require('./shorthandData');
32
const vendor = require('./vendor');
43

@@ -21,7 +20,7 @@ function sortDeclarations(a, b) {
2120
}
2221
}
2322

24-
if (!_.isUndefined(a.orderData) && !_.isUndefined(b.orderData)) {
23+
if (a.orderData && b.orderData !== undefined) {
2524
// If a and b have the same group index, and a's property index is
2625
// higher than b's property index, in a sorted list a appears after
2726
// b:
@@ -35,27 +34,27 @@ function sortDeclarations(a, b) {
3534
a.unspecifiedPropertiesPosition === 'bottomAlphabetical' ||
3635
b.unspecifiedPropertiesPosition === 'bottomAlphabetical'
3736
) {
38-
if (!_.isUndefined(a.orderData) && _.isUndefined(b.orderData)) {
37+
if (a.orderData !== undefined && b.orderData === undefined) {
3938
return -1;
4039
}
4140

42-
if (_.isUndefined(a.orderData) && !_.isUndefined(b.orderData)) {
41+
if (a.orderData === undefined && b.orderData !== undefined) {
4342
return 1;
4443
}
4544
}
4645

4746
if (a.unspecifiedPropertiesPosition === 'top') {
48-
if (!_.isUndefined(a.orderData) && _.isUndefined(b.orderData)) {
47+
if (a.orderData !== undefined && b.orderData === undefined) {
4948
return 1;
5049
}
5150

52-
if (_.isUndefined(a.orderData) && !_.isUndefined(b.orderData)) {
51+
if (a.orderData === undefined && b.orderData !== undefined) {
5352
return -1;
5453
}
5554
}
5655

5756
if (a.unspecifiedPropertiesPosition === 'bottomAlphabetical') {
58-
if (_.isUndefined(a.orderData) && _.isUndefined(b.orderData)) {
57+
if (a.orderData === undefined && b.orderData === undefined) {
5958
return sortDeclarationsAlphabetically(a, b);
6059
}
6160
}

lib/validateOptions.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const _ = require('lodash');
1+
const isString = require('./isString');
22

33
module.exports = function validateOptions(options) {
4-
if (_.isUndefined(options) || _.isNull(options)) {
4+
if (options === undefined || options === null) {
55
return false;
66
}
77

8-
if (!_.isPlainObject(options)) {
8+
if (!isObject(options)) {
99
return reportError('Options should be an object.');
1010
}
1111

12-
if (!_.isUndefined(options.order) && !_.isNull(options.order)) {
12+
if (options.order !== undefined && options.order !== null) {
1313
const validatedOrder = validateOrder(options.order);
1414
const { isValid, message } = validatedOrder;
1515

@@ -18,7 +18,7 @@ module.exports = function validateOptions(options) {
1818
}
1919
}
2020

21-
if (!_.isUndefined(options['properties-order']) && !_.isNull(options['properties-order'])) {
21+
if (options['properties-order'] !== undefined && options['properties-order'] !== null) {
2222
const validatedPropertiesOrder = validatePropertiesOrder(options['properties-order']);
2323
const { isValid, message } = validatedPropertiesOrder;
2424

@@ -28,8 +28,8 @@ module.exports = function validateOptions(options) {
2828
}
2929

3030
if (
31-
!_.isUndefined(options['unspecified-properties-position']) &&
32-
!_.isNull(options['unspecified-properties-position'])
31+
options['unspecified-properties-position'] !== undefined &&
32+
options['unspecified-properties-position'] !== null
3333
) {
3434
const validatedUnspecifiedPropertiesPosition = validateUnspecifiedPropertiesPosition(
3535
options['unspecified-properties-position']
@@ -78,11 +78,11 @@ function validateOrder(options) {
7878
// with a "type" property
7979
if (
8080
!options.every((item) => {
81-
if (_.isString(item)) {
82-
return _.includes(keywords, item);
81+
if (isString(item)) {
82+
return keywords.includes(item);
8383
}
8484

85-
return _.isPlainObject(item) && !_.isUndefined(item.type);
85+
return isObject(item) && item.type !== undefined;
8686
})
8787
) {
8888
return {
@@ -93,7 +93,7 @@ function validateOrder(options) {
9393
};
9494
}
9595

96-
const objectItems = options.filter(_.isPlainObject);
96+
const objectItems = options.filter(isObject);
9797
let wrongObjectItem;
9898

9999
if (
@@ -108,32 +108,32 @@ function validateOrder(options) {
108108

109109
if (item.type === 'at-rule') {
110110
// if parameter is specified, name should be specified also
111-
if (!_.isUndefined(item.parameter) && _.isUndefined(item.name)) {
111+
if (item.parameter !== undefined && item.name === undefined) {
112112
wrongObjectItem = `"at-rule" with "parameter" should also has a "name"`;
113113

114114
return false;
115115
}
116116

117-
if (!_.isUndefined(item.hasBlock)) {
117+
if (item.hasBlock !== undefined) {
118118
result = item.hasBlock === true || item.hasBlock === false;
119119
}
120120

121-
if (!_.isUndefined(item.name)) {
122-
result = _.isString(item.name) && item.name.length;
121+
if (item.name !== undefined) {
122+
result = isString(item.name) && item.name.length;
123123
}
124124

125-
if (!_.isUndefined(item.parameter)) {
125+
if (item.parameter !== undefined) {
126126
result =
127-
(_.isString(item.parameter) && item.parameter.length) ||
128-
_.isRegExp(item.parameter);
127+
(isString(item.parameter) && item.parameter.length) ||
128+
isRegExp(item.parameter);
129129
}
130130
}
131131

132132
if (item.type === 'rule') {
133-
if (!_.isUndefined(item.selector)) {
133+
if (item.selector !== undefined) {
134134
result =
135-
(_.isString(item.selector) && item.selector.length) ||
136-
_.isRegExp(item.selector);
135+
(isString(item.selector) && item.selector.length) ||
136+
isRegExp(item.selector);
137137
}
138138
}
139139

@@ -172,7 +172,7 @@ function validatePropertiesOrder(options) {
172172
}
173173

174174
// Every item in the array must be a string
175-
if (!options.every((item) => _.isString(item))) {
175+
if (!options.every((item) => isString(item))) {
176176
return {
177177
isValid: false,
178178
message: 'Array should contain strings only',
@@ -187,7 +187,7 @@ function validatePropertiesOrder(options) {
187187
function validateUnspecifiedPropertiesPosition(options) {
188188
const keywords = ['top', 'bottom', 'bottomAlphabetical'];
189189

190-
if (_.isString(options) && _.includes(keywords, options)) {
190+
if (isString(options) && keywords.includes(options)) {
191191
return {
192192
isValid: true,
193193
};
@@ -198,3 +198,11 @@ function validateUnspecifiedPropertiesPosition(options) {
198198
message: `Option should be one of the following values: ${keywordsList(keywords)}.`,
199199
};
200200
}
201+
202+
function isRegExp(value) {
203+
return Object.prototype.toString.call(value) === '[object RegExp]';
204+
}
205+
206+
function isObject(value) {
207+
return typeof value === 'object' && value !== null;
208+
}

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
"index.js",
2323
"!.DS_Store"
2424
],
25-
"dependencies": {
26-
"lodash": "^4.17.21"
27-
},
2825
"peerDependencies": {
2926
"postcss": "^8.0.4"
3027
},

0 commit comments

Comments
 (0)