Permalink
Browse files

Use standalone ini parser

  • Loading branch information...
1 parent ba1830f commit 7fd0f96d8bbb6f4f9cee60b09bb19e38a55d78fd @isaacs isaacs committed Aug 7, 2011
Showing with 8 additions and 67 deletions.
  1. +3 −0 .gitmodules
  2. +0 −65 lib/utils/ini-parser.js
  3. +1 −1 lib/utils/ini.js
  4. +1 −1 lib/view.js
  5. +1 −0 node_modules/ini
  6. +2 −0 package.json
View
@@ -25,3 +25,6 @@
[submodule "node_modules/proto-list"]
path = node_modules/proto-list
url = https://github.com/isaacs/proto-list.git
+[submodule "node_modules/ini"]
+ path = node_modules/ini
+ url = https://github.com/isaacs/ini.git
View
@@ -1,65 +0,0 @@
-exports.parse = function parse (d) {
- var ini = {'-':{}}
- , section = '-'
- , lines = d.split('\n')
- for (var i = 0, l = lines.length; i < l; i++ ) {
- var line = lines[i].trim()
- , rem = line.indexOf(";")
- if (rem !== -1) line = line.substr(0, rem)
- var re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i
- , match = line.match(re)
- if (match) {
- if (match[1] !== undefined) {
- section = match[1].trim()
- ini[section] = {}
- } else {
- var key = match[2].trim()
- , value = (match[3]) ? (match[4] || "").trim() : true
- ini[section][key] = value
- }
- }
- }
-
- return ini
-}
-
-function safe (val) { return (val+"").replace(/[\n\r]+/g, " ") }
-
-// ForEaches over an object. The only thing faster is to inline this function.
-function objectEach(obj, fn, thisObj) {
- var keys = Object.keys(obj).sort(function (a,b) {
- a = a.toLowerCase()
- b = b.toLowerCase()
- return a === b ? 0 : a < b ? -1 : 1
- })
- for (var i = 0, l = keys.length; i < l; i++) {
- var key = keys[i]
- fn.call(thisObj, obj[key], key, obj)
- }
-}
-
-exports.stringify = function stringify (obj) {
- // if the obj has a "-" section, then do that first.
- var ini = []
- if ("-" in obj) {
- objectEach(obj["-"], function (value, key) {
- // skip over undefined values.
- // set to null to explicitly set to nothing.
- if (value === undefined) return
- ini[ini.length] = safe(key) + " = " + safe(value) + "\n"
- })
- }
- objectEach(obj, function (section, name) {
- if (name === "-") return undefined
- ini[ini.length] = "[" + safe(name) + "]\n"
- objectEach(section, function (value, key) {
- ini[ini.length] = safe(key) + ((value === true)
- ? "\n"
- : " = "+safe(value)+"\n")
- })
- })
- return ini.join("")
-}
-
-exports.encode = exports.stringify
-exports.decode = exports.parse
View
@@ -33,7 +33,7 @@ var fs = require("graceful-fs")
, privateKey = null
, log = require("./log.js")
- , ini = require("./ini-parser.js")
+ , ini = require("ini")
, base64 = require("./base64.js")
, ProtoList = require("proto-list")
, defaultConfig
View
@@ -40,7 +40,7 @@ view.completion = function (opts, cb) {
}
var registry = require("./utils/npm-registry-client/index.js")
- , ini = require("./utils/ini-parser.js")
+ , ini = require("ini")
, log = require("./utils/log.js")
, util = require("util")
, output
Submodule ini added at bad4c0
View
@@ -25,6 +25,7 @@
, "npm-g" : "./bin/npm.js" }
, "dependencies" :
{ "semver" : "1"
+ , "ini" : "1"
, "slide" : "1"
, "abbrev" : "1"
, "graceful-fs" : "1"
@@ -35,6 +36,7 @@
, "rimraf" : "1" }
, "bundleDependencies" :
[ "slide"
+ , "ini"
, "semver"
, "abbrev"
, "graceful-fs"

0 comments on commit 7fd0f96

Please sign in to comment.