A parser for .properties files written in javascript. Properties files store key-value pairs. They are typically used for configuration and internationalization in Java applications as well as in Actionscript projects. Here's an example of the format:
# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
website = http://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
Wikipedia!
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Unicode
tab : \u0009
(taken from Wikipedia)
Currently works with any version of node.js.
parse(text)
: Parsestext
into key-value pairs. Returns an object containing the key-value pairs.read(path[, callback])
: Opens the file specified bypath
and callsparse
on its content. If the optionalcallback
parameter is provided, the result is then passed to it as the second parameter. If an error occurs, the error object is passed tocallback
as the first parameter. Ifcallback
is not provided, the file specified bypath
is synchronously read and callsparse
on its contents. The resulting object is immediately returned.createEditor([path[, callback]])
: If neitherpath
orcallback
are provided an empty editor object is returned synchronously. If onlypath
is provided, the file specified bypath
is synchronously read and parsed. An editor object with the results in then immediately returned. If bothpath
andcallback
are provided, the file specified bypath
is read and parsed asynchronously. An editor object with the results are then passed tocallback
as the second parameters. If an error occurs, the error object is passed tocallback
as the first parameter.Editor
: The editor object is returned bycreateEditor
. Has the following API:get(key)
: Returns the value currently associated withkey
.set(key, [value[, comment]])
: Associateskey
withvalue
. An optional comment can be provided. Ifvalue
is not specified or isnull
, thenkey
is unset.unset(key)
: Unsets the specifiedkey
.save([path][, callback]])
: Writes the current contents of this editor object to a file specified bypath
. Ifpath
is not provided, then it'll be defaulted to thepath
value passed tocreateEditor
. Thecallback
parameter is called when the file has been written to disk.addHeadComment
: Added a comment to the head of the file.toString
: Returns the string representation of this properties editor object. This string will be written to a file ifsave
is called.
The easiest way to get node-properties-parser is with npm:
npm install properties-parser
Alternatively you can clone this git repository:
git://github.com/xavi-/node-properties-parser.git
- Xavi Ramirez
This project is released under The MIT License.