defined
return the first argument that is `!== undefined`
Last updated 2 years ago by ljharb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install defined 
SYNC missed versions from official npm registry.

defined Version Badge

github actions coverage License Downloads

npm badge

return the first argument that is !== undefined

Most of the time when I chain together ||s, I actually just want the first item that is not undefined, not the first non-falsy item.

This module is like the defined-or (//) operator in perl 5.10+.

example

var defined = require('defined');
var opts = { y : false, w : 4 };
var x = defined(opts.x, opts.y, opts.w, 100);
console.log(x);
$ node example/defined.js
false

The return value is false because false is the first item that is !== undefined.

methods

var defined = require('defined')

var x = defined(a, b, c...)

Return the first item in the argument list a, b, c... that is !== undefined.

If all the items are === undefined, return undefined.

install

With npm do:

npm install defined

license

MIT

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

3 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           10 years ago
  • 0.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)

Copyright 2013 - present © cnpmjs.org | Home |