Fixed javascript truncate

Resolved issues in the truncate() function.  Fixed #179.