fela-plugin-important
Version:
Fela plugin that adds !important to every value
44 lines (35 loc) • 1.23 kB
JavaScript
import isPlainObject from 'isobject';
function addImportantToValue(value) {
if (typeof value === 'number' || typeof value === 'string' && value.toLowerCase().indexOf('!important') === -1) {
return "".concat(value, "!important");
}
return value;
}
function isAnimation(style) {
var styleNames = Object.getOwnPropertyNames(style);
var isAnimationItem = false;
for (var i = 0; i < styleNames.length; i++) {
var property = styleNames[i].toString();
isAnimationItem = property === 'to' || property.includes('from') || property.includes('animation') || property.includes('%');
}
return isAnimationItem;
}
function importantPlugin(style) {
if (!isAnimation(style)) {
for (var property in style) {
var value = style[property];
if (property === 'className') {// this is a fixed classname, not a style rule - leave as is
} else if (isPlainObject(value)) {
style[property] = importantPlugin(value);
} else if (Array.isArray(value)) {
style[property] = value.map(addImportantToValue);
} else {
style[property] = addImportantToValue(value);
}
}
}
return style;
}
export default function important() {
return importantPlugin;
}