optionsMatches.js 566 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const matchesStringOrRegExp = require('./matchesStringOrRegExp');
  3. /**
  4. * Check if an options object's propertyName contains a user-defined string or
  5. * regex that matches the passed in input.
  6. *
  7. * @param {{ [x: string]: any; }} options
  8. * @param {string} propertyName
  9. * @param {unknown} input
  10. *
  11. * @returns {boolean}
  12. */
  13. module.exports = function optionsMatches(options, propertyName, input) {
  14. return Boolean(
  15. options &&
  16. options[propertyName] &&
  17. typeof input === 'string' &&
  18. matchesStringOrRegExp(input, options[propertyName]),
  19. );
  20. };