API-Version: 1.9

util

Utility functions

Source:

Methods

<static> base64Decode(string) → {String}

Decodes a base64 string to a string

Parameters:
Name Type Description
string String

The string to decode

Source:
Returns:

The decoded string

Type
String

<static> base64Encode(string) → {String}

Encodes a string to base64

Parameters:
Name Type Description
string String

The string to encode

Source:
Returns:

The base64-representation of the string

Type
String

<static> camelize(text) → {String}

Converts a non-camel-case string to a camel-case string

Parameters:
Name Type Description
text String

The text to camelize

Source:
Returns:

A camelcase String

Type
String
Example
 
util.camelize("foo-bar-baz"); // "fooBarBaz"

<static> caretMode()

Shorthand for util.changeMode(Modes.CaretMode)

Source:

<static> changeMode(mode)

Change the mode, changeable modes are Modes.NormalMode, Modes.InsertMode and Modes.CaretMode

Parameters:
Name Type Description
mode Modes

The new mode

Source:

<static> checksum(data, type) → {Boolean}

Computes a checksum of a string

Parameters:
Name Type Argument Description
data String

The data

type ChecksumType <optional>

The ChecksumType, defaults to sha256

Source:
Returns:

Whether the shortcut was unbound

Type
Boolean

<static> clone(object) → {Object}

Clones an object, object with circular references are not supported.

Parameters:
Name Type Description
object Object

The object to clone

Source:
Returns:

A copy of the object

Type
Object

<static> decodeUTF8(string) → {String}

Decode a string to UTF8

Parameters:
Name Type Description
string String

The string to decode

Source:
Returns:

The decoded string

Type
String

<static> dispatchEvent(event) → {Boolean}

Dispatches a keyboard or button event

Parameters:
Name Type Description
event Object

Event details, see buttonPress, buttonRelease, keyPress or keyRelease for details.

Properties
Name Type Description
type Number

Type of the event, can be either buttonpress (4), doubleclick (5), tripleclick (6), buttonrelease (7), keypress (8) or keyrelease (9).

Source:
Returns:

Whether the event was dispatched

Type
Boolean

<static> encodeUTF8(string) → {String}

Encodes a UTF8 string

Parameters:
Name Type Description
string String

The string to encode

Source:
Returns:

The encoded string

Type
String

<static> getBody(function) → {String}

Gets the body of a function, useful for injecting scripts

Parameters:
Name Type Description
function Function

A function

Source:
Returns:

The body of the function

Type
String

<static> getMode() → {Enums and Flags.Modes}

Gets the current mode

Source:
Returns:

The current mode

Type
Enums and Flags.Modes

<static> getSelection() → {String}

Get the selected text in a webview

Source:
Returns:

The selected text or null if no text was selected

Type
String

<static> hereDoc(doc) → {String}

Function that creates a multiline string

Parameters:
Name Type Description
doc Function

A function, the body of the function must contain the here document. The content must be wrapped in /*HEREDOC ...HEREDOC*/

Source:
Returns:

The here document.

Type
String
Example
 
function myDocument() {
/*HEREDOC 
    <body>
        <input>
        </input>
    </body>
HEREDOC*/
}

tabs.current.loadString(util.hereDoc(myDocument));

<static> insertMode()

Shorthand for util.changeMode(Modes.InsertMode)

Source:

<static> markupEscape(text) → {String}

Escapes text for usage with pango markup

Parameters:
Name Type Description
text String

The text to escape

Source:
Returns:

The escaped text or null

Type
String

<static> mixin(self, varargs) → {Object}

Mixes properties of objects into an object. Properties are mixed in from left to right, so properties will not be overwritten in the leftmost object if they are already defined.

Parameters:
Name Type Description
self Object

The object to mixin the properties

varargs Object

Variable number of objects to mix in.

Source:
Returns:

self or a new object if self is null or undefined.

Type
Object
Example
 
var a = { a : 1, b : 2, c : 3 };
var b = { b : 1, d : 2, e : 3 };
var c = { e : 1, f : 2, g : 3 };

a = util.mixin(a, b, c); // a = { a : 1, b : 2, c : 3, d : 2, e : 3, f : 2, g : 3}

<static> normalMode()

Shorthand for util.changeMode(Modes.NormalMode)

Source:

<static> pathComplete(callback, label, initialPath, dirOnly)

Initializes filename completion.

Parameters:
Name Type Argument Description
callback util~onPathComplete

Callback function called when a path was chosen or escape was pressed

label String <optional>

The command line label

initialPath String <optional>

The initial path, defaults to the current working directory

dirOnly Boolean <optional>

Whether to complete only directories, default false.

Since:
  • 1.3
Source:

Searches for a string in the current or a new tab using dwb's searchengines

Parameters:
Name Type Argument Description
keyword String

The search keyword

searchString String

The string to search for

newTab Boolean <optional>

Whether to open the result in a new tab, default false

Source:

<static> tabComplete(label, items[], callback, readonly)

Initializes tab completion.

Parameters:
Name Type Argument Description
label String

The command line label

items[] Array[Object]

An array of labels,

Properties
Name Type Description
left String

Left completion label

right String

Right completion label

callback util~onTabComplete

Callback function, the first argument will be the returned string from the url bar.

readonly Boolean <optional>

Whether the items are readonly, default false

Source:

<static> uncamelize(text) → {String}

Converts camel-case string for usage with GObject properties to a non-camel-case String

Parameters:
Name Type Description
text String

The text to uncamelize

Source:
Returns:

The uncamelized String

Type
String
Example
 
util.uncamelize("fooBarBaz"); // "foo-bar-baz"

Type Definitions

onPathComplete(path)

Callback that will be called when Return or Escape was pressed after util.pathComplete was invoked.

Parameters:
Name Type Description
path String

The path or null if Escape was pressed.

Since:
  • 1.3
Source:

onTabComplete(text)

Callback that will be called when Return was pressed after util.tabComplete was invoked.

Parameters:
Name Type Description
text String

Text from the textentry.

Source: