MCPcopy Create free account
hub / github.com/Snapchat/Valdi / replacePath

Method replacePath

valdi/vscode_debugger/src/test/goldenText.ts:135–144  ·  view source on GitHub ↗
(needle: string, replacement: string)

Source from the content-addressed store, hash-verified

133 _sanitize(value: string): string {
134 // replaces path like C:/testDir/foo/bar.js -> ${testDir}/foo/bar.js
135 const replacePath = (needle: string, replacement: string) => {
136 // Escape special chars, force paths to use forward slashes
137 const safeStr = escapeRegexSpecialChars(forceForwardSlashes(needle), '/');
138 // Create an re that allows for any slash delimiter, and looks at the rest of the line
139 const re = new RegExp(safeStr.replace(/\//g, '[\\\\/]') + '(.*)', 'gi');
140
141 // Replace it with the ${replacementString} and a forward-slashed version
142 // of the rest of the line.
143 value = value.replace(re, (_match, trailing) => replacement + forceForwardSlashes(trailing));
144 };
145
146 value = String(value);
147 replacePath(this._workspaceFolder, '${workspaceFolder}');

Callers

nothing calls this directly

Calls 3

escapeRegexSpecialCharsFunction · 0.90
forceForwardSlashesFunction · 0.90
replaceMethod · 0.65

Tested by

no test coverage detected