--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
That's what npm uses for the .npmrc file. Very readable, commentable, etc.
--i
var settings = JSON.parse(
fs.readFileSync("./settings.json").toString().replace(
new RegExp("\\/\\*(.|\\r|\\n)*?\\*\\/", "g"),
"" // strip out comments
)
);
It only supports /**/ comments..
This would support both:
fs.readFileSync(blah, "utf8").replace(/\/\*(?:.|\r|\n)*?\*\/|\/\/[^\n]\n/, "")
However, only trivially. This will break it:
{ "block comments": "look /* like this */"
, "line comments" : "look // like this" }
to reliably strip out comments from arbitrary json, you have to
actually walk the string, keeping track of the state (whether you're
in a single-quoted string, a double-quoted string, whether the last
char was a \ escape, etc.) Not rocket surgery, but not a one-liner,
either.
On Mon, Mar 21, 2011 at 10:06, Oleg Slobodskoi <ole...@googlemail.com> wrote:
> - I suppose you has implemented only a part of the ini spec, is there
> actually a real spec?
Nope. Just implementations, as far as I know. And the
implementations are all a little different.
> - json has some more things like arrays, booleans and objects literals which
> can be used as values, not only strings
That's true. The config handling logic deeper in npm interprets
"true", "false", "null", and numbers as their intended values.
> P.S. can you push your parser as new independent module and describe what it
> can?
It's on the todo list to split out the whole config-and-param parsing
logic in npm out into a separate package.
--i
var json = commentedJSON.replace(/\/\/.*|\/\*[\s\S]*?\*\/|("(?:\\[\s\S]|[^"\\])*")|('(?:\\[\s\S]|[^'\\])*')/g, "$1$2");or something
--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.