Sha256: a477f2f4e634885888279866061c92b917fab2e0bf5a53cb780f056a52f9e190

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

# defined

return the first argument that is `!== undefined`

[![browser support](http://ci.testling.com/substack/defined.png)](http://ci.testling.com/substack/defined)

[![build status](https://secure.travis-ci.org/substack/defined.png)](http://travis-ci.org/substack/defined)

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

``` js
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

``` js
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](https://npmjs.org) do:

```
npm install defined
```

# license

MIT

Version data entries

20 entries across 20 versions & 9 rubygems

Version Path
boring_generators-0.5.0 tmp/templates/app_template/node_modules/defined/readme.markdown
boring_generators-0.4.0 tmp/templates/app_template/node_modules/defined/readme.markdown
ilog-0.4.1 node_modules/defined/readme.markdown
ilog-0.4.0 node_modules/defined/readme.markdown
ilog-0.3.3 node_modules/defined/readme.markdown
optimacms-0.4.3 spec/dummy/node_modules/defined/readme.markdown
optimacms-0.4.2 spec/dummy/node_modules/defined/readme.markdown
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/defined/readme.markdown
locomotivecms-3.4.0 app/javascript/node_modules/defined/readme.markdown
cortex-0.1.3 spec/dummy/node_modules/defined/readme.markdown
lanes-0.8.0 node_modules/defined/readme.markdown
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/defined/readme.markdown
minimum_viable_product-0.0.11 test/dummy/node_modules/defined/readme.markdown
brwy_rails-0.0.6 test/dummy/node_modules/defined/readme.markdown
brwy_rails-0.0.5 test/dummy/node_modules/defined/readme.markdown
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/defined/readme.markdown
brwy_rails-0.0.4 test/dummy/node_modules/defined/readme.markdown
brwy_rails-0.0.3 test/dummy/node_modules/defined/readme.markdown
brwy_rails-0.0.2 test/dummy/node_modules/defined/readme.markdown
brwy_rails-0.0.1 test/dummy/node_modules/defined/readme.markdown