rules-overlap.js 596 B

1234567891011121314151617181920212223242526272829303132
  1. var MODIFIER_PATTERN = /\-\-.+$/;
  2. function rulesOverlap(rule1, rule2, bemMode) {
  3. var scope1;
  4. var scope2;
  5. var i, l;
  6. var j, m;
  7. for (i = 0, l = rule1.length; i < l; i++) {
  8. scope1 = rule1[i][1];
  9. for (j = 0, m = rule2.length; j < m; j++) {
  10. scope2 = rule2[j][1];
  11. if (scope1 == scope2) {
  12. return true;
  13. }
  14. if (bemMode && withoutModifiers(scope1) == withoutModifiers(scope2)) {
  15. return true;
  16. }
  17. }
  18. }
  19. return false;
  20. }
  21. function withoutModifiers(scope) {
  22. return scope.replace(MODIFIER_PATTERN, '');
  23. }
  24. module.exports = rulesOverlap;