vendor.js 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. /**
  3. * Contains helpers for working with vendor prefixes.
  4. *
  5. * Copied from https://github.com/postcss/postcss/commit/777c55b5d2a10605313a4972888f4f32005f5ac2
  6. *
  7. * @namespace vendor
  8. */
  9. module.exports = {
  10. /**
  11. * Returns the vendor prefix extracted from an input string.
  12. *
  13. * @param {string} prop String with or without vendor prefix.
  14. *
  15. * @return {string} vendor prefix or empty string
  16. *
  17. * @example
  18. * vendor.prefix('-moz-tab-size') //=> '-moz-'
  19. * vendor.prefix('tab-size') //=> ''
  20. */
  21. prefix(prop) {
  22. const match = prop.match(/^(-\w+-)/);
  23. if (match) {
  24. return match[0];
  25. }
  26. return '';
  27. },
  28. /**
  29. * Returns the input string stripped of its vendor prefix.
  30. *
  31. * @param {string} prop String with or without vendor prefix.
  32. *
  33. * @return {string} String name without vendor prefixes.
  34. *
  35. * @example
  36. * vendor.unprefixed('-moz-tab-size') //=> 'tab-size'
  37. */
  38. unprefixed(prop) {
  39. return prop.replace(/^-\w+-/, '');
  40. },
  41. };