vendor.js 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. let vendor = {
  9. /**
  10. * Returns the vendor prefix extracted from an input string.
  11. *
  12. * @param {string} prop String with or without vendor prefix.
  13. *
  14. * @return {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. let 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. * @return {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. };
  41. module.exports = vendor;