Skip to content

Commit ccc87eb

Browse files
committed
doc: improve documentation for util.deprecate()
Improve documentation for `util.deprecate()`. In particular, provide complete function signature, document arguments, and document return value. PR-URL: #16393 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 60698c2 commit ccc87eb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

doc/api/util.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,20 @@ environment variable set, then it will not print anything.
107107
Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`
108108
environment variable. For example: `NODE_DEBUG=fs,net,tls`.
109109

110-
## util.deprecate(function, string)
110+
## util.deprecate(fn, msg[, code])
111111
<!-- YAML
112112
added: v0.8.0
113113
-->
114114

115-
The `util.deprecate()` method wraps the given `function` or class in such a way that
116-
it is marked as deprecated.
115+
* `fn` {Function} The function that is being deprecated.
116+
* `msg` {string} A warning message to display when the deprecated function is
117+
invoked.
118+
* `code` {string} A deprecation code. See the [list of deprecated APIs][] for a
119+
list of codes.
120+
* Returns: {Function} The deprecated function wrapped to emit a warning.
121+
122+
The `util.deprecate()` method wraps `fn` (which may be a function or class) in
123+
such a way that it is marked as deprecated.
117124

118125
<!-- eslint-disable prefer-rest-params -->
119126
```js
@@ -127,10 +134,9 @@ exports.puts = util.deprecate(function() {
127134
```
128135

129136
When called, `util.deprecate()` will return a function that will emit a
130-
`DeprecationWarning` using the `process.on('warning')` event. By default,
131-
this warning will be emitted and printed to `stderr` exactly once, the first
132-
time it is called. After the warning is emitted, the wrapped `function`
133-
is called.
137+
`DeprecationWarning` using the `process.on('warning')` event. The warning will
138+
be emitted and printed to `stderr` exactly once, the first time it is called.
139+
After the warning is emitted, the wrapped function is called.
134140

135141
If either the `--no-deprecation` or `--no-warnings` command line flags are
136142
used, or if the `process.noDeprecation` property is set to `true` *prior* to
@@ -1213,4 +1219,5 @@ Deprecated predecessor of `console.log`.
12131219
[Internationalization]: intl.html
12141220
[WHATWG Encoding Standard]: https://encoding.spec.whatwg.org/
12151221
[constructor]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/constructor
1222+
[list of deprecated APIS]: deprecations.html#deprecations_list_of_deprecated_apis
12161223
[semantically incompatible]: https://github.com/nodejs/node/issues/4179

0 commit comments

Comments
 (0)