root 3bf41bf355 update | 1 年之前 | |
---|---|---|
.. | ||
lib | 1 年之前 | |
src | 1 年之前 | |
test | 1 年之前 | |
.babelrc | 1 年之前 | |
.prettierignore | 1 年之前 | |
.prettierrc | 1 年之前 | |
LICENSE | 1 年之前 | |
README.md | 1 年之前 | |
package.json | 1 年之前 |
An ini-file parser which supports multi line, multiple levels and arrays to get a maximum of compatibility with Zend config files.
npm install multi-ini
ini = require('multi-ini');
content = ini.read(file);
content.section.key = value;
ini.write(file, content);
Following options are available:
[section.subsection]
ini = require('multi-ini');
content = ini.read(file, { encoding: 'utf8' });
content.section.key = value;
ini.write(file, content, { encoding: 'utf8' });
This option is by default off to be backward compatible, if you ever need the value containing the quotes then use this.
key="value"
Enabling this option will result in "value" instead of value.
ini = require('multi-ini');
content = ini.read(file, { keep_quotes: true });
This will also affect the Serializer and serialized values. Using it will not quote anything automatically.
{
production: {
quoted: '"quoted"',
not_quoted: 'not_quoted'
}
}
Will result in a ini like
[production]
quoted="quoted"
not_quotes=not_quoted
MultiIni = require('multi-ini');
ini = new MultiIni.Class({
filters: [MultiIni.filters.lowercase],
});
content = ini.read(file);
Replacing constants
MultiIni = require('multi-ini');
ini = new MultiIni.Class({
constants: { CONSTANT: 'replacement' },
filters: [MultiIni.filters.constants],
});
content = ini.read(file);
Define a custom filter
MultiIni = require('multi-ini');
ini = new MultiIni.Class({
filters: [
function (value) {
return 'Prepend ' + value;
},
],
});
content = ini.read(file);
Either unix
or windows
for line breaks.
ini = require('multi-ini');
content = ini.read(file, { line_breaks: 'windows' });
content.section.key = value;
Using nested_section_names
will parse nested section names having a .
.
ini = require('multi-ini');
content = ini.read(file, { nested_section_names: true });
[section.subsection]
key="value"
Will result in
{
"section": {
"subsection": {
"key": "value"
}
}
}
It's also possible to parse a ini file from an array of strings.
ini = require('multi-ini');
parser = new ini.Parser();
content = parser.parse(lines);
Like parsing it's also possible to serialize an ini object to a string.
ini = require('multi-ini');
serializer = new ini.Serializer();
content = serializer.serialize({
production: {
base_url: 'https://google.com',
},
});
constructor
and prototype
__proto__
keep_quotes
ignored when writing filesNow correctly reads
key= example
to the value "example" instead of "** example**"
Implemented support for constants and removed a lot of bugs and the options ignore_invalid and oninvalid, this may be introduced again but are currently not necessary.
Fixed a bug that the module was not recognized as a module by Node.