refactoring a nice js string lib