Parser and serializer for Mozilla Firefox and Thunderbird preference files written in Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
testdata
LICENSE
README.md
doc.go
generate.go
parser.go
parser.rl
parser_test.go
prefs.go
prefs_test.go
roundtrip_test.go
unquote.go
write.go
write_test.go

README.md

go-mozpref

GoDoc

go-mozpref is a Go library for reading and writing preference files as used by Mozilla Firefox and Thunderbird. The parser consists of a Ragel-generated state machine.

Usage

import mozpref "github.com/hansmi/go-mozpref"

Preferences can be read from any io.Reader:

file, err := os.Open("prefs.js")
if err != nil {
	// Handle error
}

prefs, err := mozpref.ReadFrom(file)
if err != nil {
	// Handle error
}

for name, p := range prefs {
	fmt.Printf("%s = %s\n", name, p.Value)
}

Writing works likewise with any io.Writer:

prefs := mozpref.PrefMap{
	"example": mozpref.Pref{
		Value: true,
		Flags: mozpref.Locked,
	},
}

_, err := prefs.WriteTo(os.Stdout)
if err != nil {
	// Handle error
}

Preferences can be marked as locked or sticky:

prefs["example"].Flags |= mozpref.Sticky
prefs["other"] = &mozpref.Pref{
	Value: "Hello World",
	Flags: mozpref.Locked | mozpref.Sticky,
}

Entries suitable for user.js files can be written using the mozpref.UserPref flag.

Versioning

go-mozpref follows semver.

License

This library is distributed under the BSD-style license found in the LICENSE file.