4
0

isStandardSyntaxValue.cjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. const hasInterpolation = require('./hasInterpolation.cjs');
  5. /**
  6. * Check whether a value is standard
  7. *
  8. * @param {string} value
  9. * @returns {boolean}
  10. */
  11. function isStandardSyntaxValue(value) {
  12. let normalizedValue = value;
  13. // Ignore operators before variables (example -$variable)
  14. if (/^[-+*/]/.test(value.charAt(0))) {
  15. normalizedValue = normalizedValue.slice(1);
  16. }
  17. // SCSS variable (example $variable)
  18. // styled component interpolation (example ${foo => foo.bar})
  19. if (normalizedValue.startsWith('$')) {
  20. return false;
  21. }
  22. // SCSS namespace (example namespace.$variable)
  23. if (/^.+\.\$/.test(value)) {
  24. return false;
  25. }
  26. // SCSS namespace (example namespace.function-name())
  27. if (/^.+\.[-\w]+\(/.test(value)) {
  28. return false;
  29. }
  30. // Less variable
  31. if (normalizedValue.startsWith('@')) {
  32. return false;
  33. }
  34. // SCSS or Less interpolation
  35. if (hasInterpolation(normalizedValue)) {
  36. return false;
  37. }
  38. // WebExtension replacement keyword used by Chrome/Firefox
  39. // more information: https://developer.chrome.com/extensions/i18n
  40. // and https://github.com/stylelint/stylelint/issues/4707
  41. if (/__MSG_\S+__/.test(value)) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. module.exports = isStandardSyntaxValue;