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

Ross Gammon ross-guest at moszumanska.debian.org
Sun Jul 23 18:39:25 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 726c55ba56d9ab1787085306f1b75526f60c902f
Author: Ross Gammon <rosco2 at ubuntu.com>
Date:   Sun Jul 23 19:42:02 2017 +0200

    New upstream version 1.2.2
---
 .travis.yml    | 163 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 index.js       | 124 ++++++++++++++++++++++++++++---------------
 package.json   |   7 +--
 test/fn.js     |   4 +-
 test/number.js |   8 +++
 test/values.js |  28 ++++++++++
 6 files changed, 266 insertions(+), 68 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index b0273e1..50dd17e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,52 +1,171 @@
 language: node_js
+os:
+ - linux
 node_js:
-  - "iojs-v3.2"
-  - "iojs-v3.1"
-  - "iojs-v3.0"
+  - "7.7"
+  - "6.10"
+  - "5.12"
+  - "4.8"
+  - "iojs-v3.3"
   - "iojs-v2.5"
-  - "iojs-v2.4"
-  - "iojs-v2.3"
-  - "iojs-v2.2"
-  - "iojs-v2.1"
-  - "iojs-v2.0"
   - "iojs-v1.8"
-  - "iojs-v1.7"
-  - "iojs-v1.6"
-  - "iojs-v1.5"
-  - "iojs-v1.4"
-  - "iojs-v1.3"
-  - "iojs-v1.2"
-  - "iojs-v1.1"
-  - "iojs-v1.0"
   - "0.12"
-  - "0.11"
   - "0.10"
-  - "0.9"
   - "0.8"
-  - "0.6"
-  - "0.4"
 before_install:
-  - '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] || npm install -g npm at 1.4.28 && npm install -g npm'
+  - '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'
+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:
+  - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
+  - 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
+  - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
+  - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
 sudo: false
+env:
+  - TEST=true
 matrix:
   fast_finish: true
-  allow_failures:
+  include:
+    - node_js: "7.6"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.5"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.4"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.3"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.2"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "7.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.9"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.8"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.7"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.6"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.5"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.4"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.3"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.2"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.11"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.10"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.9"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.8"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.7"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.6"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.5"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.4"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.3"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.2"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "5.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.7"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.6"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.5"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.4"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.3"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.2"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "4.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "iojs-v3.2"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v3.1"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v3.0"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v2.4"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v2.3"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v2.2"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v2.1"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v2.0"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.7"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.6"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.5"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.4"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.3"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.2"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.1"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "iojs-v1.0"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "0.11"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "0.9"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "0.6"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "0.4"
+      env: TEST=true ALLOW_FAILURE=true
+    ##- node_js: "7"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "6"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "5"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "4"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "iojs"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "0.12"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "0.10"
+      #env: TEST=true
+      #os: osx
+    #- node_js: "0.8"
+      #env: TEST=true
+      #os: osx
+  allow_failures:
+    - os: osx
+    - env: TEST=true ALLOW_FAILURE=true
diff --git a/index.js b/index.js
index c34abd0..0cbb43f 100644
--- a/index.js
+++ b/index.js
@@ -6,18 +6,38 @@ var hasSet = typeof Set === 'function' && Set.prototype;
 var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null;
 var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null;
 var setForEach = hasSet && Set.prototype.forEach;
+var booleanValueOf = Boolean.prototype.valueOf;
+var objectToString = Object.prototype.toString;
 
 module.exports = function inspect_ (obj, opts, depth, seen) {
+    if (typeof obj === 'undefined') {
+        return 'undefined';
+    }
+    if (obj === null) {
+        return 'null';
+    }
+    if (typeof obj === 'boolean') {
+        return obj ? 'true' : 'false';
+    }
+    if (typeof obj === 'string') {
+        return inspectString(obj);
+    }
+    if (typeof obj === 'number') {
+      if (obj === 0) {
+        return Infinity / obj > 0 ? '0' : '-0';
+      }
+      return String(obj);
+    }
+
     if (!opts) opts = {};
-    
-    var maxDepth = opts.depth === undefined ? 5 : opts.depth;
-    if (depth === undefined) depth = 0;
-    if (depth >= maxDepth && maxDepth > 0
-    && obj && typeof obj === 'object') {
+
+    var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
+    if (typeof depth === 'undefined') depth = 0;
+    if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
         return '[Object]';
     }
-    
-    if (seen === undefined) seen = [];
+
+    if (typeof seen === 'undefined') seen = [];
     else if (indexOf(seen, obj) >= 0) {
         return '[Circular]';
     }
@@ -29,22 +49,16 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         }
         return inspect_(value, opts, depth + 1, seen);
     }
-    
-    if (typeof obj === 'string') {
-        return inspectString(obj);
-    }
-    else if (typeof obj === 'function') {
+
+    if (typeof obj === 'function') {
         var name = nameOf(obj);
         return '[Function' + (name ? ': ' + name : '') + ']';
     }
-    else if (obj === null) {
-        return 'null';
-    }
-    else if (isSymbol(obj)) {
+    if (isSymbol(obj)) {
         var symString = Symbol.prototype.toString.call(obj);
-        return typeof obj === 'object' ? 'Object(' + symString + ')' : symString;
+        return typeof obj === 'object' ? markBoxed(symString) : symString;
     }
-    else if (isElement(obj)) {
+    if (isElement(obj)) {
         var s = '<' + String(obj.nodeName).toLowerCase();
         var attrs = obj.attributes || [];
         for (var i = 0; i < attrs.length; i++) {
@@ -55,7 +69,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         s += '</' + String(obj.nodeName).toLowerCase() + '>';
         return s;
     }
-    else if (isArray(obj)) {
+    if (isArray(obj)) {
         if (obj.length === 0) return '[]';
         var xs = Array(obj.length);
         for (var i = 0; i < obj.length; i++) {
@@ -63,7 +77,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         }
         return '[ ' + xs.join(', ') + ' ]';
     }
-    else if (isError(obj)) {
+    if (isError(obj)) {
         var parts = [];
         for (var key in obj) {
             if (!has(obj, key)) continue;
@@ -75,31 +89,38 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
                 parts.push(key + ': ' + inspect(obj[key]));
             }
         }
-        if (parts.length === 0) return '[' + obj + ']';
-        return '{ [' + obj + '] ' + parts.join(', ') + ' }';
+        if (parts.length === 0) return '[' + String(obj) + ']';
+        return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
     }
-    else if (typeof obj === 'object' && typeof obj.inspect === 'function') {
+    if (typeof obj === 'object' && typeof obj.inspect === 'function') {
         return obj.inspect();
     }
-    else if (isMap(obj)) {
+    if (isMap(obj)) {
         var parts = [];
         mapForEach.call(obj, function (value, key) {
             parts.push(inspect(key, obj) + ' => ' + inspect(value, obj));
         });
-        return 'Map (' + mapSize.call(obj) + ') {' + parts.join(', ') + '}';
+        return collectionOf('Map', mapSize.call(obj), parts);
     }
-    else if (isSet(obj)) {
+    if (isSet(obj)) {
         var parts = [];
         setForEach.call(obj, function (value ) {
             parts.push(inspect(value, obj));
         });
-        return 'Set (' + setSize.call(obj) + ') {' + parts.join(', ') + '}';
+        return collectionOf('Set', setSize.call(obj), parts);
     }
-    else if (typeof obj === 'object' && !isDate(obj) && !isRegExp(obj)) {
-        var xs = [], keys = [];
-        for (var key in obj) {
-            if (has(obj, key)) keys.push(key);
-        }
+    if (isNumber(obj)) {
+        return markBoxed(Number(obj));
+    }
+    if (isBoolean(obj)) {
+        return markBoxed(booleanValueOf.call(obj));
+    }
+    if (isString(obj)) {
+        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];
@@ -111,9 +132,17 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         if (xs.length === 0) return '{}';
         return '{ ' + xs.join(', ') + ' }';
     }
-    else return String(obj);
+    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, '"');
 }
@@ -123,6 +152,9 @@ function isDate (obj) { return toStr(obj) === '[object Date]' }
 function isRegExp (obj) { return toStr(obj) === '[object RegExp]' }
 function isError (obj) { return toStr(obj) === '[object Error]' }
 function isSymbol (obj) { return toStr(obj) === '[object Symbol]' }
+function isString (obj) { return toStr(obj) === '[object String]' }
+function isNumber (obj) { return toStr(obj) === '[object Number]' }
+function isBoolean (obj) { return toStr(obj) === '[object Boolean]' }
 
 var hasOwn = Object.prototype.hasOwnProperty || function (key) { return key in this; };
 function has (obj, key) {
@@ -130,12 +162,12 @@ function has (obj, key) {
 }
 
 function toStr (obj) {
-    return Object.prototype.toString.call(obj);
+    return objectToString.call(obj);
 }
 
 function nameOf (f) {
     if (f.name) return f.name;
-    var m = f.toString().match(/^function\s*([\w$]+)/);
+    var m = String(f).match(/^function\s*([\w$]+)/);
     if (m) return m[1];
 }
 
@@ -182,11 +214,19 @@ function isElement (x) {
 function inspectString (str) {
     var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
     return "'" + s + "'";
-    
-    function lowbyte (c) {
-        var n = c.charCodeAt(0);
-        var x = { 8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' }[n];
-        if (x) return '\\' + x;
-        return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16);
-    }
+}
+
+function lowbyte (c) {
+    var n = c.charCodeAt(0);
+    var x = { 8: 'b', 9: 't', 10: 'n', 12: 'f', 13: 'r' }[n];
+    if (x) return '\\' + x;
+    return '\\x' + (n < 0x10 ? '0' : '') + n.toString(16);
+}
+
+function markBoxed (str) {
+    return 'Object(' + str + ')';
+}
+
+function collectionOf(type, size, entries) {
+    return type + ' (' + size + ') {' + entries.join(', ') + '}';
 }
diff --git a/package.json b/package.json
index 88a1a0b..0189382 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,14 @@
 {
   "name": "object-inspect",
-  "version": "1.1.0",
+  "version": "1.2.2",
   "description": "string representations of objects in node and the browser",
   "main": "index.js",
   "devDependencies": {
-    "tape": "^4.2.2"
+    "tape": "^4.6.3"
   },
   "scripts": {
-    "test": "tape test/*.js"
+    "test": "npm run tests-only",
+    "tests-only": "tape test/*.js"
   },
   "testling": {
     "files": [
diff --git a/test/fn.js b/test/fn.js
index 55357db..be166ff 100644
--- a/test/fn.js
+++ b/test/fn.js
@@ -9,7 +9,9 @@ test('function', function (t) {
 
 test('function name', function (t) {
     t.plan(1);
-    var f = function () {};
+    var f = (function () {
+      return function () {};
+    }());
     f.toString = function () { return 'function xxx () {}' };
     var obj = [ 1, 2, f, 4 ];
     t.equal(inspect(obj), '[ 1, 2, [Function: xxx], 4 ]');
diff --git a/test/number.js b/test/number.js
new file mode 100644
index 0000000..e5377ac
--- /dev/null
+++ b/test/number.js
@@ -0,0 +1,8 @@
+var inspect = require('../');
+var test = require('tape');
+
+test('negative zero', function (t) {
+    t.equal(inspect(0), '0');
+    t.equal(inspect(-0), '-0');
+    t.end();
+});
diff --git a/test/values.js b/test/values.js
index af10dbe..a07d480 100644
--- a/test/values.js
+++ b/test/values.js
@@ -92,3 +92,31 @@ test('Set', { skip: typeof Set !== 'function' }, function (t) {
 
     t.end();
 });
+
+test('Strings', function (t) {
+    var str = 'abc';
+
+    t.equal(inspect(str), "'" + str + "'", 'primitive string shows as such');
+    t.equal(inspect(Object(str)), 'Object(' + inspect(str) + ')', 'String object shows as such');
+
+    t.end();
+});
+
+test('Numbers', function (t) {
+    var num = 42;
+
+    t.equal(inspect(num), String(num), 'primitive number shows as such');
+    t.equal(inspect(Object(num)), 'Object(' + inspect(num) + ')', 'Number object shows as such');
+
+    t.end();
+});
+
+test('Booleans', function (t) {
+    t.equal(inspect(true), String(true), 'primitive true shows as such');
+    t.equal(inspect(Object(true)), 'Object(' + inspect(true) + ')', 'Boolean object true shows as such');
+
+    t.equal(inspect(false), String(false), 'primitive false shows as such');
+    t.equal(inspect(Object(false)), 'Object(' + inspect(false) + ')', 'Boolean false object shows as such');
+
+    t.end();
+});

-- 
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