MCPcopy
hub / github.com/markdoc/markdoc / formatValue

Function formatValue

src/formatter.ts:463–500  ·  view source on GitHub ↗
(
  v: Value | Value[],
  o: Options = {}
)

Source from the content-addressed store, hash-verified

461}
462
463function* formatValue(
464 v: Value | Value[],
465 o: Options = {}
466): Generator<string, void, unknown> {
467 switch (typeof v) {
468 case 'undefined':
469 break;
470 case 'boolean':
471 case 'number':
472 case 'string': {
473 yield v.toString();
474 break;
475 }
476 case 'object': {
477 if (v === null) break;
478 if (Array.isArray(v)) {
479 for (const n of v) yield* formatValue(n, o);
480 break;
481 }
482 switch (v.$$mdtype) {
483 case 'Function': {
484 yield* formatFunction(v as Function);
485 break;
486 }
487 case 'Node':
488 yield* formatNode(v as Node, o);
489 break;
490 case 'Variable': {
491 yield* formatVariable(v as Variable);
492 break;
493 }
494 default:
495 throw new Error(`Unimplemented: "${v.$$mdtype}"`);
496 }
497 break;
498 }
499 }
500}
501
502export default function format(v: Value | Value[], options?: Options): string {
503 let doc = '';

Callers 3

formatChildrenFunction · 0.85
formatNodeFunction · 0.85
formatFunction · 0.85

Calls 3

formatFunctionFunction · 0.85
formatNodeFunction · 0.85
formatVariableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…