Method to perform simple replacements in JavaScript