underscore.string
underscore.string copied to clipboard
Make JavaScript String wrapper methods null/undefined-safe
A great benefit of Java String Utils libraries such as Apache Commons StringUtils is their null-safety. You should be able to provide null/undefined-safety to your JavaScript String wrapper functions, e.g.
expect(_s(null).toUpperCase().value()).to.be.a('null');
expect(_s(undefined).toUpperCase().value()).to.be.an('undefined');
I successfully spiked out this functionality with a couple of tweaks to index.js.
You may also want to add explicit null/undefined-safe wrapper functions, so that one can tap into this safety without chaining, e.g.
expect(_s.toUpperCase(null)).to.be.a('null');
expect(_s.toUpperCase(undefined)).to.be.an('undefined');