MCPcopy Create free account
hub / github.com/composify-js/composify / stringifyValue

Function stringifyValue

packages/react/src/renderer/Parser/Parser.ts:187–214  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

185};
186
187const stringifyValue = (value: unknown): string => {
188 if (isNode(value)) {
189 return stringify(value);
190 }
191
192 if (Array.isArray(value)) {
193 return `[${value.map(stringifyValue).join(', ')}]`;
194 }
195
196 if (value === null) {
197 return 'null';
198 }
199
200 switch (typeof value) {
201 case 'string':
202 return `"${value}"`;
203 case 'number':
204 return String(value);
205 case 'boolean':
206 return value ? 'true' : 'false';
207 case 'object':
208 return `{${Object.entries(value)
209 .map(([key, val]) => `${key}: ${stringifyValue(val)}`)
210 .join(', ')}}`;
211 default:
212 return '';
213 }
214};
215
216const isNode = (value: unknown): value is Node => {
217 return !!value && typeof value === 'object' && '__composify__' in value;

Callers 1

stringifyAttributesFunction · 0.85

Calls 2

isNodeFunction · 0.85
stringifyFunction · 0.85

Tested by

no test coverage detected