wip(ssr): restructure

This commit is contained in:
Evan You
2020-01-27 17:23:42 -05:00
parent d293876c34
commit 012bc5df9d
11 changed files with 224 additions and 144 deletions

View File

@@ -6,6 +6,7 @@ export * from './globalsWhitelist'
export * from './codeframe'
export * from './domTagConfig'
export * from './mockWarn'
export * from './normalizeProp'
export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__
? Object.freeze({})

View File

@@ -0,0 +1,38 @@
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()
}