diff --git a/README.md b/README.md index babb04b..dee38c1 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,10 @@ npm install assert-valid-glob-opts const assertValidGlobOpts = require('assert-valid-glob-opts'); ``` -### assertValidGlobOpts(*obj*) +### assertValidGlobOpts(*obj* [, *customValidations*]) *obj*: `Object` ([`glob` options](https://github.com/isaacs/node-glob#options)) +*customValidations*: `Array` (passed to [`validate-glob-opts`](https://github.com/shinnn/validate-glob-opts#validategloboptsobj--customvalidations)) It validates a given object with [validate-glob-opts](https://github.com/shinnn/validate-glob-opts) and throws an error if the value is not valid. diff --git a/index.js b/index.js index 9e021b0..ec15c4c 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,8 @@ const GlobOptionError = require('glob-option-error'); const validateGlobOpts = require('validate-glob-opts'); -module.exports = function assertValidGlobOpts(obj) { - const results = validateGlobOpts(obj); +module.exports = function assertValidGlobOpts(...args) { + const results = validateGlobOpts(...args); if (results.length === 0) { return; diff --git a/package.json b/package.json index aa0dc2e..ff8c812 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "strict" ], "dependencies": { - "glob-option-error": "^0.1.0", - "validate-glob-opts": "^0.4.0" + "glob-option-error": "^1.0.0", + "validate-glob-opts": "^1.0.0" }, "devDependencies": { "@shinnn/eslint-config-node": "^3.0.0", diff --git a/test.js b/test.js index 354b68a..69c40e9 100644 --- a/test.js +++ b/test.js @@ -9,6 +9,12 @@ test('assertValidGlobOpts()', t => { 'should throw no errors when it takes no arguments.' ); + t.throws( + () => main({}, [], null), + /^TypeError.*Expected 0, 1 or 2 arguments \(\[, ]\), but got 3\./, + 'should throw no errors when it takes too many arguments.' + ); + t.doesNotThrow( () => main({nodir: true}), 'should throw no errors when it takes a valid glob option.' @@ -16,7 +22,7 @@ test('assertValidGlobOpts()', t => { t.throws( () => main({cwd: 1}), - /^TypeError: node-glob expected `cwd` option to be a directory path \(string\), but got 1\./, + /^TypeError.*node-glob expected `cwd` option to be a directory path \(string\), but got 1 \(number\)\./, 'should throw an error when it takes an invalid glob option.' ); @@ -32,5 +38,17 @@ test('assertValidGlobOpts()', t => { 'should throw a type error when every error in the result is type error.' ); + t.throws( + () => main({x: '!!!err!!!'}, [({x}) => new Error(x)]), + /^Error.*!!!err!!!/, + 'should support custom validation parameter.' + ); + + t.throws( + () => main({}, new WeakMap()), + /^TypeError.*Expected an array of functions, but got a non-array value WeakMap {}\./, + 'should invalidate the non-array second aergument.' + ); + t.end(); });