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

Function insertNextToPattern

src/toolbox/patching-tools.ts:142–156  ·  view source on GitHub ↗
(data: string, opts: GluegunPatchingPatchOptions)

Source from the content-addressed store, hash-verified

140}
141
142function insertNextToPattern(data: string, opts: GluegunPatchingPatchOptions) {
143 // Insert before/after a particular string
144 const findPattern: string | RegExp = opts.before || opts.after
145
146 // sanity check the findPattern
147 const patternIsString = typeof findPattern === 'string'
148 if (!(findPattern instanceof RegExp) && !patternIsString) return false
149
150 const isPatternFound = isPatternIncluded(data, findPattern)
151 if (!isPatternFound) return false
152
153 const originalString = patternIsString ? findPattern : data.match(findPattern)[0]
154 const newContents = opts.after ? `${originalString}${opts.insert || ''}` : `${opts.insert || ''}${originalString}`
155 return data.replace(findPattern, newContents)
156}
157
158function isPatternIncluded(data: string, findPattern: string | RegExp): boolean {
159 if (!findPattern) return false

Callers 1

patchStringFunction · 0.85

Calls 2

isPatternIncludedFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…