1- const _ = require ( 'lodash ' ) ;
1+ const isString = require ( './isString ' ) ;
22
33module . 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) {
187187function 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+ }
0 commit comments