39 lines
904 B
TypeScript
39 lines
904 B
TypeScript
|
import { isArray, isString, isObject } from './'
|
||
|
|
||
|
export function normalizeStyle(
|
||
|
value: unknown
|
||
|
): Record<string, string | number> | void {
|
||
|
if (isArray(value)) {
|
||
|
const res: Record<string, string | number> = {}
|
||
|
for (let i = 0; i < value.length; i++) {
|
||
|
const normalized = normalizeStyle(value[i])
|
||
|
if (normalized) {
|
||
|
for (const key in normalized) {
|
||
|
res[key] = normalized[key]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return res
|
||
|
} else if (isObject(value)) {
|
||
|
return value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function normalizeClass(value: unknown): string {
|
||
|
let res = ''
|
||
|
if (isString(value)) {
|
||
|
res = value
|
||
|
} else if (isArray(value)) {
|
||
|
for (let i = 0; i < value.length; i++) {
|
||
|
res += normalizeClass(value[i]) + ' '
|
||
|
}
|
||
|
} else if (isObject(value)) {
|
||
|
for (const name in value) {
|
||
|
if (value[name]) {
|
||
|
res += name + ' '
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return res.trim()
|
||
|
}
|