Code for a convenient way to encode a string safe for javascript i.e. properly escaped