esamattis / esamattis/underscore.string

Make JavaScript String wrapper methods null/undefined-safe

Open
#484 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.