aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-03-15 13:45:43 +0100
committerAnna Henningsen <anna@addaleax.net>2018-04-12 23:23:53 +0200
commit681c1d2f2c76540b114e868f601782c16bf6a493 (patch)
treed616b0d6a823660e073b564e5bcb49f2607f810d /lib
parent039cdebe81e232cae23acdfd8392a8149b718460 (diff)
downloadandroid-node-v8-681c1d2f2c76540b114e868f601782c16bf6a493.tar.gz
android-node-v8-681c1d2f2c76540b114e868f601782c16bf6a493.tar.bz2
android-node-v8-681c1d2f2c76540b114e868f601782c16bf6a493.zip
util: introduce `formatWithOptions()`
Identical to `format()` except that it takes an options argument that is passed through to `inspect()`. PR-URL: https://github.com/nodejs/node/pull/19372 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/util.js33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/util.js b/lib/util.js
index 003d2dfa68..0483e4e067 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -173,23 +173,28 @@ function tryStringify(arg) {
}
}
-function format(f) {
+const emptyOptions = {};
+function format(...args) {
+ return formatWithOptions(emptyOptions, ...args);
+}
+
+function formatWithOptions(inspectOptions, f) {
let i, tempStr;
if (typeof f !== 'string') {
- if (arguments.length === 0) return '';
+ if (arguments.length === 1) return '';
let res = '';
- for (i = 0; i < arguments.length - 1; i++) {
- res += inspect(arguments[i]);
+ for (i = 1; i < arguments.length - 1; i++) {
+ res += inspect(arguments[i], inspectOptions);
res += ' ';
}
- res += inspect(arguments[i]);
+ res += inspect(arguments[i], inspectOptions);
return res;
}
- if (arguments.length === 1) return f;
+ if (arguments.length === 2) return f;
let str = '';
- let a = 1;
+ let a = 2;
let lastPos = 0;
for (i = 0; i < f.length - 1; i++) {
if (f.charCodeAt(i) === 37) { // '%'
@@ -206,12 +211,17 @@ function format(f) {
tempStr = `${Number(arguments[a++])}`;
break;
case 79: // 'O'
- tempStr = inspect(arguments[a++]);
+ tempStr = inspect(arguments[a++], inspectOptions);
break;
case 111: // 'o'
- tempStr = inspect(arguments[a++],
- { showHidden: true, showProxy: true });
+ {
+ const opts = Object.assign({}, inspectOptions, {
+ showHidden: true,
+ showProxy: true
+ });
+ tempStr = inspect(arguments[a++], opts);
break;
+ }
case 105: // 'i'
tempStr = `${parseInt(arguments[a++])}`;
break;
@@ -244,7 +254,7 @@ function format(f) {
if ((typeof x !== 'object' && typeof x !== 'symbol') || x === null) {
str += ` ${x}`;
} else {
- str += ` ${inspect(x)}`;
+ str += ` ${inspect(x, inspectOptions)}`;
}
}
return str;
@@ -1206,6 +1216,7 @@ module.exports = exports = {
debuglog,
deprecate,
format,
+ formatWithOptions,
getSystemErrorName,
inherits,
inspect,