MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / addLineAfterLastOccurrence

Function addLineAfterLastOccurrence

SurgeModuleTool_macOS.js:191–204  ·  view source on GitHub ↗
(text, addition)

Source from the content-addressed store, hash-verified

189 return finalFileName
190}
191function addLineAfterLastOccurrence(text, addition) {
192 const regex = /^#!.+?$/gm
193 const matchArray = text.match(regex)
194 const lastIndex = matchArray ? matchArray.length - 1 : -1
195
196 if (lastIndex >= 0) {
197 const lastMatch = matchArray[lastIndex]
198 const insertIndex = text.indexOf(lastMatch) + lastMatch.length
199 const newText = text.slice(0, insertIndex) + addition + text.slice(insertIndex)
200 return newText
201 }
202
203 return text
204}
205
206function delay(ms) {
207 return new Promise(resolve => setTimeout(resolve, ms))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected