1 An ini format parser and serializer for node.
3 Sections are treated as nested objects. Items before the first
4 heading are saved on the object directly.
8 Consider an ini-file `config.ini` that looks like this:
10 ; this comment is being ignored
16 database = use_this_database
19 datadir = /var/lib/data
21 array[] = second value
24 You can read, manipulate and write the ini-file like so:
26 var fs = require('fs')
27 , ini = require('ini')
29 var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
31 config.scope = 'local'
32 config.database.database = 'use_another_database'
33 config.paths.default.tmpdir = '/tmp'
34 delete config.paths.default.datadir
35 config.paths.default.array.push('fourth value')
37 fs.writeFileSync('./config_modified.ini', ini.stringify(config, { section: 'section' }))
39 This will result in a file called `config_modified.ini` being written
40 to the filesystem with the following content:
47 database=use_another_database
48 [section.paths.default]
60 Decode the ini-style formatted `inistring` into a nested object.
64 Alias for `decode(inistring)`
66 ### encode(object, [options])
68 Encode the object `object` into an ini-style formatted string. If the
69 optional parameter `section` is given, then all top-level properties
70 of the object are put into this section and the `section`-string is
71 prepended to all sub-sections, see the usage example above.
73 The `options` object may contain the following:
75 * `section` A string which will be the first `section` in the encoded
76 ini data. Defaults to none.
77 * `whitespace` Boolean to specify whether to put whitespace around the
78 `=` character. By default, whitespace is omitted, to be friendly to
79 some persnickety old parsers that don't tolerate it well. But some
80 find that it's more human-readable and pretty with the whitespace.
82 For backwards compatibility reasons, if a `string` options is passed
83 in, then it is assumed to be the `section` value.
85 ### stringify(object, [options])
87 Alias for `encode(object, [options])`
91 Escapes the string `val` such that it is safe to be used as a key or
92 value in an ini-file. Basically escapes quotes. For example
94 ini.safe('"unsafe string"')
102 Unescapes the string `val`