Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-01-13 20:33:27 +0400
committerisaacs <i@izs.me>2012-01-13 20:41:06 +0400
commitc18fe966ddbeb66c8a9b9aa8ab4899166e6986f5 (patch)
tree8650e7575caff9d05e04352b78669dd81d21230d /node_modules/ini
parentb7ff884870958221eb52c5a600c101fab4c26781 (diff)
check in node_modules
Diffstat (limited to 'node_modules/ini')
-rw-r--r--node_modules/ini/LICENSE23
-rw-r--r--node_modules/ini/README.md71
-rw-r--r--node_modules/ini/ini.js102
-rw-r--r--node_modules/ini/package.json24
4 files changed, 220 insertions, 0 deletions
diff --git a/node_modules/ini/LICENSE b/node_modules/ini/LICENSE
new file mode 100644
index 000000000..05a401094
--- /dev/null
+++ b/node_modules/ini/LICENSE
@@ -0,0 +1,23 @@
+Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/ini/README.md b/node_modules/ini/README.md
new file mode 100644
index 000000000..9f82a765d
--- /dev/null
+++ b/node_modules/ini/README.md
@@ -0,0 +1,71 @@
+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.
+
+## Usage
+
+Consider an ini-file `config.ini` that looks like this:
+
+ ; this comment is being ignored
+ scope = global
+
+ [database]
+ user = dbuser
+ password = dbpassword
+ database = use_this_database
+
+ [paths.default]
+ datadir = /var/lib/data
+
+You can read, manipulate and write the ini-file like so:
+
+ var fs = require('fs')
+ , ini = require('ini')
+
+ var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
+
+ config.scope = 'local'
+ config.database.database = 'use_another_database'
+ config.paths.default.tmpdir = '/tmp'
+ delete config.paths.default.datadir
+
+ fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section'))
+
+This will result in a file called `config_modified.ini` being written to the filesystem with the following content:
+
+ [section]
+ scope = local
+ [section.database]
+ user = dbuser
+ password = dbpassword
+ database = use_another_database
+ [section.paths.default]
+ tmpdir = /tmp
+
+## 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.
+
+### stringify(object, [section])
+Alias for `encode(object, [section])`
+
+### 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
+
+ ini.safe('"unsafe string"')
+
+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
new file mode 100644
index 000000000..e8a949f94
--- /dev/null
+++ b/node_modules/ini/ini.js
@@ -0,0 +1,102 @@
+
+exports.parse = exports.decode = decode
+exports.stringify = exports.encode = encode
+
+exports.safe = safe
+exports.unsafe = unsafe
+
+function encode (obj, section) {
+ var children = []
+ , out = ""
+
+ Object.keys(obj).forEach(function (k, _, __) {
+ var val = obj[k]
+ if (val && typeof val === "object") {
+ children.push(k)
+ } else {
+ out += safe(k) + " = " + safe(val) + "\n"
+ }
+ })
+
+ if (section && out.length) {
+ out = "[" + safe(section) + "]" + "\n" + out
+ }
+
+ children.forEach(function (k, _, __) {
+ var child = encode(obj[k], (section ? section + "." : "") + k)
+ if (out.length && child.length) {
+ out += "\n"
+ }
+ out += child
+ })
+
+ return out
+}
+
+function decode (str) {
+ var out = {}
+ , p = out
+ , section = null
+ , state = "START"
+ // section |key = value
+ , re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i
+ , lines = str.split(/[\r\n]+/g)
+ , section = null
+
+ lines.forEach(function (line, _, __) {
+ //line = line
+ var rem = line.indexOf(";")
+ if (rem !== -1) line = line.substr(0, rem)//.trim()
+ if (!line) return
+ var match = line.match(re)
+ if (!match) return
+ if (match[1] !== undefined) {
+ section = unsafe(match[1])
+ p = out[section] = out[section] || {}
+ return
+ }
+ var key = unsafe(match[2])
+ , value = match[3] ? unsafe((match[4] || "")) : true
+ 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
+ // see if the parent section is also an object.
+ // if so, add it to that, and mark this one for deletion
+ var parts = k.split(".")
+ , p = out
+ , l = parts.pop()
+ parts.forEach(function (part, _, __) {
+ if (!p[part] || typeof p[part] !== "object") p[part] = {}
+ p = p[part]
+ })
+ if (p === out) return false
+ p[l] = out[k]
+ return true
+ }).forEach(function (del, _, __) {
+ delete out[del]
+ })
+
+ return out
+}
+
+function safe (val) {
+ return ( typeof val !== "string"
+ || val.match(/[\r\n]/)
+ || val.match(/^\[/)
+ || (val.length > 1
+ && val.charAt(0) === "\""
+ && val.slice(-1) === "\"")
+ || val !== val.trim() ) ? JSON.stringify(val) : val
+}
+
+function unsafe (val) {
+ val = (val || "").trim()
+ if (val.charAt(0) === "\"" && val.slice(-1) === "\"") {
+ try { val = JSON.parse(val) } catch (_) {}
+ }
+ return val
+}
diff --git a/node_modules/ini/package.json b/node_modules/ini/package.json
new file mode 100644
index 000000000..a022b598f
--- /dev/null
+++ b/node_modules/ini/package.json
@@ -0,0 +1,24 @@
+{
+ "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
+ "name": "ini",
+ "description": "An ini encoder/decoder for node",
+ "version": "1.0.2",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/isaacs/ini.git"
+ },
+ "main": "ini.js",
+ "scripts": {
+ "test": "node ini.js"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "tap": "~0.0.9"
+ },
+ "scripts": {
+ "test": "tap test/*.js"
+ }
+}