pax_global_header00006660000000000000000000000064125063511730014515gustar00rootroot0000000000000052 comment=3a46c81d39b5f94c0c17c47638939af2528520f3 defined-1.0.0/000077500000000000000000000000001250635117300131115ustar00rootroot00000000000000defined-1.0.0/.travis.yml000066400000000000000000000000531250635117300152200ustar00rootroot00000000000000language: node_js node_js: - 0.6 - 0.8 defined-1.0.0/LICENSE000066400000000000000000000020611250635117300141150ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. defined-1.0.0/example/000077500000000000000000000000001250635117300145445ustar00rootroot00000000000000defined-1.0.0/example/defined.js000066400000000000000000000001731250635117300165010ustar00rootroot00000000000000var defined = require('../'); var opts = { y : false, w : 4 }; var x = defined(opts.x, opts.y, opts.w, 8); console.log(x); defined-1.0.0/index.js000066400000000000000000000002261250635117300145560ustar00rootroot00000000000000module.exports = function () { for (var i = 0; i < arguments.length; i++) { if (arguments[i] !== undefined) return arguments[i]; } }; defined-1.0.0/package.json000066400000000000000000000021061250635117300153760ustar00rootroot00000000000000{ "name" : "defined", "version" : "1.0.0", "description" : "return the first argument that is `!== undefined`", "main" : "index.js", "directories" : { "example" : "example", "test" : "test" }, "dependencies" : {}, "devDependencies" : { "tape" : "~3.5.0" }, "scripts" : { "test" : "tape test/*.js" }, "testling" : { "files" : "test/*.js", "browsers" : { "ie" : [ 6, 7, 8, 9 ], "ff" : [ 3.5, 10, 15.0 ], "chrome" : [ 10, 22 ], "safari" : [ 5.1 ], "opera" : [ 12 ] } }, "repository" : { "type" : "git", "url" : "git://github.com/substack/defined.git" }, "homepage" : "https://github.com/substack/defined", "keywords" : [ "undefined", "short-circuit", "||", "or", "//", "defined-or" ], "author" : { "name" : "James Halliday", "email" : "mail@substack.net", "url" : "http://substack.net" }, "license" : "MIT" } defined-1.0.0/readme.markdown000066400000000000000000000020721250635117300161130ustar00rootroot00000000000000# 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 defined-1.0.0/test/000077500000000000000000000000001250635117300140705ustar00rootroot00000000000000defined-1.0.0/test/def.js000066400000000000000000000013371250635117300151700ustar00rootroot00000000000000var defined = require('../'); var test = require('tape'); test('defined-or', function (t) { var u = undefined; t.equal(defined(), u, 'empty arguments'); t.equal(defined(u), u, '1 undefined'); t.equal(defined(u, u), u, '2 undefined'); t.equal(defined(u, u, u, u), u, '4 undefineds'); t.equal(defined(undefined, false, true), false, 'false[0]'); t.equal(defined(false, true), false, 'false[1]'); t.equal(defined(undefined, 0, true), 0, 'zero[0]'); t.equal(defined(0, true), 0, 'zero[1]'); t.equal(defined(3, undefined, 4), 3, 'first arg'); t.equal(defined(undefined, 3, 4), 3, 'second arg'); t.equal(defined(undefined, undefined, 3), 3, 'third arg'); t.end(); }); defined-1.0.0/test/falsy.js000066400000000000000000000003271250635117300155460ustar00rootroot00000000000000var test = require('tape'); var defined = require('../'); test('falsy', function (t) { t.plan(1); var opts = { y : false, w : 4 }; var x = defined(opts.x, opts.y, opts.w, 8); t.equal(x, false); });