lib: add options to util.deprecate · nodejs/node@a37c01e · GitHub
Skip to content

Commit a37c01e

Browse files
RafaelGSSaduh95
authored andcommitted
lib: add options to util.deprecate
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: #59982 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9c99ab6 commit a37c01e

3 files changed

Lines changed: 43 additions & 8 deletions

File tree

doc/api/util.md

Lines changed: 9 additions & 1 deletion

lib/util.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const { getOptionValue } = require('internal/options');
8484
const binding = internalBinding('util');
8585

8686
const {
87-
deprecate,
87+
deprecate: internalDeprecate,
8888
getLazy,
8989
getSystemErrorMap,
9090
getSystemErrorName: internalErrorName,
@@ -459,13 +459,18 @@ function getCallSites(frameCount = 10, options) {
459459
return binding.getCallSites(frameCount);
460460
};
461461

462+
// Public util.deprecate API
463+
function deprecate(fn, msg, code, { modifyPrototype } = {}) {
464+
return internalDeprecate(fn, msg, code, undefined, modifyPrototype);
465+
}
466+
462467
// Keep the `exports =` so that various functions can still be monkeypatched
463468
module.exports = {
464469
_errnoException,
465470
_exceptionWithHostPort,
466-
_extend: deprecate(_extend,
467-
'The `util._extend` API is deprecated. Please use Object.assign() instead.',
468-
'DEP0060'),
471+
_extend: internalDeprecate(_extend,
472+
'The `util._extend` API is deprecated. Please use Object.assign() instead.',
473+
'DEP0060'),
469474
callbackify,
470475
debug: debuglog,
471476
debuglog,
@@ -479,9 +484,9 @@ module.exports = {
479484
getSystemErrorMessage,
480485
inherits,
481486
inspect,
482-
isArray: deprecate(ArrayIsArray,
483-
'The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.',
484-
'DEP0044'),
487+
isArray: internalDeprecate(ArrayIsArray,
488+
'The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.',
489+
'DEP0044'),
485490
isDeepStrictEqual(a, b, skipPrototype) {
486491
if (internalDeepEqual === undefined) {
487492
internalDeepEqual = require('internal/util/comparisons').isDeepStrictEqual;

test/parallel/test-util-deprecate.js

Lines changed: 22 additions & 0 deletions

0 commit comments

Comments
 (0)