utils.js 792 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. /**
  3. * Utils
  4. */
  5. var utils = module.exports;
  6. /**
  7. * Create regex for matching JavaScript linting config comments.
  8. *
  9. * @param {Array} `vendors`
  10. * @return {RegExp}
  11. */
  12. utils.toPrefixRegex = function(vendors) {
  13. var prefixes = '(' + vendors.join('|') + ')';
  14. return new RegExp('^' + prefixes);
  15. };
  16. /**
  17. * Trim trailing whitespace
  18. *
  19. * @param {String} `str`
  20. * @return {String}
  21. */
  22. utils.trimRight = function(str) {
  23. return str.replace(/\s+$/, '');
  24. };
  25. /**
  26. * Strip stars from the beginning of each comment line.
  27. *
  28. * @param {String} `str`
  29. * @return {String}
  30. */
  31. utils.stripStars = function(str) {
  32. str = str.replace(/^[ \t]/gm, '');
  33. str = str.replace(/^[ \t]*\*[ \t]?/gm, '');
  34. return utils.trimRight(str);
  35. };
  36. /**
  37. * Expose `utils`
  38. */
  39. module.exports = utils;