@humanwhocodes/config-array
Advanced tools
Comparing version 0.1.0 to 0.2.0
30
api.js
@@ -72,3 +72,17 @@ 'use strict'; | ||
}, | ||
validate: assertIsArrayOfStrings | ||
validate(value) { | ||
// first check if it's an array | ||
assertIsArray(value); | ||
// then check each member | ||
value.forEach(item => { | ||
if (Array.isArray(item)) { | ||
assertIsArrayOfStrings(item); | ||
} else if (typeof item !== "string") { | ||
throw new TypeError("Items must be a string or an array of strings."); | ||
} | ||
}); | ||
} | ||
}, | ||
@@ -152,5 +166,17 @@ ignores: { | ||
// if files isn't an array, throw an error | ||
if (!Array.isArray(config.files) || config.files.length === 0) { | ||
throw new TypeError("The files key must be a non-empty array."); | ||
} | ||
// check for all matches to config.files | ||
let matches = config.files.some(pattern => { | ||
return minimatch(relativeFilePath, pattern, MINIMATCH_OPTIONS); | ||
if (typeof pattern === "string") { | ||
return minimatch(relativeFilePath, pattern, MINIMATCH_OPTIONS); | ||
} | ||
// otherwise it's an array where we need to AND the patterns | ||
return pattern.every(subpattern => { | ||
return minimatch(relativeFilePath, subpattern, MINIMATCH_OPTIONS); | ||
}); | ||
}); | ||
@@ -157,0 +183,0 @@ |
{ | ||
"name": "@humanwhocodes/config-array", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Glob-based configuration matching.", | ||
@@ -5,0 +5,0 @@ "author": "Nicholas C. Zakas", |
@@ -143,8 +143,16 @@ # Config Array | ||
} | ||
] | ||
], | ||
// filename must match all patterns in subarray | ||
{ | ||
files: [ ["*.test.*", "*.js"] ], | ||
handler: jsTestHandler | ||
} | ||
]; | ||
``` | ||
In this example, the array contains both a config object and a config array. When a config array is normalized (see details below), it is flattened so only config objects remain. However, the order of evaluation remains the same. | ||
In this example, the array contains both config objects and a config array. When a config array is normalized (see details below), it is flattened so only config objects remain. However, the order of evaluation remains the same. | ||
If the `files` array contains an item that is an array of strings, then all patterns must match in order for the config to match. In the preceding examples, both `*.test.*` and `*.js` must match in order for the config object to be used. | ||
### Config Functions | ||
@@ -151,0 +159,0 @@ |
33196
333
240