From 678f2c261a0a09af679d93783e19819a8327baf4 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 15 Mar 2018 13:45:43 +0100 Subject: [PATCH] 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 Reviewed-By: James M Snell --- doc/api/util.md | 19 +++++++++++++++++++ lib/util.js | 33 ++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/doc/api/util.md b/doc/api/util.md index effe5074d2be89..23a1774a1fa6bf 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -254,6 +254,24 @@ intended as a debugging tool. Some input values can have a significant performance overhead that can block the event loop. Use this function with care and never in a hot code path. +## util.formatWithOptions(inspectOptions, format[, ...args]) + + +* `inspectOptions` {Object} +* `format` {string} + +This function is identical to [`util.format()`][], except in that it takes +an `inspectOptions` argument which specifies options that are passed along to +[`util.inspect()`][]. + +```js +util.formatWithOptions({ colors: true }, 'See object %O', { foo: 42 }); + // Returns 'See object { foo: 42 }', where `42` is colored as a number + // when printed to a terminal. +``` + ## util.getSystemErrorName(err)