33module . exports = convert
44
55function convert ( test ) {
6- if ( typeof test === 'string' ) {
7- return typeFactory ( test )
6+ if ( test == null ) {
7+ return ok
88 }
99
10- if ( test === null || test === undefined ) {
11- return ok
10+ if ( typeof test === 'string' ) {
11+ return typeFactory ( test )
1212 }
1313
1414 if ( typeof test === 'object' ) {
15- return ( 'length' in test ? anyFactory : matchesFactory ) ( test )
15+ return 'length' in test ? anyFactory ( test ) : allFactory ( test )
1616 }
1717
1818 if ( typeof test === 'function' ) {
@@ -22,52 +22,40 @@ function convert(test) {
2222 throw new Error ( 'Expected function, string, or object as test' )
2323}
2424
25- function convertAll ( tests ) {
26- var results = [ ]
27- var length = tests . length
28- var index = - 1
29-
30- while ( ++ index < length ) {
31- results [ index ] = convert ( tests [ index ] )
32- }
33-
34- return results
35- }
36-
3725// Utility assert each property in `test` is represented in `node`, and each
3826// values are strictly equal.
39- function matchesFactory ( test ) {
40- return matches
27+ function allFactory ( test ) {
28+ return all
4129
42- function matches ( node ) {
30+ function all ( node ) {
4331 var key
4432
4533 for ( key in test ) {
46- if ( node [ key ] !== test [ key ] ) {
47- return false
48- }
34+ if ( node [ key ] !== test [ key ] ) return
4935 }
5036
5137 return true
5238 }
5339}
5440
5541function anyFactory ( tests ) {
56- var checks = convertAll ( tests )
57- var length = checks . length
42+ var checks = [ ]
43+ var index = - 1
44+
45+ while ( ++ index < tests . length ) {
46+ checks [ index ] = convert ( tests [ index ] )
47+ }
5848
59- return matches
49+ return any
6050
61- function matches ( ) {
51+ function any ( ) {
6252 var index = - 1
6353
64- while ( ++ index < length ) {
54+ while ( ++ index < checks . length ) {
6555 if ( checks [ index ] . apply ( this , arguments ) ) {
6656 return true
6757 }
6858 }
69-
70- return false
7159 }
7260}
7361
@@ -77,7 +65,7 @@ function typeFactory(test) {
7765 return type
7866
7967 function type ( node ) {
80- return Boolean ( node && node . type === test )
68+ return node && node . type === test
8169 }
8270}
8371
0 commit comments