4
0

isStandardSyntaxValue.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import hasInterpolation from './hasInterpolation.mjs';
  2. /**
  3. * Check whether a value is standard
  4. *
  5. * @param {string} value
  6. * @returns {boolean}
  7. */
  8. export default function isStandardSyntaxValue(value) {
  9. let normalizedValue = value;
  10. // Ignore operators before variables (example -$variable)
  11. if (/^[-+*/]/.test(value.charAt(0))) {
  12. normalizedValue = normalizedValue.slice(1);
  13. }
  14. // SCSS variable (example $variable)
  15. // styled component interpolation (example ${foo => foo.bar})
  16. if (normalizedValue.startsWith('$')) {
  17. return false;
  18. }
  19. // SCSS namespace (example namespace.$variable)
  20. if (/^.+\.\$/.test(value)) {
  21. return false;
  22. }
  23. // SCSS namespace (example namespace.function-name())
  24. if (/^.+\.[-\w]+\(/.test(value)) {
  25. return false;
  26. }
  27. // Less variable
  28. if (normalizedValue.startsWith('@')) {
  29. return false;
  30. }
  31. // SCSS or Less interpolation
  32. if (hasInterpolation(normalizedValue)) {
  33. return false;
  34. }
  35. // WebExtension replacement keyword used by Chrome/Firefox
  36. // more information: https://developer.chrome.com/extensions/i18n
  37. // and https://github.com/stylelint/stylelint/issues/4707
  38. if (/__MSG_\S+__/.test(value)) {
  39. return false;
  40. }
  41. return true;
  42. }