MCPcopy Index your code
hub / github.com/kyechan99/capsule-render / stringifyProperties

Function stringifyProperties

utils/css.ts:31–55  ·  view source on GitHub ↗
(
  properties: CSSProperties,
  indent: string = "  ",
)

Source from the content-addressed store, hash-verified

29};
30
31const stringifyProperties = (
32 properties: CSSProperties,
33 indent: string = " ",
34) => {
35 let css = "";
36
37 for (const [key, value] of Object.entries(properties)) {
38 const propertyName = kebabCase(key);
39
40 if (typeof value === "object") {
41 if (key.startsWith("@")) {
42 css += `${key} { ${stringifyProperties(value as CSSProperties, indent + " ")}${indent} } `;
43 } else if (key === "from" || key === "to" || /^\d+%$/.test(key)) {
44 css += `${indent}${key} { ${stringifyProperties(value as CSSProperties, indent + " ")}${indent}} `;
45 } else {
46 css += stringifyProperties(value as CSSProperties, indent);
47 }
48 } else {
49 const formattedValue = formatCSSValue(propertyName, value);
50 css += `${indent}${propertyName}: ${formattedValue}; `;
51 }
52 }
53
54 return css;
55};
56
57export const css = (selector: string, properties: CSSProperties) => {
58 return `${selector} { ${stringifyProperties(properties)} } `;

Callers 1

cssFunction · 0.85

Calls 2

kebabCaseFunction · 0.85
formatCSSValueFunction · 0.85

Tested by

no test coverage detected