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
The walk stopped after 200 commits: lines older than 82bdc4d point at it.
4.9.0Yusuke Wadabefore adoption82bdc4d
lines 1–27why, one step back1const normalizeElementKeyMap: Map<string, string> = new Map([2 ['className', 'class'],3 ['htmlFor', 'for'],4 ['crossOrigin', 'crossorigin'],5 ['httpEquiv', 'http-equiv'],6 ['itemProp', 'itemprop'],7 ['fetchPriority', 'fetchpriority'],8 ['noModule', 'nomodule'],9 ['formAction', 'formaction'],10])11export const normalizeIntrinsicElementKey = (key: string): string =>12 normalizeElementKeyMap.get(key) || key1314export const styleObjectForEach = (15 style: Record<string, string | number>,16 fn: (key: string, value: string | null) => void17): void => {18 for (const [k, v] of Object.entries(style)) {19 const key =20 k[0] === '-' || !/[A-Z]/.test(k)21 ? k // a CSS variable or a lowercase only property22 : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`) // a camelCase property. convert to kebab-case23 fn(24 key,25 v == null26 ? null27 : typeof v === 'number'chore: bump linter and formatter (#4568)ryubefore adoptionb6f4bcd
lines 28–33why, one step back28 ? !key.match(29 /^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/30 )31 ? `${v}px`32 : `${v}`33 : v4.9.0Yusuke Wadabefore adoption82bdc4d
lines 34–36why, one step back34 )35 }36}