MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / safeInsertRule

Function safeInsertRule

code/styling/public/app.js:20212–20227  ·  view source on GitHub ↗
(sheet, cssRule, index)

Source from the content-addressed store, hash-verified

20210
20211/* insert a rule safely and return whether it was actually injected */
20212var safeInsertRule = function safeInsertRule(sheet, cssRule, index) {
20213 /* abort early if cssRule string is falsy */
20214 if (!cssRule) return false;
20215
20216 var maxIndex = sheet.cssRules.length;
20217
20218 try {
20219 /* use insertRule and cap passed index with maxIndex (no of cssRules) */
20220 sheet.insertRule(cssRule, index <= maxIndex ? index : maxIndex);
20221 } catch (err) {
20222 /* any error indicates an invalid rule */
20223 return false;
20224 }
20225
20226 return true;
20227};
20228
20229/* deletes `size` rules starting from `removalIndex` */
20230var deleteRules = function deleteRules(sheet, removalIndex, size) {

Callers 1

insertRulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected