MCPcopy Create free account
hub / github.com/denoland/std / #format

Method #format

toml/stringify.ts:226–265  ·  view source on GitHub ↗
(options: StringifyOptions = {})

Source from the content-addressed store, hash-verified

224 return `${this.#declaration(keys)}${this.#printDate(value)}`;
225 }
226 #format(options: StringifyOptions = {}): string[] {
227 const { keyAlignment = false } = options;
228 const rDeclaration = /^(\".*\"|[^=]*)\s=/;
229 const out = [];
230 for (let i = 0; i < this.output.length; i++) {
231 const l = this.output[i] as string;
232 // we keep empty entry for array of objects
233 if (l[0] === "[" && l[1] !== "[") {
234 // non-empty object with only subobjects as properties
235 if (
236 this.output[i + 1] === "" &&
237 this.output[i + 2]?.slice(0, l.length) === l.slice(0, -1) + "."
238 ) {
239 i += 1;
240 continue;
241 }
242 out.push(l);
243 } else {
244 if (keyAlignment) {
245 const m = rDeclaration.exec(l);
246 if (m && m[1]) {
247 out.push(l.replace(m[1], m[1].padEnd(this.maxPad)));
248 } else {
249 out.push(l);
250 }
251 } else {
252 out.push(l);
253 }
254 }
255 }
256 // Cleaning multiple spaces
257 const cleanedOutput = [];
258 for (let i = 0; i < out.length; i++) {
259 const l = out[i] as string;
260 if (!(l === "" && out[i + 1] === "")) {
261 cleanedOutput.push(l);
262 }
263 }
264 return cleanedOutput;
265 }
266}
267
268/**

Callers 1

dumpMethod · 0.95

Calls 2

sliceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected