# util

> A Node.js-compatible implementation of the core `util` module

- Source: https://titaniumsdk.com/docs/sdk/13.0.1/util
- Titanium SDK version: 13.0.1
- Kind: pseudo
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 8.1.0

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](https://nodejs.org/api/util.html)

## Properties

### types

- Type: util.types
- Platforms: Android, iPhone, iPad, macOS

`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

### callbackify

- Platforms: Android, iPhone, iPad, macOS

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:

- `original` (Function): An `async` function

Returns: Function - a callback style function

### debug

- Platforms: Android, iPhone, iPad, macOS

Alias for `util.debuglog`. Usage allows for readability of that doesn't imply logging when only using `util.debuglog().enabled`.

Parameters:

- `section` (String): A string identifying the portion of the application for which the `debuglog` function is being created.
- `callback` (Function, optional): A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.

Returns: Function - The logging function

### debuglog

- Platforms: Android, iPhone, iPad, macOS

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:

- `section` (String): A string identifying the portion of the application for which the `debuglog` function is being created.
- `callback` (Function, optional): A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.

Returns: Function - The logging function

### deprecate

- Platforms: Android, iPhone, iPad, macOS

The `util.deprecate()` method wraps fn (which may be a function or class) in such a way that it is marked as deprecated.

Parameters:

- `fn` (Function): The function that is being deprecated.
- `msg` (String): A warning message to display when the deprecated function is invoked.
- `code` (String, optional): A deprecation code. **NOTE:** Titanium currently ignores this argument.

Returns: Function - The deprecated function wrapped to emit a warning.

### format

- Platforms: Android, iPhone, iPad, macOS

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:

- `format` (String): A `printf`-like format string.
- `args` (any, optional, repeatable): variable arguments to inject into the formatted string

### formatWithOptions

- Platforms: Android, iPhone, iPad, macOS

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:

- `inspectOptions` (UtilInspectOptions): Options passed along to [util.inspect](https://titaniumsdk.com/docs/sdk/util.md#inspect)`()`
- `format` (String): A `printf`-like format string.

### inherits

- Platforms: Android, iPhone, iPad, macOS

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:

- `constructor` (Function): constructor function for "subclass"
- `superConstructor` (Function): constructor function for "super class"

### inspect

- Platforms: Android, iPhone, iPad, macOS

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:

- `object` (any): Any JavaScript primitive or Object.
- `options` (UtilInspectOptions, optional): Additional options to modify the output of the inspect function

Returns: String

### isArray

- Platforms: Android, iPhone, iPad, macOS

Alias for `Array.isArray()`.

Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isBoolean

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isBuffer

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isDate

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isError

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is an `Error`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isFunction

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Function`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isNull

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is strictly `null`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isNullOrUndefined

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is `null` or `undefined`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isNumber

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isObject

- Platforms: Android, iPhone, iPad, macOS

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:

- `object` (any): any value

Returns: Boolean

### isPrimitive

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a primitive type. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isRegExp

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isString

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isSymbol

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### isUndefined

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.

Parameters:

- `object` (any): any value

Returns: Boolean

### log

- Platforms: Android, iPhone, iPad, macOS

The `util.log()` method prints the given `string` to `stdout` with an included timestamp.

Parameters:

- `string` (String): string to print

### promisify

- Platforms: Android, iPhone, iPad, macOS

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:

- `original` (Function): A typical Node.js style callback function

Returns: Function - a function that returns a `Promise`

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

