The utils module¶
This module provides simple helper functions, some of them being very specific to CasperJS though.
Functions reference¶
Usage is pretty much straightforward:
var utils = require('utils');
utils.dump({plop: 42});
betterTypeOf()¶
Signature: betterTypeOf(input)
Provides a better typeof operator equivalent, eg. able to retrieve the Array type.
betterInstanceOf()¶
New in version 1.1.
Signature: betterInstanceOf(input, constructor)
Provides a better instanceof operator equivalent, is able to retrieve the Array instance or to deal with inheritance.
dump()¶
Signature: dump(value)
Dumps a JSON representation of passed argument to the standard output. Useful for debugging your scripts.
fillBlanks()¶
Signature: fillBlanks(text, pad)
Fills a string with trailing spaces to match pad length.
format()¶
Signature: format(f)
Formats a string against passed args. sprintf equivalent.
Note
This is a port of nodejs util.format().
getPropertyPath()¶
Signature: getPropertyPath(Object obj, String path)
New in version 1.0.
Retrieves the value of an Object foreign property using a dot-separated path string:
var account = {
username: 'chuck',
skills: {
kick: {
roundhouse: true
}
}
}
utils.getPropertyPath(account, 'skills.kick.roundhouse'); // true
Warning
This function doesn’t handle object key names containing a dot.
inherits()¶
Signature: inherits(ctor, superCtor)
Makes a constructor inheriting from another. Useful for subclassing and extending.
Note
This is a port of nodejs util.inherits().
isCasperObject()¶
Signature: isCasperObject(value)
Checks if passed argument is an instance of Casper.
isJsFile()¶
Signature: isJsFile(file)
Checks if passed filename is a Javascript one (by checking if it has a .js or .coffee file extension).
isType()¶
Signature: isType(what, type)
Checks if passed argument has its type matching the type argument.
isWebPage()¶
Signature: isWebPage(what)
Checks if passed argument is an instance of native PhantomJS’ WebPage object.
mergeObjects()¶
Signature: mergeObjects(origin, add[, Object opts])
Merges two objects recursively.
Add opts.keepReferences if cloning of internal objects is not needed.
node()¶
Signature: node(name, attributes)
Creates an (HT|X)ML element, having optional attributes added.
