add method removeCSSRule with test
This commit is contained in:
parent
7e05271c51
commit
b128aad311
13
src/utils.js
13
src/utils.js
@ -180,6 +180,18 @@ function buildCSSRule(rule, styleMap, cssRulesString = '') {
|
|||||||
return `${cssRulesString}${getCSSRuleBlock(rule, styleMap)}`;
|
return `${cssRulesString}${getCSSRuleBlock(rule, styleMap)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeCSSRule(rule, cssRulesString = '') {
|
||||||
|
const rulePatternStr = `${escapeRegExp(rule)} {([^}]*)}`;
|
||||||
|
const rulePattern = new RegExp(rulePatternStr, 'g');
|
||||||
|
let output = cssRulesString;
|
||||||
|
|
||||||
|
if (cssRulesString && cssRulesString.match(rulePattern)) {
|
||||||
|
output = cssRulesString.replace(rulePattern, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.trim();
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getHeaderHTML,
|
getHeaderHTML,
|
||||||
getBodyHTML,
|
getBodyHTML,
|
||||||
@ -191,6 +203,7 @@ export default {
|
|||||||
namespaceSelector,
|
namespaceSelector,
|
||||||
getCSSString,
|
getCSSString,
|
||||||
buildCSSRule,
|
buildCSSRule,
|
||||||
|
removeCSSRule,
|
||||||
makeDataAttributeString,
|
makeDataAttributeString,
|
||||||
getDefault,
|
getDefault,
|
||||||
escapeRegExp
|
escapeRegExp
|
||||||
|
|||||||
@ -4,7 +4,8 @@ import chai from 'chai';
|
|||||||
import {
|
import {
|
||||||
makeDataAttributeString,
|
makeDataAttributeString,
|
||||||
getCSSString,
|
getCSSString,
|
||||||
buildCSSRule,
|
buildCSSRule,
|
||||||
|
removeCSSRule
|
||||||
} from '../src/utils.js';
|
} from '../src/utils.js';
|
||||||
|
|
||||||
chai.expect();
|
chai.expect();
|
||||||
@ -67,4 +68,14 @@ describe('#utils', () => {
|
|||||||
.to.be.equal('.test { width: 5px; height: 19px; margin-top: 3px; }.test2 { height: 45px; }');
|
.to.be.equal('.test { width: 5px; height: 19px; margin-top: 3px; }.test2 { height: 45px; }');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('removeCSSRule', () => {
|
||||||
|
it('should remove the css rule based on the selector', () => {
|
||||||
|
const rule = '.test';
|
||||||
|
const cssRuleString = `.test {margin-top: 2px;} .test2 {color: blue;}`;
|
||||||
|
|
||||||
|
expect(removeCSSRule(rule, cssRuleString))
|
||||||
|
.to.be.equal('.test2 {color: blue;}');
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user