JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25149
  • Score
    100M100P100Q152487F
  • License MIT

Validate glob options

Package Exports

  • validate-glob-opts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (validate-glob-opts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

validate-glob-opts

NPM version Build Status Coverage Status

Validate node-glob options

validateGlobOpts({
  sync: true,
  mark: '/',
  caches: {}
});
/* => [
  TypeError: `sync` option is deprecated and there is no need to pass any values to the option, but true is provided.,
  TypeError: node-glob expected `mark` option to be a Boolean value, but got '/'.,
  Error: node-glob doesn't have `caches` option. Probably you meant `cache`.
] */

Installation

Use npm.

npm install validate-glob-opts

API

const validateGlobOpts = require('validate-glob-opts');

validateGlobOpts(obj)

obj: Object (glob options)
Return: Array of errors

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(ok);
results.length; //=> 4
results[0];
//=>  TypeError: node-glob expected `root` option to be a directory path (string), but got <Buffer 48 69>.
results[1];
//=> TypeError: node-glob expected `nodir` option to be a Boolean value, but got NaN.
results[2];
//=> TypeError: Expected every value in the `ignore` option to be a string, but the array includes a non-string value 1.
results[3];
//=> Error: node-glob doesn't have `symlink` option. Probably you meant `symlinks`.

License

Copyright (c) 2017 Shinnosuke Watanabe

Licensed under the MIT License.