UNPKG

@redocly/theme

Version:

Shared UI components lib

23 lines (19 loc) 737 B
export function parseStyleString(styleString: string): React.CSSProperties { return styleString .split(';') .filter((style) => style.trim().length) .reduce((styleObj: React.CSSProperties, style) => { const colonIndex = style.indexOf(':'); if (colonIndex === -1) return styleObj; const key = style.substring(0, colonIndex).trim(); const value = style.substring(colonIndex + 1).trim(); if (key && value) { const camelCaseKey = key.replace(/-[a-z]/g, (match) => { return match[1].toUpperCase(); }); /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ (styleObj as any)[camelCaseKey] = value; } return styleObj; }, {}); }