diff options
author | isaacs <i@izs.me> | 2013-01-30 11:06:45 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-01-30 11:06:45 +0400 |
commit | 2980948865e3ba80c93eed35f217d2d9181f95eb (patch) | |
tree | a08b9e23dadcd2cc65ecd26c6d04e00f4a4520ff /node_modules/ini | |
parent | fc13f37bb8538d6f5b9735c0b15df0963ae1de33 (diff) |
ini@1.1.0
Diffstat (limited to 'node_modules/ini')
-rw-r--r-- | node_modules/ini/README.md | 10 | ||||
-rw-r--r-- | node_modules/ini/ini.js | 30 | ||||
-rw-r--r-- | node_modules/ini/package.json | 7 | ||||
-rw-r--r-- | node_modules/ini/test/fixtures/foo.ini | 15 | ||||
-rw-r--r-- | node_modules/ini/test/foo.js | 16 |
5 files changed, 68 insertions, 10 deletions
diff --git a/node_modules/ini/README.md b/node_modules/ini/README.md index 9f82a765d..acbe8ec89 100644 --- a/node_modules/ini/README.md +++ b/node_modules/ini/README.md @@ -17,6 +17,9 @@ Consider an ini-file `config.ini` that looks like this: [paths.default] datadir = /var/lib/data + array[] = first value + array[] = second value + array[] = third value You can read, manipulate and write the ini-file like so: @@ -29,6 +32,7 @@ You can read, manipulate and write the ini-file like so: config.database.database = 'use_another_database' config.paths.default.tmpdir = '/tmp' delete config.paths.default.datadir + config.paths.default.array.push('fourth value') fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section')) @@ -42,6 +46,11 @@ This will result in a file called `config_modified.ini` being written to the fil database = use_another_database [section.paths.default] tmpdir = /tmp + array[] = first value + array[] = second value + array[] = third value + array[] = fourth value + ## API @@ -68,4 +77,3 @@ would result in ### unsafe(val) Unescapes the string `val` - diff --git a/node_modules/ini/ini.js b/node_modules/ini/ini.js index 45651c03f..eaf320933 100644 --- a/node_modules/ini/ini.js +++ b/node_modules/ini/ini.js @@ -13,7 +13,12 @@ function encode (obj, section) { Object.keys(obj).forEach(function (k, _, __) { var val = obj[k] - if (val && typeof val === "object") { + if (val && Array.isArray(val)) { + val.forEach(function(item) { + out += safe(k + "[]") + " = " + safe(item) + "\n" + }) + } + else if (val && typeof val === "object") { children.push(k) } else { out += safe(k) + " = " + safe(val) + eol @@ -71,13 +76,32 @@ function decode (str) { case 'false': case 'null': value = JSON.parse(value) } - p[key] = value + + // Convert keys with '[]' suffix to an array + if (key.length > 2 && key.slice(-2) === "[]") { + key = key.substring(0, key.length - 2) + if (!p[key]) { + p[key] = [] + } + else if (!Array.isArray(p[key])) { + p[key] = [p[key]] + } + } + + // safeguard against resetting a previously defined + // array by accidentally forgetting the brackets + if (Array.isArray(p[key])) { + p[key].push(value) + } + else { + p[key] = value + } }) // {a:{y:1},"a.b":{x:2}} --> {a:{y:1,b:{x:2}}} // use a filter to return the keys that have to be deleted. Object.keys(out).filter(function (k, _, __) { - if (!out[k] || typeof out[k] !== "object") return false + if (!out[k] || typeof out[k] !== "object" || Array.isArray(out[k])) return false // see if the parent section is also an object. // if so, add it to that, and mark this one for deletion var parts = dotSplit(k) diff --git a/node_modules/ini/package.json b/node_modules/ini/package.json index 3f45c18e2..41c63607a 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.0.5", + "version": "1.1.0", "repository": { "type": "git", "url": "git://github.com/isaacs/ini.git" @@ -22,7 +22,8 @@ "devDependencies": { "tap": "~0.0.9" }, - "readme": "An ini format parser and serializer for node.\n\nSections are treated as nested objects. Items before the first heading\nare saved on the object directly.\n\n## Usage\n\nConsider an ini-file `config.ini` that looks like this:\n\n ; this comment is being ignored\n scope = global\n\n [database]\n user = dbuser\n password = dbpassword\n database = use_this_database\n\n [paths.default]\n datadir = /var/lib/data\n\nYou can read, manipulate and write the ini-file like so:\n\n var fs = require('fs')\n , ini = require('ini')\n\n var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))\n\n config.scope = 'local'\n config.database.database = 'use_another_database'\n config.paths.default.tmpdir = '/tmp'\n delete config.paths.default.datadir\n\n fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section'))\n\nThis will result in a file called `config_modified.ini` being written to the filesystem with the following content:\n\n [section]\n scope = local\n [section.database]\n user = dbuser\n password = dbpassword\n database = use_another_database\n [section.paths.default]\n tmpdir = /tmp\n\n## API\n\n### decode(inistring)\nDecode the ini-style formatted `inistring` into a nested object.\n\n### parse(inistring)\nAlias for `decode(inistring)`\n\n### encode(object, [section])\nEncode 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.\n\n### stringify(object, [section])\nAlias for `encode(object, [section])`\n\n### safe(val)\nEscapes 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\n\n ini.safe('\"unsafe string\"')\n\nwould result in\n\n \"\\\"unsafe string\\\"\"\n\n### unsafe(val)\nUnescapes the string `val`\n\n", - "_id": "ini@1.0.5", + "readme": "An ini format parser and serializer for node.\n\nSections are treated as nested objects. Items before the first heading\nare saved on the object directly.\n\n## Usage\n\nConsider an ini-file `config.ini` that looks like this:\n\n ; this comment is being ignored\n scope = global\n\n [database]\n user = dbuser\n password = dbpassword\n database = use_this_database\n\n [paths.default]\n datadir = /var/lib/data\n array[] = first value\n array[] = second value\n array[] = third value\n\nYou can read, manipulate and write the ini-file like so:\n\n var fs = require('fs')\n , ini = require('ini')\n\n var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))\n\n config.scope = 'local'\n config.database.database = 'use_another_database'\n config.paths.default.tmpdir = '/tmp'\n delete config.paths.default.datadir\n config.paths.default.array.push('fourth value')\n\n fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section'))\n\nThis will result in a file called `config_modified.ini` being written to the filesystem with the following content:\n\n [section]\n scope = local\n [section.database]\n user = dbuser\n password = dbpassword\n database = use_another_database\n [section.paths.default]\n tmpdir = /tmp\n array[] = first value\n array[] = second value\n array[] = third value\n array[] = fourth value\n\n\n## API\n\n### decode(inistring)\nDecode the ini-style formatted `inistring` into a nested object.\n\n### parse(inistring)\nAlias for `decode(inistring)`\n\n### encode(object, [section])\nEncode 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.\n\n### stringify(object, [section])\nAlias for `encode(object, [section])`\n\n### safe(val)\nEscapes 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\n\n ini.safe('\"unsafe string\"')\n\nwould result in\n\n \"\\\"unsafe string\\\"\"\n\n### unsafe(val)\nUnescapes the string `val`\n", + "readmeFilename": "README.md", + "_id": "ini@1.1.0", "_from": "ini@latest" } diff --git a/node_modules/ini/test/fixtures/foo.ini b/node_modules/ini/test/fixtures/foo.ini index 6f11f3679..1d81378fd 100644 --- a/node_modules/ini/test/fixtures/foo.ini +++ b/node_modules/ini/test/fixtures/foo.ini @@ -8,6 +8,17 @@ o = p ; wrap in quotes to get a key with a bracket, not a section. "[disturbing]" = hey you never know +; Test arrays +zr[] = deedee +ar[] = one +ar[] = three +; This should be included in the array +ar = this is included + +; Test resetting of a value (and not turn it into an array) +br = cold +br = warm + ; a section [a] av = a val @@ -15,6 +26,10 @@ e = { o: p, a: { av: a val, b: { c: { e: "this [value]" } } } } j = "{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }" "[]" = a square? +; Nested array +cr[] = four +cr[] = eight + ; nested child without middle parent ; should create otherwise-empty a.b [a.b.c] diff --git a/node_modules/ini/test/foo.js b/node_modules/ini/test/foo.js index 64bd22329..3a05eaf32 100644 --- a/node_modules/ini/test/foo.js +++ b/node_modules/ini/test/foo.js @@ -10,6 +10,11 @@ var i = require("../") + 'a with spaces = b c\n' + '" xa n p " = "\\"\\r\\nyoyoyo\\r\\r\\n"\n' + '"[disturbing]" = hey you never know\n' + + 'zr[] = deedee\n' + + 'ar[] = one\n' + + 'ar[] = three\n' + + 'ar[] = this is included\n' + + 'br = warm\n' + '\n' + '[a]\n' + 'av = a val\n' @@ -17,21 +22,26 @@ var i = require("../") + '{ av: a val, b: { c: { e: "this [value]" ' + '} } } }\nj = "\\"{ o: \\"p\\", a: { av:' + ' \\"a val\\", b: { c: { e: \\"this [value]' - + '\\" } } } }\\""\n"[]" = a square?\n\n[a.b.c]\ne = 1\n' + + '\\" } } } }\\""\n"[]" = a square?\n' + + 'cr[] = four\ncr[] = eight\n\n' + +'[a.b.c]\ne = 1\n' + 'j = 2\n\n[x\\.y\\.z]\nx.y.z = xyz\n\n' - + '[x\\.y\\.z.a\\.b\\.c]\n' - + 'a.b.c = abc\n' + + '[x\\.y\\.z.a\\.b\\.c]\na.b.c = abc\n' + 'nocomment = this\\; this is not a comment\n' , expectD = { o: 'p', 'a with spaces': 'b c', " xa n p ":'"\r\nyoyoyo\r\r\n', '[disturbing]': 'hey you never know', + 'zr': ['deedee'], + 'ar': ['one', 'three', 'this is included'], + 'br': 'warm', a: { av: 'a val', e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }', j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"', "[]": "a square?", + cr: ['four', 'eight'], b: { c: { e: '1', j: '2' } } }, 'x.y.z': { 'x.y.z': 'xyz', |