Simplify JavaScript string encoding (thanks, Diego Medina)