Javascript string truncation helper