preferences-service

The preferences-service module provides access to the application-wide preferences service singleton.

API Reference

Functions

set(name, value)

Sets the application preference name to value.

name : string

Preference name.

value : string,number,bool

Preference value.

Example:

var name = "extensions.checkCompatibility.nightly";
require("preferences-service").set(name, false);

get(name, defaultValue)

Gets the application preference name.

name : string
defaultValue : string,number,bool

Preference value.

Returns: string,number,bool

Preference value, returns a default value if no preference is set.

Example:

var name = "extensions.checkCompatibility.nightly";
var nightlyCompatChk = require("preferences-service").get(name);

has(name)

name : string

Preference name.

Returns: bool

Returns whether or not the application preference name exists.

Example:

var name = "extensions.checkCompatibility.nightly";
if (require("preferences-service").has(name)) {
  // ...
}

keys(root)

root : string

Preference root name.

Returns: array

Returns an array of strings representing the child preferences of the root of this branch.

isSet(name)

name : string

Preference name.

Returns: bool

Returns whether or not the application preference name both exists and has been set to a non-default value by the user (or a program acting on the user's behalf).

Example:

var name = "extensions.checkCompatibility.nightly";
if (require("preferences-service").isSet(name)) {
  // ...
}

reset(name)

Clears a non-default, user-set value from the application preference name. If no user-set value is defined on name, the function does nothing. If no default value exists the preference will cease to exist.

name : string

Preference name.

Example:

var name = "extensions.checkCompatibility.nightly";
require("preferences-service").reset(name);

getLocalized(name, defaultValue)

Gets the localized value for an application preference name.

name : string
defaultValue : string

Preference value.

Returns: string

Localized preference value, returns a default value if no preference is set. Some preferences refer to a properties file. So that prefs.get returns the properties file URL whereas prefs.getLocalized returns the value defined in the properties file.

Example:

var prefs = require("preferences-service");
var name = "general.useragent.locale";
prefs.get(name); // is equal to "chrome://global/locale/intl.properties"
prefs.getLocalized(name) // is equal to "en-US"

setLocalized(name, value)

Sets the localized application preference name to value.

name : string

Preference name.

value : string

Preference value, a URL to a properties file

Example:

require("preferences-service").set("general.useragent.locale",
                                   "chrome://global/locale/intl.properties");