Replace the first literal occurrence of needle in haystack with
replacement. Uses indexOf rather than String.prototype.replace
with a regex so we don't fall foul of the security/detect-unsafe-regex
lint rule, and so we never accidentally interpret regex metacharacters
inside needle or $1-style references inside replacement.
Parameters
haystack: string
String to search in
needle: string
Literal substring to replace
replacement: string
Literal replacement text (no $ escaping needed)
Returns string
Modified string, or haystack unchanged when needle is absent
Replace the first literal occurrence of
needleinhaystackwithreplacement. UsesindexOfrather thanString.prototype.replacewith a regex so we don't fall foul of the security/detect-unsafe-regex lint rule, and so we never accidentally interpret regex metacharacters insideneedleor$1-style references insidereplacement.