(data: string, opts: GluegunPatchingPatchOptions)
| 140 | } |
| 141 | |
| 142 | function 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 | |
| 158 | function isPatternIncluded(data: string, findPattern: string | RegExp): boolean { |
| 159 | if (!findPattern) return false |
no test coverage detected
searching dependent graphs…