MCPcopy Create free account
hub / github.com/chhoumann/quickadd / formatFileName

Method formatFileName

src/formatters/completeFormatter.ts:101–130  ·  view source on GitHub ↗
(input: string, valueHeader: string)

Source from the content-addressed store, hash-verified

99 }
100
101 async formatFileName(input: string, valueHeader: string): Promise<string> {
102 // Check for {{title}} usage in filename which would cause infinite recursion
103 if (/\{\{title\}\}/i.test(input)) {
104 throw new Error(
105 "{{title}} cannot be used in file names as it would create a circular dependency. The title is derived from the filename itself.",
106 );
107 }
108
109 this.valueHeader = valueHeader;
110 let output = await this.format(input);
111 // A {{title}} produced AFTER the raw-input check — by an expanded global
112 // snippet ({{GLOBAL_VAR:x}} -> {{title}}) or a {{VALUE}} that resolved to
113 // the literal text "{{title}}" — would otherwise survive into the file name
114 // (the token pass below omits `title`, leaving it verbatim). Re-check post
115 // format() so it throws the same circular-dependency error, mirroring
116 // formatTemplateFilePath's post-global-expansion guard.
117 if (/\{\{title\}\}/i.test(output)) {
118 throw new Error(
119 "{{title}} cannot be used in file names as it would create a circular dependency. The title is derived from the filename itself.",
120 );
121 }
122 // {{filenamecurrent}} + {{folder}} in one pass (links stay literal in a
123 // file name; {{title}} threw above). One pass so no token re-scans
124 // another's output (#1358).
125 output = this.replaceCurrentFileTokensInString(output, {
126 fileName: true,
127 folder: true,
128 });
129 return output;
130 }
131
132 async formatFileContent(input: string): Promise<string> {
133 let output: string = input;

Calls 1

formatMethod · 0.95

Tested by

no test coverage detected