GLOBAL INDEX  |  FRAMES  |  NO FRAMES
Library: utilities
Overview
A collection of miscellaneous utilities.
source: utilities.js
Constructors
StringSet(initialString1, initialString2, etc)
Constructor for an object that holds a set of strings, with basic set operations. This is better for keeping track of a set than using an associative arrays, because it avoids key collisions with javascript built-ins like 'toString', 'class', etc.
parameters
string initialString1
string initialString2
string etc ...
methods
HttpRequestError(message, info)
The error thrown by wget and wpost if there's a problem retrieveing the requested URL.
parameters
string message A status message describing why the action failed.
HttpResponse info Additional info, including headers and received data, if any.
HttpResponse()
Description of an object containing the properties of the HTTP response returned by wget and wpost
properties
Functions
md5(x)
Returns a string version of the MD5 signature of x.
parameters
String x a string
returns
String the md5 hash of x
examples
print(md5("appjet")); // prints "9b458805f67473b49761c13e48c5de35"
eachProperty(obj, func)
Iterator convenience for JavaScript Objects. Note that if func returns false, the iteration will be immediately terminated. (Returning undefined, or not specifying a return type, does not terminate the iteration).
parameters
object obj The object over which to iterate.
function func The function to run on each [key,value] pair.
examples
var pastels = {
  red: "#fcc",
  green: "#cfc",
  blue: "#ccf"
};
eachProperty(pastels, function(key, value) {
  print(DIV({style: 'background: '+value+';'}, key));
});
object(parent)
Douglas Crockford's "object" function for prototypal inheritance, taken from http://javascript.crockford.com/prototypal.html
parameters
object parent The parent object.
returns
object A new object whose prototype is parent.
keys(obj)
Creates an array of the properties of obj, not including built-in or inherited properties. If no argument is given, applies to the global object.
parameters
object obj
examples
// Prints "abc"
keys({a: 1, b: 2, c: 3}).forEach(function(k) {
  print(k);
}
// Prints all the functions and object members of the global "appjet" object,
// one per line.
print(keys(appjet).join('\n'));
cmp(a, b)
Comparator that returns -1, +1, or 0 depending on whether ab, or neither, respectively.
parameters
object a
object b
returns
number -1, 0, or +1
trim(str)
Removes leading and trailing whitespace from a string.
parameters
string str
returns
string The trimmed string.
StringSet.contains(x)
Returns whether this set contains the given string.
parameters
string x
returns
boolean Whether x exits in this set.
StringSet.add(x)
Adds the given string to the set if it is not already in it.
parameters
string x
StringSet.remove(x)
Removes the given string from the set if it is contained in it.
parameters
string x The string to remove from the set.
StringSet.forEach(f)
Iterators over the strings in the set, calling the provided function on each element.
parameters
function f The function to call on each string in the set.
wget(url, params, options)
Fetches the text of a URL and returns it as a string.
parameters
string url The name of the url to retreive. If the transport is not specified, HTTP is assumed.
object params? Optional parameters to include with the GET, as a dictionary of {name: value} entries.
object options? Optional object with three optional properties:
  • headers: HTTP request headers to send with the GET, as a dictionary of {name: value} entries.
  • followRedirects: A boolean indicating whether to follow redirect headers returned by the server. Defaults to true.
  • complete: If true, wget returns an object containing all information about the response, not just its contents. Otherwise, wget throws a HttpRequestError if it encounters an error GETing.
returns
string The full text of the url's content.
HttpResponse The "complete" response, returned if the "complete" parameter is true.
examples
g = wget("google.com");
page.setMode("plain");
print(raw(g));
wpost(url, params, options)
Simple way to POST data to a URL and get back the response. Values of params will automatically be escaped.
parameters
string url The url to POST to.
object params? Optional parameters to include with the POST, as a dictionary of {name: value} entries.
object options? Optional object with three optional properties:
  • headers: HTTP request headers to send with the POST, as a dictionary of {name: value} entries.
  • followRedirects: A boolean indicating whether to follow redirect headers returned by the server.
  • complete: If true, wpost returns an object containing all information about the response, not just its contents. Otherwise, wpost throws a HttpRequestError if it encounters an error POSTing.
returns
string The full text returned from the server POSTed to.
HttpResponse The complete response, returned if the "complete" parameter is true.
examples
result = wpost("example.com", {id: 25, value: "here is the post value"});
sendEmail(toAddress, subject, body, headers)
Simple way to send an email to a single recipient. Emails will have a "from" address of noreply@{appjet.appName}.{appjet.mainDomain}. Sending is limited to 100 emails per developer account per day. However, emails sent to the address on file for the app's owner are not counted toward this limit.
parameters
string toAddress The one email address to send a message to.
string subject The message subject.
string body The message body.
object headers? Optional headers to include in the message, as a dictionary of {name: value} entries.
examples
result = sendEmail("noone@example.com", "Test Subject", 
                   "Greetings!", {"Reply-To": "sender@example.com"});
Objects
number
The status code of the server's response, or an internal status code if connecting to the server failed.
string
HttpResponse.statusInfo
An explanation of the status code if it is an internal code (that is, less than 0)
string
The data returned by the server, if any.
string
HttpResponse.contentType
The content type returned by the server, if any.
object
HttpResponse.headers
An object containing property names and values corresponding to the headers returned by the server.
Generated by JsDoc Toolkit 1.3.3 on Sun, 04 May 2008 19:53:43 GMT.