underscore.string icon indicating copy to clipboard operation
underscore.string copied to clipboard

Make JavaScript String wrapper methods null/undefined-safe

Open d215steinberg opened this issue 10 years ago • 0 comments

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');

d215steinberg avatar Jan 28 '16 21:01 d215steinberg