evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a pattern validation utility that converts glob patterns into regular expressions and validates file paths against them.
Create a module that provides functionality to:
The module should expose a function that takes a glob pattern (or array of patterns) and returns a validator object with a test method that checks if a given path matches the pattern.
// Example: Pattern "*.js" should match "file.js" but not "file.ts"
const validator = createValidator('*.js');
validator.test('file.js') === true;
validator.test('file.ts') === false;// Example: Pattern "**/*.js" should match files in any nested directory
const validator = createValidator('**/*.js');
validator.test('src/utils/helper.js') === true;
validator.test('lib/index.js') === true;
validator.test('readme.md') === false;// Example: With nocase option, "*.JS" should match "file.js"
const validator = createValidator('*.JS', { nocase: true });
validator.test('file.js') === true;
validator.test('file.JS') === true;/**
* Creates a validator from one or more glob patterns
* @param {string|string[]} patterns - Glob pattern(s) to compile
* @param {object} options - Configuration options (e.g., { nocase: true })
* @returns {object} Validator object with test method
*/
function createValidator(patterns, options) {
// Returns { test: (path) => boolean }
}
module.exports = { createValidator };Provides glob pattern compilation and matching support.