validate-glob-opts
Validate node-glob options
validateGlobOpts({
sync: true,
mark: '/',
caches: {}
});
Installation
Use npm.
npm install validate-glob-opts
API
const validateGlobOpts = require('validate-glob-opts');
validateGlobOpts(obj [, customValidations])
obj: Object
(glob
options)
customValidations: Array<function>
Return: Array<Error>
It strictly validates glob
options, for example,
- It disallows the deprecated
sync
option to receive any values. - It disallows String options e.g.
cwd
to receive non-string values. - It disallows Boolean options e.g.
stat
to receive non-boolean values. - It disallows Object options e.g.
symlinks
to receive non-object values. - It invalidates probably typoed option names e.g.
symlink
.
Then, it returns the validation result as an array of error objects.
const validateGlobOpts = require('validate-glob-opts');
const ok = {
root: '/foo/bar/',
nodir: true,
ignore: ['path1', 'path2'],
symlinks: {}
};
validateGlobOpts(ok);
const notOk = {
root: Buffer.from('Hi'),
nodir: NaN,
ignore: ['path1', 1],
symlink: {}
};
const results = validateGlobOpts(notOk);
results.length;
results[0];
results[1];
results[2];
results[3];
User-defined validation
You can provide your own validations by passing an array of functions to the second parameter. Each function receives the object and should return an error when the object is not valid.
validateGlobOpts({realPath: true, nodir: true});
validateGlobOpts({realPath: true, nodir: true}, [
obj => obj.nodir ? new Error('My app doesn\'t support `nodir` option.') : null
]);
License
ISC License © 2018 Shinnosuke Watanabe