vendor.mjs 964 B

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