[Pkg-javascript-commits] [node-defined] 01/03: Imported Upstream version 1.0.0

Ross Gammon ross-guest at moszumanska.debian.org
Wed Oct 21 14:34:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

ross-guest pushed a commit to branch master
in repository node-defined.

commit 5d0a2dc6cfe29f3a05e2e6d835698ee8e2109bcf
Author: Ross Gammon <rossgammon at mail.dk>
Date:   Wed Oct 21 15:56:08 2015 +0200

    Imported Upstream version 1.0.0
---
 .travis.yml        |  4 ++++
 LICENSE            | 18 ++++++++++++++++++
 example/defined.js |  4 ++++
 index.js           |  5 +++++
 package.json       | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 readme.markdown    | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/def.js        | 22 ++++++++++++++++++++++
 test/falsy.js      |  9 +++++++++
 8 files changed, 161 insertions(+)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..895dbd3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - 0.6
+  - 0.8
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ee27ba4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+This 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.
diff --git a/example/defined.js b/example/defined.js
new file mode 100644
index 0000000..7b5d982
--- /dev/null
+++ b/example/defined.js
@@ -0,0 +1,4 @@
+var defined = require('../');
+var opts = { y : false, w : 4 };
+var x = defined(opts.x, opts.y, opts.w, 8);
+console.log(x);
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..f8a2219
--- /dev/null
+++ b/index.js
@@ -0,0 +1,5 @@
+module.exports = function () {
+    for (var i = 0; i < arguments.length; i++) {
+        if (arguments[i] !== undefined) return arguments[i];
+    }
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..7f69976
--- /dev/null
+++ b/package.json
@@ -0,0 +1,46 @@
+{
+    "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 at substack.net",
+        "url" : "http://substack.net"
+    },
+    "license" : "MIT"
+}
diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..9616195
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,53 @@
+# 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
diff --git a/test/def.js b/test/def.js
new file mode 100644
index 0000000..48da517
--- /dev/null
+++ b/test/def.js
@@ -0,0 +1,22 @@
+var 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();
+});
diff --git a/test/falsy.js b/test/falsy.js
new file mode 100644
index 0000000..6b7d623
--- /dev/null
+++ b/test/falsy.js
@@ -0,0 +1,9 @@
+var 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);
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-defined.git



More information about the Pkg-javascript-commits mailing list