MCPcopy Create free account
hub / github.com/babel/babel / stringTemplate

Function stringTemplate

packages/babel-template/src/string.ts:8–24  ·  view source on GitHub ↗
(
  formatter: Formatter<T>,
  code: string,
  opts: TemplateOpts,
)

Source from the content-addressed store, hash-verified

6import populatePlaceholders from "./populate.ts";
7
8export default function stringTemplate<T>(
9 formatter: Formatter<T>,
10 code: string,
11 opts: TemplateOpts,
12): (arg?: unknown) => T {
13 code = formatter.code(code);
14
15 let metadata: Metadata;
16
17 return (arg?: unknown) => {
18 const replacements = normalizeReplacements(arg);
19
20 if (!metadata) metadata = parseAndBuildMetadata(formatter, code, opts);
21
22 return formatter.unwrap(populatePlaceholders(metadata, replacements));
23 };
24}

Callers 1

createTemplateBuilderFunction · 0.85

Calls 3

normalizeReplacementsFunction · 0.90
parseAndBuildMetadataFunction · 0.85
populatePlaceholdersFunction · 0.85

Tested by

no test coverage detected