diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-10-17 08:45:30 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-10-17 08:45:30 +0400 |
commit | e15ab15a27a8f14cf0d9dc6f11dee452080378a0 (patch) | |
tree | b880e42980a9685deac561077ac6c35d79abd9ba /node_modules/ini/ini.js | |
parent | 7610f3e62e699292ece081bfd33084d436e3246d (diff) |
ini@1.3.0
Tighten up whitespace handling.
Diffstat (limited to 'node_modules/ini/ini.js')
-rw-r--r-- | node_modules/ini/ini.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/node_modules/ini/ini.js b/node_modules/ini/ini.js index f5e444118..1e232e743 100644 --- a/node_modules/ini/ini.js +++ b/node_modules/ini/ini.js @@ -7,31 +7,47 @@ exports.unsafe = unsafe var eol = process.platform === "win32" ? "\r\n" : "\n" -function encode (obj, section) { +function encode (obj, opt) { var children = [] , out = "" + if (typeof opt === "string") { + opt = { + section: opt, + whitespace: false + } + } else { + opt = opt || {} + opt.whitespace = opt.whitespace === true + } + + var separator = opt.whitespace ? " = " : "=" + Object.keys(obj).forEach(function (k, _, __) { var val = obj[k] if (val && Array.isArray(val)) { val.forEach(function(item) { - out += safe(k + "[]") + "=" + safe(item) + "\n" + out += safe(k + "[]") + separator + safe(item) + "\n" }) } else if (val && typeof val === "object") { children.push(k) } else { - out += safe(k) + "=" + safe(val) + eol + out += safe(k) + separator + safe(val) + eol } }) - if (section && out.length) { - out = "[" + safe(section) + "]" + eol + out + if (opt.section && out.length) { + out = "[" + safe(opt.section) + "]" + eol + out } children.forEach(function (k, _, __) { var nk = dotSplit(k).join('\\.') - var child = encode(obj[k], (section ? section + "." : "") + nk) + var section = (opt.section ? opt.section + "." : "") + nk + var child = encode(obj[k], { + section: section, + whitespace: opt.whitespace + }) if (out.length && child.length) { out += eol } |