index.js 770 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. /**
  3. * Checks if a given namespace is allowed by the given variable.
  4. *
  5. * @param {String} name namespace that should be included.
  6. * @param {String} variable Value that needs to be tested.
  7. * @returns {Boolean} Indication if namespace is enabled.
  8. * @public
  9. */
  10. module.exports = function enabled(name, variable) {
  11. if (!variable) return false;
  12. var variables = variable.split(/[\s,]+/)
  13. , i = 0;
  14. for (; i < variables.length; i++) {
  15. variable = variables[i].replace('*', '.*?');
  16. if ('-' === variable.charAt(0)) {
  17. if ((new RegExp('^'+ variable.substr(1) +'$')).test(name)) {
  18. return false;
  19. }
  20. continue;
  21. }
  22. if ((new RegExp('^'+ variable +'$')).test(name)) {
  23. return true;
  24. }
  25. }
  26. return false;
  27. };