(data: string, opts: GluegunPatchingPatchOptions = {})
| 123 | } |
| 124 | |
| 125 | export 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 | |
| 142 | function insertNextToPattern(data: string, opts: GluegunPatchingPatchOptions) { |
| 143 | // Insert before/after a particular string |
no test coverage detected
searching dependent graphs…