I wrote a small JavaScript library called undefsafe which I use in my work. I believe the _.get lodash package is very similar (though I added a few super powers to my own library).
However, with frameworks like Next.js and Nuxt.js (and likely others), I've found that I don't need undefsafe due to the optional chaining and nullish coalescing features that are provided with ES2020 (which are polyfilled for us in these frameworks).
This means my code can go from this:
let v = undefsafe(this, 'pkg.services.vulns.count') || "not available";
To this:
let v = this.pkg.services?.vulns.count ?? "not available";
The nullish coalesce is useful because of .count
is 0
, then the value of v
is, correctly, zero.