diff --git a/node_modules/ini/README.md b/node_modules/ini/README.md index acbe8ec895fb5..33df258297db7 100644 --- a/node_modules/ini/README.md +++ b/node_modules/ini/README.md @@ -1,7 +1,7 @@ An ini format parser and serializer for node. -Sections are treated as nested objects. Items before the first heading -are saved on the object directly. +Sections are treated as nested objects. Items before the first +heading are saved on the object directly. ## Usage @@ -34,40 +34,62 @@ You can read, manipulate and write the ini-file like so: delete config.paths.default.datadir config.paths.default.array.push('fourth value') - fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section')) + fs.writeFileSync('./config_modified.ini', ini.stringify(config, { section: 'section' })) -This will result in a file called `config_modified.ini` being written to the filesystem with the following content: +This will result in a file called `config_modified.ini` being written +to the filesystem with the following content: [section] - scope = local + scope=local [section.database] - user = dbuser - password = dbpassword - database = use_another_database + user=dbuser + password=dbpassword + database=use_another_database [section.paths.default] - tmpdir = /tmp - array[] = first value - array[] = second value - array[] = third value - array[] = fourth value + tmpdir=/tmp + array[]=first value + array[]=second value + array[]=third value + array[]=fourth value ## API ### decode(inistring) + Decode the ini-style formatted `inistring` into a nested object. ### parse(inistring) + Alias for `decode(inistring)` -### encode(object, [section]) -Encode the object `object` into an ini-style formatted string. If the optional parameter `section` is given, then all top-level properties of the object are put into this section and the `section`-string is prepended to all sub-sections, see the usage example above. +### encode(object, [options]) -### stringify(object, [section]) -Alias for `encode(object, [section])` +Encode the object `object` into an ini-style formatted string. If the +optional parameter `section` is given, then all top-level properties +of the object are put into this section and the `section`-string is +prepended to all sub-sections, see the usage example above. + +The `options` object may contain the following: + +* `section` A string which will be the first `section` in the encoded + ini data. Defaults to none. +* `whitespace` Boolean to specify whether to put whitespace around the + `=` character. By default, whitespace is omitted, to be friendly to + some persnickety old parsers that don't tolerate it well. But some + find that it's more human-readable and pretty with the whitespace. + +For backwards compatibility reasons, if a `string` options is passed +in, then it is assumed to be the `section` value. + +### stringify(object, [options]) + +Alias for `encode(object, [options])` ### safe(val) -Escapes the string `val` such that it is safe to be used as a key or value in an ini-file. Basically escapes quotes. For example + +Escapes the string `val` such that it is safe to be used as a key or +value in an ini-file. Basically escapes quotes. For example ini.safe('"unsafe string"') @@ -76,4 +98,5 @@ would result in "\"unsafe string\"" ### unsafe(val) + Unescapes the string `val` diff --git a/node_modules/ini/ini.js b/node_modules/ini/ini.js index f5e444118636f..1e232e7438703 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 } diff --git a/node_modules/ini/package.json b/node_modules/ini/package.json index 5212afb063fa4..3042c406277ca 100644 --- a/node_modules/ini/package.json +++ b/node_modules/ini/package.json @@ -6,7 +6,7 @@ }, "name": "ini", "description": "An ini encoder/decoder for node", - "version": "1.2.1", + "version": "1.3.0", "repository": { "type": "git", "url": "git://github.com/isaacs/ini.git" @@ -22,15 +22,15 @@ "devDependencies": { "tap": "~0.4.0" }, - "gitHead": "13498ce1ba5a6a20cd77ed2b55de0e714786f70c", + "gitHead": "6c314944d0201f3199e1189aeb5687d0aaf1c575", "bugs": { "url": "https://github.com/isaacs/ini/issues" }, "homepage": "https://github.com/isaacs/ini", - "_id": "ini@1.2.1", - "_shasum": "7f774e2f22752cd1dacbf9c63323df2a164ebca3", - "_from": "ini@latest", - "_npmVersion": "1.4.11", + "_id": "ini@1.3.0", + "_shasum": "625483e56c643a7721014c76604d3353f44bd429", + "_from": "ini@>=1.3.0 <2.0.0", + "_npmVersion": "2.0.0", "_npmUser": { "name": "isaacs", "email": "i@izs.me" @@ -42,9 +42,10 @@ } ], "dist": { - "shasum": "7f774e2f22752cd1dacbf9c63323df2a164ebca3", - "tarball": "http://registry.npmjs.org/ini/-/ini-1.2.1.tgz" + "shasum": "625483e56c643a7721014c76604d3353f44bd429", + "tarball": "http://registry.npmjs.org/ini/-/ini-1.3.0.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/ini/-/ini-1.2.1.tgz" + "_resolved": "https://registry.npmjs.org/ini/-/ini-1.3.0.tgz", + "readme": "ERROR: No README data found!" } diff --git a/node_modules/ini/test/foo.js b/node_modules/ini/test/foo.js index 5c59890e8b641..9d34aa6fdaf37 100644 --- a/node_modules/ini/test/foo.js +++ b/node_modules/ini/test/foo.js @@ -59,6 +59,16 @@ var i = require("../") } } } + , expectF = '[prefix.log]\n' + + 'type=file\n\n' + + '[prefix.log.level]\n' + + 'label=debug\n' + + 'value=10\n' + , expectG = '[log]\n' + + 'type = file\n\n' + + '[log.level]\n' + + 'label = debug\n' + + 'value = 10\n' test("decode from file", function (t) { var d = i.decode(data) @@ -77,3 +87,19 @@ test("encode from data", function (t) { t.end() }) + +test("encode with option", function (t) { + var obj = {log: { type:'file', level: {label:'debug', value:10} } } + e = i.encode(obj, {section: 'prefix'}) + + t.equal(e, expectF) + t.end() +}) + +test("encode with whitespace", function (t) { + var obj = {log: { type:'file', level: {label:'debug', value:10} } } + e = i.encode(obj, {whitespace: true}) + + t.equal(e, expectG) + t.end() +}) diff --git a/package.json b/package.json index 512b0eebd8ebe..289af350ce71b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "graceful-fs": "~3.0.4", "inflight": "~1.0.4", "inherits": "~2.0.1", - "ini": "~1.2.0", + "ini": "~1.3.0", "init-package-json": "~1.1.0", "lockfile": "~1.0.0", "lru-cache": "~2.5.0",