class BaseError()

An extendable error class that inherits from Error().

Example usage:

var MyError = BaseError.extend(function(self, message) {
    self.name = "MyError";
    self.message = message;

BaseError() copies .extend from Extendable() rather than inheriting it because it inherits from Error() already.

class DeprecationError()

Thrown when deprecated functionality is used.

class Extendable()

A base class for extendable classes.

class Extendable.extend(Child)

Create a sub-class.

  • Child (Class) – The constructor for the child class.

Example usage:

var MyClass = Extendable.extend(function(self, name) {
    self.my_name = name;

var OtherClass = MyClass.extend(function(self, other) {
    self.other_var = other;
basic_auth(username, password)

Return an HTTP Basic authentication header value for the given username and password.

  • username (string) – The username to authenticate as.
  • password (string) – The password to authenticate with.

Return true if v is defined and not null, and false otherwise.

  • v (Object) – The value to check.
format_addr(addr, type)

Format an address as a standardized string.

This function delegates to the formatter format_addr[type] or returns the address unchanged if there is no custom formatter.

  • addr (string) – The address to format.
  • type (string) – The address type for the address.

Canonicalize a Gtalk address by stripping the device-specifier, if any.

  • addr (string) – The Gtalk address to format.

Canonicalize an MSISDN by adding a + prefix if one is not present.

  • addr (string) – The MSISDN to format.

Coerce obj to a function.

If obj is a function, return the function. Otherwise return a constant function that returns obj when called.

  • obj (Object) – The object to coerce.

Return the address type for the given delivery class.

A delivery class is type of system that messages can be sent or received over. Common values are sms, ussd, gtalk, twitter, mxit and wechat.

An address type is a type of address used to identify a user and corresponds to a field on a Contact() object. Common values are msisdn, gtalk_id and twitter_handler, mxit_id and wechat_id.

If the delivery_class isn’t know, the delivery_class itself is returned as the address_type.

  • delivery_class (string) – The delivery class to look up.
The mapping of delivery classes to address types is a low-level
implementation detail that is subject to change. Use higher-level
alternatives where possible.
inherit(Parent, Child)

Inherit the parent’s prototype and mark the child as extending the parent.

  • Parent (Class) – The parent class to inherit and extend from.
  • Child (Class) – The child class that inherits and extends.

Return true if v is of type number and has no fractional part.

  • v (Object) – The value to check.
maybe_call(obj, that, args)

Coerce a function to its result.

If obj is a function, call it with the given arguments and return the result. Otherwise return obj.

  • obj (Object) – The function to call or result to return.
  • that (Object) – The value of this to bind to the function.
  • args (Array) – Arguments to call the function with.
normalize_msisdn(number, country_code)

Normalizes an MSISDN number.

This function will normalize an MSISDN number by removing any invalid characters and adding the country code. It will return null if the given number cannot be normalized.

This function is based on the MSISDN normalize function found within the vumi utils.

  • number (string) – The number to normalize.
  • country_code (string) – (optional) The country code for the number.
starts_with(haystack, needle)

Return true if haystack starts with needle and false otherwise.

  • haystack (string) – The string to search within.
  • needle (string) – The string to look for.

If either parameter is false-like, it is treated as the empty string.


Return a UUID (version 4).


Format a date in Vumi’s date format.

  • date (obj) – A value moment can interpret as a UTC date.