-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"rules": { | ||
"consistent-return": 1, | ||
"indent": [2, 4], | ||
"sort-keys": 0, | ||
}, | ||
|
||
"overrides": [ | ||
{ | ||
"files": "example/**", | ||
"rules": { | ||
"no-console": 0, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
'use strict'; | ||
|
||
var defined = require('../'); | ||
var opts = { y : false, w : 4 }; | ||
var opts = { y: false, w: 4 }; | ||
var x = defined(opts.x, opts.y, opts.w, 8); | ||
console.log(x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
module.exports = function () { | ||
'use strict'; | ||
|
||
module.exports = function defined() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
if (arguments[i] !== undefined) return arguments[i]; | ||
if (typeof arguments[i] !== 'undefined') { | ||
return arguments[i]; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
'use strict'; | ||
|
||
var defined = require('../'); | ||
var test = require('tape'); | ||
|
||
test('defined-or', function (t) { | ||
var u = undefined; | ||
var u = void 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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
'use strict'; | ||
|
||
var test = require('tape'); | ||
var defined = require('../'); | ||
|
||
test('falsy', function (t) { | ||
t.plan(1); | ||
var opts = { y : false, w : 4 }; | ||
var opts = { y: false, w: 4 }; | ||
var x = defined(opts.x, opts.y, opts.w, 8); | ||
t.equal(x, false); | ||
}); |