summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2017-04-12 21:47:49 -0700
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2017-04-25 10:52:01 -0400
commit00842604483e4c2e622dfdb3a97440e07646158f (patch)
treef3346902636a44b6037652523767636bf7e4f2c9 /deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js
parent061c5da010e0d249379618382a499840d38247b8 (diff)
downloadandroid-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.gz
android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.bz2
android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.zip
deps: upgrade npm to 4.5.0
PR-URL: https://github.com/nodejs/node/pull/12480 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js')
-rw-r--r--deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js b/deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js
new file mode 100644
index 0000000000..c1bbe4d389
--- /dev/null
+++ b/deps/npm/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/rc/lib/utils.js
@@ -0,0 +1,102 @@
+'use strict';
+var fs = require('fs')
+var ini = require('ini')
+var path = require('path')
+var stripJsonComments = require('strip-json-comments')
+
+var parse = exports.parse = function (content) {
+
+ //if it ends in .json or starts with { then it must be json.
+ //must be done this way, because ini accepts everything.
+ //can't just try and parse it and let it throw if it's not ini.
+ //everything is ini. even json with a syntax error.
+
+ if(/^\s*{/.test(content))
+ return JSON.parse(stripJsonComments(content))
+ return ini.parse(content)
+
+}
+
+var file = exports.file = function () {
+ var args = [].slice.call(arguments).filter(function (arg) { return arg != null })
+
+ //path.join breaks if it's a not a string, so just skip this.
+ for(var i in args)
+ if('string' !== typeof args[i])
+ return
+
+ var file = path.join.apply(null, args)
+ var content
+ try {
+ return fs.readFileSync(file,'utf-8')
+ } catch (err) {
+ return
+ }
+}
+
+var json = exports.json = function () {
+ var content = file.apply(null, arguments)
+ return content ? parse(content) : null
+}
+
+var env = exports.env = function (prefix, env) {
+ env = env || process.env
+ var obj = {}
+ var l = prefix.length
+ for(var k in env) {
+ if((k.indexOf(prefix)) === 0) {
+
+ var keypath = k.substring(l).split('__')
+
+ // Trim empty strings from keypath array
+ var _emptyStringIndex
+ while ((_emptyStringIndex=keypath.indexOf('')) > -1) {
+ keypath.splice(_emptyStringIndex, 1)
+ }
+
+ var cursor = obj
+ keypath.forEach(function _buildSubObj(_subkey,i){
+
+ // (check for _subkey first so we ignore empty strings)
+ // (check for cursor to avoid assignment to primitive objects)
+ if (!_subkey || typeof cursor !== 'object')
+ return
+
+ // If this is the last key, just stuff the value in there
+ // Assigns actual value from env variable to final key
+ // (unless it's just an empty string- in that case use the last valid key)
+ if (i === keypath.length-1)
+ cursor[_subkey] = env[k]
+
+
+ // Build sub-object if nothing already exists at the keypath
+ if (cursor[_subkey] === undefined)
+ cursor[_subkey] = {}
+
+ // Increment cursor used to track the object at the current depth
+ cursor = cursor[_subkey]
+
+ })
+
+ }
+
+ }
+
+ return obj
+}
+
+var find = exports.find = function () {
+ var rel = path.join.apply(null, [].slice.call(arguments))
+
+ function find(start, rel) {
+ var file = path.join(start, rel)
+ try {
+ fs.statSync(file)
+ return file
+ } catch (err) {
+ if(path.dirname(start) !== start) // root
+ return find(path.dirname(start), rel)
+ }
+ }
+ return find(process.cwd(), rel)
+}