(text, addition)
| 34 | } |
| 35 | |
| 36 | function addLineAfterLastOccurrence(text, addition) { |
| 37 | const regex = /^#!.+?$/gm |
| 38 | const matchArray = text.match(regex) |
| 39 | const lastIndex = matchArray ? matchArray.length - 1 : -1 |
| 40 | |
| 41 | if (lastIndex >= 0) { |
| 42 | const lastMatch = matchArray[lastIndex] |
| 43 | const insertIndex = text.indexOf(lastMatch) + lastMatch.length |
| 44 | const newText = text.slice(0, insertIndex) + addition + text.slice(insertIndex) |
| 45 | return newText |
| 46 | } |
| 47 | |
| 48 | return text |
| 49 | } |
| 50 | |
| 51 | let idx |
| 52 | let fromUrlScheme |