1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import type { Styles } from '../types/style'
- import PolishedError from '../internalHelpers/_errors'
- export default function important(styleBlock: Styles, rules?: Array<string> | string): Styles {
- if (typeof styleBlock !== 'object' || styleBlock === null) {
- throw new PolishedError(75, typeof styleBlock)
- }
- const newStyleBlock = {}
- Object.keys(styleBlock).forEach(key => {
- if (typeof styleBlock[key] === 'object' && styleBlock[key] !== null) {
- newStyleBlock[key] = important(styleBlock[key], rules)
- } else if (!rules || (rules && (rules === key || rules.indexOf(key) >= 0))) {
- newStyleBlock[key] = `${styleBlock[key]} !important`
- } else {
- newStyleBlock[key] = styleBlock[key]
- }
- })
- return newStyleBlock
- }
|