[Pkg-javascript-commits] [node-object-inspect] 01/06: New upstream version 1.3.0

Ross Gammon ross-guest at moszumanska.debian.org
Fri Aug 4 20:59:16 UTC 2017


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

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

commit 1e7dd80b93d2f692683ac98c49a7fb2c443138f7
Author: Ross Gammon <rosco2 at ubuntu.com>
Date:   Fri Aug 4 21:46:56 2017 +0200

    New upstream version 1.3.0
---
 .gitignore      |  6 +++++
 .npmrc          |  1 +
 .travis.yml     | 20 ++++++++++++---
 index.js        | 76 ++++++++++++++++++++++++++++-----------------------------
 package.json    |  6 +++--
 test-core-js.js | 16 ++++++++++++
 test/values.js  | 10 ++++++++
 7 files changed, 92 insertions(+), 43 deletions(-)

diff --git a/.gitignore b/.gitignore
index 3c3629e..f833451 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,7 @@
+# gitignore
 node_modules
+
+# Only apps should have lockfiles
+npm-shrinkwrap.json
+package-lock.json
+yarn.lock
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/.travis.yml b/.travis.yml
index 50dd17e..7693d63 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,8 +2,9 @@ language: node_js
 os:
  - linux
 node_js:
-  - "7.7"
-  - "6.10"
+  - "8.2"
+  - "7.10"
+  - "6.11"
   - "5.12"
   - "4.8"
   - "iojs-v3.3"
@@ -14,7 +15,7 @@ node_js:
   - "0.8"
 before_install:
   - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm at 1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm at 1.4.28 ;; 2.*) npm install -g npm at 2 ;; esac ; fi'
-  - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then npm install -g npm; fi'
+  - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm at 4.5 ; else npm install -g npm; fi; fi'
 install:
   - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then nvm install 0.8 && npm install -g npm at 1.3 && npm install -g npm at 1.4.28 && npm install -g npm at 2 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
 script:
@@ -28,6 +29,16 @@ env:
 matrix:
   fast_finish: true
   include:
+    - node_js: "8.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.9"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.8"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.7"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "7.6"
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "7.5"
@@ -42,6 +53,8 @@ matrix:
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "7.0"
       env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.10"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "6.9"
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "6.8"
@@ -169,3 +182,4 @@ matrix:
   allow_failures:
     - os: osx
     - env: TEST=true ALLOW_FAILURE=true
+    - env: COVERAGE=true
diff --git a/index.js b/index.js
index 0cbb43f..47b7631 100644
--- a/index.js
+++ b/index.js
@@ -41,7 +41,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
     else if (indexOf(seen, obj) >= 0) {
         return '[Circular]';
     }
-    
+
     function inspect (value, from) {
         if (from) {
             seen = seen.slice();
@@ -71,24 +71,10 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
     }
     if (isArray(obj)) {
         if (obj.length === 0) return '[]';
-        var xs = Array(obj.length);
-        for (var i = 0; i < obj.length; i++) {
-            xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
-        }
-        return '[ ' + xs.join(', ') + ' ]';
+        return '[ ' + arrObjKeys(obj, inspect).join(', ') + ' ]';
     }
     if (isError(obj)) {
-        var parts = [];
-        for (var key in obj) {
-            if (!has(obj, key)) continue;
-            
-            if (/[^\w$]/.test(key)) {
-                parts.push(inspect(key) + ': ' + inspect(obj[key]));
-            }
-            else {
-                parts.push(key + ': ' + inspect(obj[key]));
-            }
-        }
+        var parts = arrObjKeys(obj, inspect);
         if (parts.length === 0) return '[' + String(obj) + ']';
         return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
     }
@@ -119,30 +105,13 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         return markBoxed(inspect(String(obj)));
     }
     if (!isDate(obj) && !isRegExp(obj)) {
-        var xs = [];
-        var keys = objectKeys(obj);
-        keys.sort();
-        for (var i = 0; i < keys.length; i++) {
-            var key = keys[i];
-            if (/[^\w$]/.test(key)) {
-                xs.push(inspect(key) + ': ' + inspect(obj[key], obj));
-            }
-            else xs.push(key + ': ' + inspect(obj[key], obj));
-        }
+        var xs = arrObjKeys(obj, inspect);
         if (xs.length === 0) return '{}';
         return '{ ' + xs.join(', ') + ' }';
     }
     return String(obj);
 };
 
-function objectKeys(obj) {
-    var keys = [];
-    for (var key in obj) {
-        if (has(obj, key)) keys.push(key);
-    }
-    return keys;
-}
-
 function quote (s) {
     return String(s).replace(/"/g, '"');
 }
@@ -185,7 +154,12 @@ function isMap (x) {
     }
     try {
         mapSize.call(x);
-        return true;
+        try {
+            setSize.call(x);
+        } catch (s) {
+            return true;
+        }
+        return x instanceof Map; // core-js workaround, pre-v2.5.0
     } catch (e) {}
     return false;
 }
@@ -196,7 +170,12 @@ function isSet (x) {
     }
     try {
         setSize.call(x);
-        return true;
+        try {
+            mapSize.call(x);
+        } catch (m) {
+            return true;
+        }
+        return x instanceof Set; // core-js workaround, pre-v2.5.0
     } catch (e) {}
     return false;
 }
@@ -227,6 +206,27 @@ function markBoxed (str) {
     return 'Object(' + str + ')';
 }
 
-function collectionOf(type, size, entries) {
+function collectionOf (type, size, entries) {
     return type + ' (' + size + ') {' + entries.join(', ') + '}';
 }
+
+function arrObjKeys (obj, inspect) {
+    var isArr = isArray(obj);
+    var xs = [];
+    if (isArr) {
+        xs.length = obj.length;
+        for (var i = 0; i < obj.length; i++) {
+            xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
+        }
+    }
+    for (var key in obj) {
+        if (!has(obj, key)) continue;
+        if (isArr && String(Number(key)) === key && key < obj.length) continue;
+        if (/[^\w$]/.test(key)) {
+            xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj));
+        } else {
+            xs.push(key + ': ' + inspect(obj[key], obj));
+        }
+    }
+    return xs;
+}
diff --git a/package.json b/package.json
index 0189382..fadef0c 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,15 @@
 {
   "name": "object-inspect",
-  "version": "1.2.2",
+  "version": "1.3.0",
   "description": "string representations of objects in node and the browser",
   "main": "index.js",
   "devDependencies": {
-    "tape": "^4.6.3"
+    "core-js": "^2.4.1",
+    "tape": "^4.7.0"
   },
   "scripts": {
     "test": "npm run tests-only",
+    "pretests-only": "node test-core-js",
     "tests-only": "tape test/*.js"
   },
   "testling": {
diff --git a/test-core-js.js b/test-core-js.js
new file mode 100644
index 0000000..12c4e2a
--- /dev/null
+++ b/test-core-js.js
@@ -0,0 +1,16 @@
+'use strict';
+
+require('core-js');
+
+var inspect = require('./');
+var test = require('tape');
+
+test('Maps', function (t) {
+    t.equal(inspect(new Map([[1, 2]])), 'Map (1) {1 => 2}');
+    t.end();
+});
+
+test('Sets', function (t) {
+    t.equal(inspect(new Set([[1, 2]])), 'Set (1) {[ 1, 2 ]}');
+    t.end();
+});
diff --git a/test/values.js b/test/values.js
index a07d480..1fcd998 100644
--- a/test/values.js
+++ b/test/values.js
@@ -7,6 +7,16 @@ test('values', function (t) {
     t.equal(inspect(obj), '[ {}, [], { \'a-b\': 5 } ]');
 });
 
+test('arrays with properties', function (t) {
+   t.plan(1);
+   var arr = [3];
+   arr.foo = 'bar';
+   var obj = [1, 2, arr];
+   obj.baz = 'quux';
+   obj.index = -1;
+   t.equal(inspect(obj), '[ 1, 2, [ 3, foo: \'bar\' ], baz: \'quux\', index: -1 ]');
+});
+
 test('has', function (t) {
     t.plan(1);
     var has = Object.prototype.hasOwnProperty;

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



More information about the Pkg-javascript-commits mailing list