[Pkg-javascript-commits] [node-object-inspect] 01/03: New upstream version 1.5.0

Bastien Roucariès rouca at moszumanska.debian.org
Fri Mar 9 15:46:26 UTC 2018


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

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

commit ff5eeff87a6662669d57b2234fb512f9c325206e
Author: Bastien ROUCARIÈS <roucaries.bastien at gmail.com>
Date:   Fri Mar 9 16:43:19 2018 +0100

    New upstream version 1.5.0
---
 .gitignore         |  4 ++++
 .nycrc             | 17 +++++++++++++++
 .travis.yml        | 62 ++++++++++++++++++++++++++----------------------------
 index.js           | 35 ++++++++++++++++++++++--------
 package.json       | 15 ++++++++-----
 readme.markdown    |  6 ++++--
 test/element.js    |  4 +++-
 test/fn.js         | 10 +++++++++
 test/number.js     |  8 +++++--
 test/quoteStyle.js | 17 +++++++++++++++
 test/values.js     |  4 ++++
 util.inspect.js    |  1 +
 12 files changed, 132 insertions(+), 51 deletions(-)

diff --git a/.gitignore b/.gitignore
index f833451..fe3655a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,7 @@ node_modules
 npm-shrinkwrap.json
 package-lock.json
 yarn.lock
+
+# Coverage
+coverage
+.nyc_output
diff --git a/.nycrc b/.nycrc
new file mode 100644
index 0000000..6455ef3
--- /dev/null
+++ b/.nycrc
@@ -0,0 +1,17 @@
+{
+  "all": true,
+  "check-coverage": true,
+  "instrumentation": false,
+  "sourceMap": false,
+  "reporter": "html",
+  "lines": 95.95,
+  "statements": 95,
+  "functions": 96,
+  "branches": 92,
+  "exclude": [
+    "coverage",
+    "example",
+    "test",
+    "test-core-js.js"
+  ]
+}
diff --git a/.travis.yml b/.travis.yml
index 7693d63..9c39fed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,9 +2,10 @@ language: node_js
 os:
  - linux
 node_js:
-  - "8.2"
+  - "9.3"
+  - "8.9"
   - "7.10"
-  - "6.11"
+  - "6.12"
   - "5.12"
   - "4.8"
   - "iojs-v3.3"
@@ -13,11 +14,11 @@ node_js:
   - "0.12"
   - "0.10"
   - "0.8"
+  - "0.6"
 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 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'
+  - 'nvm install-latest-npm'
 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;'
+  - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && 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'
@@ -29,6 +30,28 @@ env:
 matrix:
   fast_finish: true
   include:
+    - node_js: "node"
+      env: COVERAGE=true
+    - node_js: "9.2"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "9.1"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "9.0"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.8"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.7"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.6"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.5"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.4"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.3"
+      env: TEST=true ALLOW_FAILURE=true
+    - node_js: "8.2"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "8.1"
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "8.0"
@@ -53,6 +76,8 @@ matrix:
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "7.0"
       env: TEST=true ALLOW_FAILURE=true
+    - node_js: "6.11"
+      env: TEST=true ALLOW_FAILURE=true
     - node_js: "6.10"
       env: TEST=true ALLOW_FAILURE=true
     - node_js: "6.9"
@@ -151,35 +176,8 @@ matrix:
       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
-    - env: COVERAGE=true
diff --git a/index.js b/index.js
index 47b7631..ae78858 100644
--- a/index.js
+++ b/index.js
@@ -9,7 +9,16 @@ var setForEach = hasSet && Set.prototype.forEach;
 var booleanValueOf = Boolean.prototype.valueOf;
 var objectToString = Object.prototype.toString;
 
+var inspectCustom = require('./util.inspect').custom;
+var inspectSymbol = (inspectCustom && isSymbol(inspectCustom)) ? inspectCustom : null;
+
 module.exports = function inspect_ (obj, opts, depth, seen) {
+    if (!opts) opts = {};
+
+    if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
+        throw new TypeError('option "quoteStyle" must be "single" or "double"');
+    }
+
     if (typeof obj === 'undefined') {
         return 'undefined';
     }
@@ -19,8 +28,9 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
     if (typeof obj === 'boolean') {
         return obj ? 'true' : 'false';
     }
+
     if (typeof obj === 'string') {
-        return inspectString(obj);
+        return inspectString(obj, opts);
     }
     if (typeof obj === 'number') {
       if (obj === 0) {
@@ -29,8 +39,6 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
       return String(obj);
     }
 
-    if (!opts) opts = {};
-
     var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth;
     if (typeof depth === 'undefined') depth = 0;
     if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') {
@@ -62,7 +70,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         var s = '<' + String(obj.nodeName).toLowerCase();
         var attrs = obj.attributes || [];
         for (var i = 0; i < attrs.length; i++) {
-            s += ' ' + attrs[i].name + '="' + quote(attrs[i].value) + '"';
+            s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts);
         }
         s += '>';
         if (obj.childNodes && obj.childNodes.length) s += '...';
@@ -78,8 +86,12 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         if (parts.length === 0) return '[' + String(obj) + ']';
         return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
     }
-    if (typeof obj === 'object' && typeof obj.inspect === 'function') {
-        return obj.inspect();
+    if (typeof obj === 'object') {
+        if (inspectSymbol && typeof obj[inspectSymbol] === 'function') {
+            return obj[inspectSymbol]();
+        } else if (typeof obj.inspect === 'function') {
+            return obj.inspect();
+        }
     }
     if (isMap(obj)) {
         var parts = [];
@@ -96,7 +108,7 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
         return collectionOf('Set', setSize.call(obj), parts);
     }
     if (isNumber(obj)) {
-        return markBoxed(Number(obj));
+        return markBoxed(inspect(Number(obj)));
     }
     if (isBoolean(obj)) {
         return markBoxed(booleanValueOf.call(obj));
@@ -112,6 +124,11 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
     return String(obj);
 };
 
+function wrapQuotes (s, defaultStyle, opts) {
+    var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
+    return quoteChar + s + quoteChar;
+}
+
 function quote (s) {
     return String(s).replace(/"/g, '"');
 }
@@ -190,9 +207,9 @@ function isElement (x) {
     ;
 }
 
-function inspectString (str) {
+function inspectString (str, opts) {
     var s = str.replace(/(['\\])/g, '\\$1').replace(/[\x00-\x1f]/g, lowbyte);
-    return "'" + s + "'";
+    return wrapQuotes(s, 'single', opts);
 }
 
 function lowbyte (c) {
diff --git a/package.json b/package.json
index fadef0c..5f2a46e 100644
--- a/package.json
+++ b/package.json
@@ -1,16 +1,18 @@
 {
   "name": "object-inspect",
-  "version": "1.3.0",
+  "version": "1.5.0",
   "description": "string representations of objects in node and the browser",
   "main": "index.js",
   "devDependencies": {
-    "core-js": "^2.4.1",
-    "tape": "^4.7.0"
+    "core-js": "^2.5.1",
+    "nyc": "^10.3.2",
+    "tape": "^4.8.0"
   },
   "scripts": {
     "test": "npm run tests-only",
     "pretests-only": "node test-core-js",
-    "tests-only": "tape test/*.js"
+    "tests-only": "tape test/*.js",
+    "coverage": "nyc npm run tests-only"
   },
   "testling": {
     "files": [
@@ -45,5 +47,8 @@
     "email": "mail at substack.net",
     "url": "http://substack.net"
   },
-  "license": "MIT"
+  "license": "MIT",
+  "browser": {
+    "./util.inspect.js": false
+  }
 }
diff --git a/readme.markdown b/readme.markdown
index 41959a4..744eeb5 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -43,8 +43,10 @@ var inspect = require('object-inspect')
 
 ## var s = inspect(obj, opts={})
 
-Return a string `s` with the string representation of `obj` up to a depth of
-`opts.depth`.
+Return a string `s` with the string representation of `obj` up to a depth of `opts.depth`.
+
+Additional options:
+  - `quoteStyle`: must be "single" or "double", if present
 
 # install
 
diff --git a/test/element.js b/test/element.js
index 66df4b8..a36f465 100644
--- a/test/element.js
+++ b/test/element.js
@@ -2,7 +2,7 @@ var inspect = require('../');
 var test = require('tape');
 
 test('element', function (t) {
-    t.plan(1);
+    t.plan(3);
     var elem = {
         nodeName: 'div',
         attributes: [ { name: 'class', value: 'row' } ],
@@ -11,6 +11,8 @@ test('element', function (t) {
     };
     var obj = [ 1, elem, 3 ];
     t.deepEqual(inspect(obj), '[ 1, <div class="row"></div>, 3 ]');
+    t.deepEqual(inspect(obj, { quoteStyle: 'single' }), "[ 1, <div class='row'></div>, 3 ]");
+    t.deepEqual(inspect(obj, { quoteStyle: 'double' }), '[ 1, <div class="row"></div>, 3 ]');
 });
     
 test('element no attr', function (t) {
diff --git a/test/fn.js b/test/fn.js
index be166ff..c7d5712 100644
--- a/test/fn.js
+++ b/test/fn.js
@@ -16,3 +16,13 @@ test('function name', function (t) {
     var obj = [ 1, 2, f, 4 ];
     t.equal(inspect(obj), '[ 1, 2, [Function: xxx], 4 ]');
 });
+
+test('anon function', function (t) {
+    var f = (function () {
+      return function () {};
+    }());
+    var obj = [ 1, 2, f, 4 ];
+    t.equal(inspect(obj), '[ 1, 2, [Function], 4 ]');
+
+    t.end();
+});
diff --git a/test/number.js b/test/number.js
index e5377ac..448304e 100644
--- a/test/number.js
+++ b/test/number.js
@@ -2,7 +2,11 @@ var inspect = require('../');
 var test = require('tape');
 
 test('negative zero', function (t) {
-    t.equal(inspect(0), '0');
-    t.equal(inspect(-0), '-0');
+    t.equal(inspect(0), '0', 'inspect(0) === "0"');
+    t.equal(inspect(Object(0)), 'Object(0)', 'inspect(Object(0)) === "Object(0)"');
+
+    t.equal(inspect(-0), '-0', 'inspect(-0) === "-0"');
+    t.equal(inspect(Object(-0)), 'Object(-0)', 'inspect(Object(-0)) === "Object(-0)"');
+
     t.end();
 });
diff --git a/test/quoteStyle.js b/test/quoteStyle.js
new file mode 100644
index 0000000..ae4d734
--- /dev/null
+++ b/test/quoteStyle.js
@@ -0,0 +1,17 @@
+'use strict';
+
+var inspect = require('../');
+var test = require('tape');
+
+test('quoteStyle option', function (t) {
+    t['throws'](function () { inspect(null, { quoteStyle: false }); }, 'false is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: true }); }, 'true is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: '' }); }, '"" is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: {} }); }, '{} is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: [] }); }, '[] is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: 42 }); }, '42 is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: NaN }); }, 'NaN is not a valid value');
+    t['throws'](function () { inspect(null, { quoteStyle: function () {} }); }, 'a function is not a valid value');
+
+    t.end();
+});
diff --git a/test/values.js b/test/values.js
index 1fcd998..3e1954b 100644
--- a/test/values.js
+++ b/test/values.js
@@ -107,7 +107,11 @@ test('Strings', function (t) {
     var str = 'abc';
 
     t.equal(inspect(str), "'" + str + "'", 'primitive string shows as such');
+    t.equal(inspect(str, { quoteStyle: 'single' }), "'" + str + "'", 'primitive string shows as such, single quoted');
+    t.equal(inspect(str, { quoteStyle: 'double' }), '"' + str + '"', 'primitive string shows as such, double quoted');
     t.equal(inspect(Object(str)), 'Object(' + inspect(str) + ')', 'String object shows as such');
+    t.equal(inspect(Object(str), { quoteStyle: 'single' }), 'Object(' + inspect(str, { quoteStyle: 'single' }) + ')', 'String object shows as such, single quoted');
+    t.equal(inspect(Object(str), { quoteStyle: 'double' }), 'Object(' + inspect(str, { quoteStyle: 'double' }) + ')', 'String object shows as such, double quoted');
 
     t.end();
 });
diff --git a/util.inspect.js b/util.inspect.js
new file mode 100644
index 0000000..7784fab
--- /dev/null
+++ b/util.inspect.js
@@ -0,0 +1 @@
+module.exports = require('util').inspect;

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