M
M
Mithgol2011-11-27 19:14:44
JavaScript
Mithgol, 2011-11-27 19:14:44

JavaScript code to parse configuration files (.conf)?

Just as in Windows it is the de facto standard to store settings either in the registry or in ".ini" files that look like

setting1=value
setting2="value1, value2"
setting3=value1,value2
setting4="Some long value."

so in the Linux world, “.conf” files are common, in which the name and value of the setting are separated not by an equal sign, but by a space, and the value may not be quoted, and may also contain a lot of named and unnamed values ​​separated by commas, spaces and God knows what else
Setting1 Value
Setting2 "Long value with spaces."
Setting3 Yet another long value with spaces.
Setting4 Value1, value2
Setting5 -key1=value1 -key2 -key3 "Long parameter" "Another long parameter" -key4 -key5=value2

Is there a ready-made JavaScript parser (for example, for Node.js) that processes the lines of such a configuration file and converts them into arrays and (or) objects?
If it does not exist, then it will not be a particularly great effort to write it; but if it exists, then I would like to know about it, so as not to waste time reinventing bicycles. Tell me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sdevalex, 2011-11-27
@sdevalex

What was wrong with json?

M
mnasyrov, 2011-11-28
@mnasyrov

Try writing your own parser using peg.js . This is a generator of parsers based on PEG grammars , which are similar to regular expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question