util
A Node.js-compatible implementation of the core util module
Titanium provides a number of shims and ports of core Node.js module functionality.
This module is intended to provide a Node-compatible port of the util core module.
More details on the Node.js API can be found in their util module documentation
Properties 1
util.types provides type checks for different kinds of built-in objects. Unlike instanceof or Object.prototype.toString.call(value), these checks do not inspect properties of the object that are accessible from JavaScript (like their prototype), and usually have the overhead of calling into C++.
The result generally does not make any guarantees about what kinds of properties or behavior a value exposes in JavaScript. They are primarily useful for addon developers who prefer to do type checking in JavaScript.
Methods 25
Takes an async function (or a function that returns a Promise) and returns a function following the error-first callback style, i.e. taking an (err, value) => ... callback as the last argument. In the callback, the first argument will be the rejection reason (or null if the Promise resolved), and the second argument will be the resolved value.
| Parameters | Type | Description |
|---|---|---|
| original | Function | An |
a callback style function
Alias for util.debuglog. Usage allows for readability of that doesn't imply logging when only using util.debuglog().enabled.
| Parameters | Type | Description |
|---|---|---|
| section | String | A string identifying the portion of the application for which the |
| callback? | Function | A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function. |
The logging function
The util.debuglog() method is used to create a function that conditionally writes debug messages to stderr based on the existence of the NODE_DEBUG environment variable. If the section name appears within the value of that environment variable, then the returned function operates similar to console.error(). If not, then the returned function is a no-op.
NOTE: Titanium currently returns a no-op regardless of the NODE_DEBUG environment variable.
| Parameters | Type | Description |
|---|---|---|
| section | String | A string identifying the portion of the application for which the |
| callback? | Function | A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function. |
The logging function
The util.deprecate() method wraps fn (which may be a function or class) in such a way that it is marked as deprecated.
| Parameters | Type | Description |
|---|---|---|
| fn | Function | The function that is being deprecated. |
| msg | String | A warning message to display when the deprecated function is invoked. |
| code? | String | A deprecation code. NOTE: Titanium currently ignores this argument. |
The deprecated function wrapped to emit a warning.
The util.format() method returns a formatted string using the first argument as a printf-like format string which can contain zero or more format specifiers. Each specifier is replaced with the converted value from the corresponding argument.
| Parameters | Type | Description |
|---|---|---|
| format | String | A |
| args? | any | variable arguments to inject into the formatted 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().
| Parameters | Type | Description |
|---|---|---|
| inspectOptions | UtilInspectOptions | Options passed along to util.inspect 11 fields
|
| format | String | A |
Usage of util.inherits() is discouraged. Please use the ES6 class and extends keywords to get language level inheritance support. Also note that the two styles are semantically incompatible.
Inherit the prototype methods from one constructor into another. The prototype of constructor will be set to a new object created from superConstructor.
This mainly adds some input validation on top of Object.setPrototypeOf(constructor.prototype, superConstructor.prototype). As an additional convenience, superConstructor will be accessible through the constructor.super_ property.
| Parameters | Type | Description |
|---|---|---|
| constructor | Function | constructor function for "subclass" |
| superConstructor | Function | constructor function for "super class" |
The util.inspect() method returns a string representation of object that is intended for debugging. The output of util.inspect may change at any time and should not be depended upon programmatically. Additional options may be passed that alter the result. util.inspect() will use the constructor's name and/or @@toStringTag to make an identifiable tag for an inspected value.
| Parameters | Type | Description |
|---|---|---|
| object | any | Any JavaScript primitive or Object. |
| options? | UtilInspectOptions | Additional options to modify the output of the inspect function 11 fields
|
Alias for Array.isArray().
Returns true if the given object is an Array. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Boolean. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Buffer. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Date. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is an Error. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Function. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is strictly null. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is null or undefined. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Number. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is strictly an Object and not a Function (even though functions are objects in JavaScript). Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a primitive type. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a RegExp. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a string. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is a Symbol. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
Returns true if the given object is undefined. Otherwise, returns false.
| Parameters | Type | Description |
|---|---|---|
| object | any | any value |
The util.log() method prints the given string to stdout with an included timestamp.
| Parameters | Type | Description |
|---|---|---|
| string | String | string to print |
Takes a function following the common error-first callback style, i.e. taking an (err, value) => ... callback as the last argument, and returns a version that returns promises.
| Parameters | Type | Description |
|---|---|---|
| original | Function | A typical Node.js style callback function |
a function that returns a Promise