MCPcopy Create free account
hub / github.com/rollup/plugins / serializeObject

Function serializeObject

packages/pluginutils/src/dataToEsm.ts:24–38  ·  view source on GitHub ↗
(obj: object, indent: Indent, baseIndent: string)

Source from the content-addressed store, hash-verified

22}
23
24function serializeObject(obj: object, indent: Indent, baseIndent: string): string {
25 let output = '{';
26 const separator = indent ? `\n${baseIndent}${indent}` : '';
27 const entries = Object.entries(obj);
28 for (let i = 0; i < entries.length; i++) {
29 const [key, value] = entries[i];
30 const stringKey = makeLegalIdentifier(key) === key ? key : stringify(key);
31 output += `${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize(
32 value,
33 indent,
34 baseIndent + indent
35 )}`;
36 }
37 return `${output}${indent ? `\n${baseIndent}` : ''}}`;
38}
39
40function serialize(obj: unknown, indent: Indent, baseIndent: string): string {
41 if (typeof obj === 'object' && obj !== null) {

Callers 1

serializeFunction · 0.85

Calls 4

makeLegalIdentifierFunction · 0.85
stringifyFunction · 0.85
serializeFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected