| 21 | * React.HTMLAttributes<HTMLElement> 转换为 attributes 字符串 |
| 22 | */ |
| 23 | export const htmlAttributesToString = (attributes: Record<string, any>): string => { |
| 24 | return Object.keys(attributes).reduce((accumulator, key) => { |
| 25 | // transform the key from camelCase to kebab-case |
| 26 | const attrKey = kebabCase(key) |
| 27 | // remove ' in value |
| 28 | const attrValue = String(attributes[key]).replace("'", '') |
| 29 | // build the result |
| 30 | // you can break the line, add indent for it if you need |
| 31 | return `${accumulator}${attrKey}="${attrValue}" ` |
| 32 | }, '') |
| 33 | } |