3 module.exports = convert
5 function convert(test) {
6 if (typeof test === 'string') {
7 return typeFactory(test)
10 if (test === null || test === undefined) {
14 if (typeof test === 'object') {
15 return ('length' in test ? anyFactory : matchesFactory)(test)
18 if (typeof test === 'function') {
22 throw new Error('Expected function, string, or object as test')
25 function convertAll(tests) {
27 var length = tests.length
30 while (++index < length) {
31 results[index] = convert(tests[index])
37 // Utility assert each property in `test` is represented in `node`, and each
38 // values are strictly equal.
39 function matchesFactory(test) {
42 function matches(node) {
46 if (node[key] !== test[key]) {
55 function anyFactory(tests) {
56 var checks = convertAll(tests)
57 var length = checks.length
64 while (++index < length) {
65 if (checks[index].apply(this, arguments)) {
74 // Utility to convert a string into a function which checks a given node’s type
76 function typeFactory(test) {
80 return Boolean(node && node.type === test)
84 // Utility to return true.