util
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
inherits | 2.0.4 | 1.98 kB | ISC | prod | |
is-arguments | 1.1.1 | 9.64 kB | MIT | prod | |
is-generator-function | 1.0.10 | 10.21 kB | MIT | prod | |
is-typed-array | 1.1.13 | 7.79 kB | MIT | prod | |
which-typed-array | 1.1.15 | 39.75 kB | MIT | prod |
Util is a Node.js module meant for use across all engines, even ones that don't inherently support it, such as browsers. It's designed to provide an identical API to the Node.js util module, replicating its functionality for broader compatibility. It's built into Node.js and also included with certain browser bundlers like webpack and browserify. Util is a constructive tool that implements several commonly used processes in Node.js like inheritance, formatting, and inspection.
Using util is simple and straight-forward, especially if your code runs in Node.js or you are using browser bundlers like webpack or browserify. If not, you will need to install util with npm first by typing npm install util
in your shell. After util has been integrated into your development environment, require it at the start of your javascript file with var util = require('util')
. Here's a sample usage that demonstrates the functionality of util, in this case, it's used to handle inheritance:
var util = require('util');
var EventEmitter = require('events');
function MyClass() {
EventEmitter.call(this);
}
util.inherits(MyClass, EventEmitter);
Note: Promises must be available to use util.promisify
and util.callbackify
. If you're working with environments like IE11 that do not support Promises, consider using a shim like es6-promise.
The comprehensive documentation for util is maintained on the Node.js website, and can be accessed at https://nodejs.org/docs/latest-v8.x/api/util.html. Due to its nature as a mirror of the original module, any discrepancies or behavioural disparities that are noticed should be reported as issues for resolution. Keep in mind that this adaptation of util is designed to align closely with its Node.js counterpart, and hence, it currently supports the Node 8 LTS API while some of its methods might be outdated.