wip(ssr): restructure
This commit is contained in:
@@ -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({})
|
||||
|
||||
38
packages/shared/src/normalizeProp.ts
Normal file
38
packages/shared/src/normalizeProp.ts
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user