1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-12 10:16:16 +01:00
Pinafore-Web-Client-Frontend/routes/_utils/strings.js
Nolan Lawson 8b282de973 refactor
2018-01-28 15:02:02 -08:00

16 lines
420 B
JavaScript

export function replaceAll(string, replacee, replacement) {
if (!string.length || !replacee.length || !replacement.length) {
return string
}
let idx
let pos = 0
while (true) {
idx = string.indexOf(replacee, pos)
if (idx === -1) {
break
}
string = string.substring(0, idx) + replacement + string.substring(idx + replacee.length)
pos = idx + replacement.length
}
return string
}