MCPcopy
hub / github.com/infinitered/gluegun / patchString

Function patchString

src/toolbox/patching-tools.ts:125–140  ·  view source on GitHub ↗
(data: string, opts: GluegunPatchingPatchOptions = {})

Source from the content-addressed store, hash-verified

123}
124
125export function patchString(data: string, opts: GluegunPatchingPatchOptions = {}): string | false {
126 // Already includes string, and not forcing it
127 if (isPatternIncluded(data, opts.insert) && !opts.force) return false
128
129 // delete <string> is the same as replace <string> + insert ''
130 const replaceString = opts.delete || opts.replace
131
132 if (replaceString) {
133 if (!isPatternIncluded(data, replaceString)) return false
134
135 // Replace matching string with new string or nothing if nothing provided
136 return data.replace(replaceString, `${opts.insert || ''}`)
137 } else {
138 return insertNextToPattern(data, opts)
139 }
140}
141
142function insertNextToPattern(data: string, opts: GluegunPatchingPatchOptions) {
143 // Insert before/after a particular string

Callers 1

patchFunction · 0.85

Calls 3

isPatternIncludedFunction · 0.85
insertNextToPatternFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…