MCPcopy Index your code
hub / github.com/resend/react-email / inlineCssToJs

Function inlineCssToJs

packages/editor/src/utils/styles.ts:52–90  ·  view source on GitHub ↗
(
  inlineStyle: string,
  options: { removeUnit?: boolean } = {},
)

Source from the content-addressed store, hash-verified

50};
51
52export const inlineCssToJs = (
53 inlineStyle: string,
54 options: { removeUnit?: boolean } = {},
55) => {
56 const styleObject: { [key: string]: string } = {};
57
58 if (!inlineStyle || inlineStyle === '' || typeof inlineStyle === 'object') {
59 return styleObject;
60 }
61
62 splitDeclarations(inlineStyle).forEach((style: string) => {
63 const trimmed = style.trim();
64 if (trimmed) {
65 const separatorIndex = trimmed.indexOf(':');
66 if (separatorIndex === -1) return;
67
68 const key = trimmed.slice(0, separatorIndex);
69 const value = trimmed.slice(separatorIndex + 1);
70 const valueTrimmed = value.trim();
71
72 if (!valueTrimmed) {
73 return;
74 }
75
76 const formattedKey = key
77 .trim()
78 .replace(/-\w/g, (match) => match[1].toUpperCase());
79
80 const UNIT_REGEX = /px|%/g;
81 const sanitizedValue = options?.removeUnit
82 ? valueTrimmed.replace(UNIT_REGEX, '')
83 : valueTrimmed;
84
85 styleObject[formattedKey] = sanitizedValue;
86 }
87 });
88
89 return styleObject;
90};
91
92/**
93 * Expands CSS shorthand properties (margin, padding) into their longhand equivalents.

Callers 15

styles.spec.tsFile · 0.90
parseContentFunction · 0.90
InspectorTextFunction · 0.90
InspectorNodeFunction · 0.90
updateParentBlockStyleFunction · 0.90
updateParentBlockPaddingFunction · 0.90
customUpdateStylesFunction · 0.90
getLinkColorFunction · 0.90
updateLinkColorFunction · 0.90
renderToReactEmailFunction · 0.90
bullet-list.tsxFile · 0.90
renderToReactEmailFunction · 0.90

Calls 2

splitDeclarationsFunction · 0.85
forEachMethod · 0.80

Tested by

no test coverage detected