The util module provides utilities to the Anchor platform.
$ component install anchorjs/util
$ volo add anchorjs/util
Build a formatted string using the first argument as a printf-like format.
util.format('%s %d', 'hello', 32); // 'hello 32'
util.log('message');
// => 30 Dec 22:34:31 - message
util.debug('message');
// => DEBUG: message
util.error('message');
// => message
util.puts('message');
// => message
Build a string representation of object, which is useful for debugging.
console.log(util.inspect(util, true, null));
Check if an object is of a particular type.
util.isArray([]);
util.isRegExp(/some regexp/);
util.isDate(new Date());
util.isError(new Error());
Inherit the prototype methods from one constructor into another.
function MyStream() {
events.EventEmitter.call(this);
}
util.inherits(MyStream, events.EventEmitter);
This module uses the AMD format. To include in component builds, use component-amd:
component build -u component-amd
This module implements the interface exported by Node's Utilities module.
To run tests in a browser, execute the Make target for the desired browser:
$ make test-chrome
$ make test-firefox
$ make test-safari
Headless tests can be executed directly from a terminal:
$ make test-phantomjs
Copyright (c) 2012-2013 Jared Hanson <http://jaredhanson.net/>
Copyright Joyent, Inc. and other Node contributors.