[Pkg-javascript-commits] [node-deep-is] 01/05: Import Upstream version 0.1.3

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Mon Oct 10 12:16:02 UTC 2016


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

praveen pushed a commit to branch master
in repository node-deep-is.

commit e63a25d733ebdd85c4bd20825002d16afd75a9e2
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date:   Mon Oct 10 16:51:09 2016 +0530

    Import Upstream version 0.1.3
---
 .gitignore           |   1 +
 .travis.yml          |   6 +++
 LICENSE              |  22 +++++++++++
 README.markdown      |  70 +++++++++++++++++++++++++++++++++++
 example/cmp.js       |  11 ++++++
 index.js             | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json         |  61 ++++++++++++++++++++++++++++++
 test/NaN.js          |  16 ++++++++
 test/cmp.js          |  23 ++++++++++++
 test/neg-vs-pos-0.js |  15 ++++++++
 10 files changed, 327 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d523c5f
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+  - 0.4
+  - 0.6
+  - 0.8
+  - 0.10
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c38f840
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012, 2013 Thorsten Lorenz <thlorenz at gmx.de>
+Copyright (c) 2012 James Halliday <mail at substack.net>
+Copyright (c) 2009 Thomas Robinson <280north.com>
+
+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/README.markdown b/README.markdown
new file mode 100644
index 0000000..eb69a83
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,70 @@
+deep-is
+==========
+
+Node's `assert.deepEqual() algorithm` as a standalone module. Exactly like
+[deep-equal](https://github.com/substack/node-deep-equal) except for the fact that `deepEqual(NaN, NaN) === true`.
+
+This module is around [5 times faster](https://gist.github.com/2790507)
+than wrapping `assert.deepEqual()` in a `try/catch`.
+
+[![browser support](http://ci.testling.com/thlorenz/deep-is.png)](http://ci.testling.com/thlorenz/deep-is)
+
+[![build status](https://secure.travis-ci.org/thlorenz/deep-is.png)](http://travis-ci.org/thlorenz/deep-is)
+
+example
+=======
+
+``` js
+var equal = require('deep-is');
+console.dir([
+    equal(
+        { a : [ 2, 3 ], b : [ 4 ] },
+        { a : [ 2, 3 ], b : [ 4 ] }
+    ),
+    equal(
+        { x : 5, y : [6] },
+        { x : 5, y : 6 }
+    )
+]);
+```
+
+methods
+=======
+
+var deepIs = require('deep-is')
+
+deepIs(a, b)
+---------------
+
+Compare objects `a` and `b`, returning whether they are equal according to a
+recursive equality algorithm.
+
+install
+=======
+
+With [npm](http://npmjs.org) do:
+
+```
+npm install deep-is
+```
+
+test
+====
+
+With [npm](http://npmjs.org) do:
+
+```
+npm test
+```
+
+license
+=======
+
+Copyright (c) 2012, 2013 Thorsten Lorenz <thlorenz at gmx.de>
+Copyright (c) 2012 James Halliday <mail at substack.net>
+
+Derived largely from node's assert module, which has the copyright statement:
+
+Copyright (c) 2009 Thomas Robinson <280north.com>
+
+Released under the MIT license, see LICENSE for details.
diff --git a/example/cmp.js b/example/cmp.js
new file mode 100644
index 0000000..67014b8
--- /dev/null
+++ b/example/cmp.js
@@ -0,0 +1,11 @@
+var equal = require('../');
+console.dir([
+    equal(
+        { a : [ 2, 3 ], b : [ 4 ] },
+        { a : [ 2, 3 ], b : [ 4 ] }
+    ),
+    equal(
+        { x : 5, y : [6] },
+        { x : 5, y : 6 }
+    )
+]);
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..506fe27
--- /dev/null
+++ b/index.js
@@ -0,0 +1,102 @@
+var pSlice = Array.prototype.slice;
+var Object_keys = typeof Object.keys === 'function'
+    ? Object.keys
+    : function (obj) {
+        var keys = [];
+        for (var key in obj) keys.push(key);
+        return keys;
+    }
+;
+
+var deepEqual = module.exports = function (actual, expected) {
+  // enforce Object.is +0 !== -0
+  if (actual === 0 && expected === 0) {
+    return areZerosEqual(actual, expected);
+
+  // 7.1. All identical values are equivalent, as determined by ===.
+  } else if (actual === expected) {
+    return true;
+
+  } else if (actual instanceof Date && expected instanceof Date) {
+    return actual.getTime() === expected.getTime();
+
+  } else if (isNumberNaN(actual)) {
+    return isNumberNaN(expected);
+
+  // 7.3. Other pairs that do not both pass typeof value == 'object',
+  // equivalence is determined by ==.
+  } else if (typeof actual != 'object' && typeof expected != 'object') {
+    return actual == expected;
+
+  // 7.4. For all other Object pairs, including Array objects, equivalence is
+  // determined by having the same number of owned properties (as verified
+  // with Object.prototype.hasOwnProperty.call), the same set of keys
+  // (although not necessarily the same order), equivalent values for every
+  // corresponding key, and an identical 'prototype' property. Note: this
+  // accounts for both named and indexed properties on Arrays.
+  } else {
+    return objEquiv(actual, expected);
+  }
+};
+
+function isUndefinedOrNull(value) {
+  return value === null || value === undefined;
+}
+
+function isArguments(object) {
+  return Object.prototype.toString.call(object) == '[object Arguments]';
+}
+
+function isNumberNaN(value) {
+  // NaN === NaN -> false
+  return typeof value == 'number' && value !== value;
+}
+
+function areZerosEqual(zeroA, zeroB) {
+  // (1 / +0|0) -> Infinity, but (1 / -0) -> -Infinity and (Infinity !== -Infinity)
+  return (1 / zeroA) === (1 / zeroB);
+}
+
+function objEquiv(a, b) {
+  if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
+    return false;
+
+  // an identical 'prototype' property.
+  if (a.prototype !== b.prototype) return false;
+  //~~~I've managed to break Object.keys through screwy arguments passing.
+  //   Converting to array solves the problem.
+  if (isArguments(a)) {
+    if (!isArguments(b)) {
+      return false;
+    }
+    a = pSlice.call(a);
+    b = pSlice.call(b);
+    return deepEqual(a, b);
+  }
+  try {
+    var ka = Object_keys(a),
+        kb = Object_keys(b),
+        key, i;
+  } catch (e) {//happens when one is a string literal and the other isn't
+    return false;
+  }
+  // having the same number of owned properties (keys incorporates
+  // hasOwnProperty)
+  if (ka.length != kb.length)
+    return false;
+  //the same set of keys (although not necessarily the same order),
+  ka.sort();
+  kb.sort();
+  //~~~cheap key test
+  for (i = ka.length - 1; i >= 0; i--) {
+    if (ka[i] != kb[i])
+      return false;
+  }
+  //equivalent values for every corresponding key, and
+  //~~~possibly expensive deep test
+  for (i = ka.length - 1; i >= 0; i--) {
+    key = ka[i];
+    if (!deepEqual(a[key], b[key])) return false;
+  }
+  return true;
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..63628f0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,61 @@
+{
+  "name": "deep-is",
+  "version": "0.1.3",
+  "description": "node's assert.deepEqual algorithm except for NaN being equal to NaN",
+  "main": "index.js",
+  "directories": {
+    "lib": ".",
+    "example": "example",
+    "test": "test"
+  },
+  "scripts": {
+    "test": "tape test/*.js"
+  },
+  "devDependencies": {
+    "tape": "~1.0.2"
+  },
+  "repository": {
+    "type": "git",
+    "url": "http://github.com/thlorenz/deep-is.git"
+  },
+  "keywords": [
+    "equality",
+    "equal",
+    "compare"
+  ],
+  "author": {
+    "name": "Thorsten Lorenz",
+    "email": "thlorenz at gmx.de",
+    "url": "http://thlorenz.com"
+  },
+  "license": {
+    "type": "MIT",
+    "url": "https://github.com/thlorenz/deep-is/blob/master/LICENSE"
+  },
+  "testling": {
+    "files": "test/*.js",
+    "browsers": {
+      "ie": [
+        6,
+        7,
+        8,
+        9
+      ],
+      "ff": [
+        3.5,
+        10,
+        15
+      ],
+      "chrome": [
+        10,
+        22
+      ],
+      "safari": [
+        5.1
+      ],
+      "opera": [
+        12
+      ]
+    }
+  }
+}
diff --git a/test/NaN.js b/test/NaN.js
new file mode 100644
index 0000000..ddaa5a7
--- /dev/null
+++ b/test/NaN.js
@@ -0,0 +1,16 @@
+var test = require('tape');
+var equal = require('../');
+
+test('NaN and 0 values', function (t) {
+    t.ok(equal(NaN, NaN));
+    t.notOk(equal(0, NaN));
+    t.ok(equal(0, 0));
+    t.notOk(equal(0, 1));
+    t.end();
+});
+
+
+test('nested NaN values', function (t) {
+    t.ok(equal([ NaN, 1, NaN ], [ NaN, 1, NaN ]));
+    t.end();
+});
diff --git a/test/cmp.js b/test/cmp.js
new file mode 100644
index 0000000..3071013
--- /dev/null
+++ b/test/cmp.js
@@ -0,0 +1,23 @@
+var test = require('tape');
+var equal = require('../');
+
+test('equal', function (t) {
+    t.ok(equal(
+        { a : [ 2, 3 ], b : [ 4 ] },
+        { a : [ 2, 3 ], b : [ 4 ] }
+    ));
+    t.end();
+});
+
+test('not equal', function (t) {
+    t.notOk(equal(
+        { x : 5, y : [6] },
+        { x : 5, y : 6 }
+    ));
+    t.end();
+});
+
+test('nested nulls', function (t) {
+    t.ok(equal([ null, null, null ], [ null, null, null ]));
+    t.end();
+});
diff --git a/test/neg-vs-pos-0.js b/test/neg-vs-pos-0.js
new file mode 100644
index 0000000..ac26130
--- /dev/null
+++ b/test/neg-vs-pos-0.js
@@ -0,0 +1,15 @@
+var test = require('tape');
+var equal = require('../');
+
+test('0 values', function (t) {
+    t.ok(equal( 0,  0), ' 0 ===  0');
+    t.ok(equal( 0, +0), ' 0 === +0');
+    t.ok(equal(+0, +0), '+0 === +0');
+    t.ok(equal(-0, -0), '-0 === -0');
+
+    t.notOk(equal(-0,  0), '-0 !==  0');
+    t.notOk(equal(-0, +0), '-0 !== +0');
+
+    t.end();
+});
+

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



More information about the Pkg-javascript-commits mailing list