MCPcopy Create free account
hub / github.com/denoland/std / stringify

Function stringify

ini/stringify.ts:107–135  ·  view source on GitHub ↗
(
  object: object,
  options: StringifyOptions = {},
)

Source from the content-addressed store, hash-verified

105 * @returns The INI string
106 */
107export function stringify(
108 object: object,
109 options: StringifyOptions = {},
110): string {
111 const {
112 replacer = defaultReplacer,
113 pretty = false,
114 lineBreak = "\n",
115 } = options;
116 const assignment = pretty ? " = " : "=";
117
118 const entries = Object.entries(object).sort(sort);
119
120 const lines = [];
121 for (const [key, value] of entries) {
122 if (isPlainObject(value)) {
123 const sectionName = key;
124 lines.push(`[${sectionName}]`);
125 for (const [key, val] of Object.entries(value)) {
126 const line = `${key}${assignment}${replacer(key, val, sectionName)}`;
127 lines.push(line);
128 }
129 } else {
130 const line = `${key}${assignment}${replacer(key, value)}`;
131 lines.push(line);
132 }
133 }
134 return lines.join(lineBreak);
135}

Callers 1

fnFunction · 0.90

Calls 3

isPlainObjectFunction · 0.70
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected