utils.ts
This file
Path
src/jsx/utils.ts
36 lines 路 1.1 KiB 路 TypeScript
Last changed by
chore: bump linter and formatter (#4568)ryubefore adoptionb6f4bcd
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637const normalizeElementKeyMap: Map<string, string> = new Map([ ['className', 'class'], ['htmlFor', 'for'], ['crossOrigin', 'crossorigin'], ['httpEquiv', 'http-equiv'], ['itemProp', 'itemprop'], ['fetchPriority', 'fetchpriority'], ['noModule', 'nomodule'], ['formAction', 'formaction'],])export const normalizeIntrinsicElementKey = (key: string): string => normalizeElementKeyMap.get(key) || key
export const styleObjectForEach = ( style: Record<string, string | number>, fn: (key: string, value: string | null) => void): void => { for (const [k, v] of Object.entries(style)) { const key = k[0] === '-' || !/[A-Z]/.test(k) ? k // a CSS variable or a lowercase only property : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`) // a camelCase property. convert to kebab-case fn( key, v == null ? null : typeof v === 'number' ? !key.match( /^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/ ) ? `${v}px` : `${v}` : v ) }}