diff options
Diffstat (limited to 'deps/npm/node_modules/@npmcli/config/lib/parse-field.js')
-rw-r--r-- | deps/npm/node_modules/@npmcli/config/lib/parse-field.js | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/deps/npm/node_modules/@npmcli/config/lib/parse-field.js b/deps/npm/node_modules/@npmcli/config/lib/parse-field.js index 95b8d9f2720..9428996c98a 100644 --- a/deps/npm/node_modules/@npmcli/config/lib/parse-field.js +++ b/deps/npm/node_modules/@npmcli/config/lib/parse-field.js @@ -6,10 +6,11 @@ const { resolve } = require('path') const { parse: umaskParse } = require('./umask.js') const parseField = (f, key, opts, listElement = false) => { - if (typeof f !== 'string' && !Array.isArray(f)) + if (typeof f !== 'string' && !Array.isArray(f)) { return f + } - const { platform, types, log, home, env } = opts + const { platform, types, home, env } = opts // type can be array or a single thing. coerce to array. const typeList = new Set([].concat(types[key])) @@ -20,8 +21,9 @@ const parseField = (f, key, opts, listElement = false) => { const isNumber = typeList.has(typeDefs.Number.type) const isList = !listElement && typeList.has(Array) - if (Array.isArray(f)) + if (Array.isArray(f)) { return !isList ? f : f.map(field => parseField(field, key, opts, true)) + } // now we know it's a string f = f.trim() @@ -29,12 +31,14 @@ const parseField = (f, key, opts, listElement = false) => { // list types get put in the environment separated by double-\n // usually a single \n would suffice, but ca/cert configs can contain // line breaks and multiple entries. - if (isList) + if (isList) { return parseField(f.split('\n\n'), key, opts) + } // --foo is like --foo=true for boolean types - if (isBool && !isString && f === '') + if (isBool && !isString && f === '') { return true + } // string types can be the string 'true', 'false', etc. // otherwise, parse these values out @@ -51,10 +55,11 @@ const parseField = (f, key, opts, listElement = false) => { if (isPath) { const homePattern = platform === 'win32' ? /^~(\/|\\)/ : /^~\// - if (homePattern.test(f) && home) + if (homePattern.test(f) && home) { f = resolve(home, f.substr(2)) - else + } else { f = resolve(f) + } } if (isUmask) { @@ -66,8 +71,9 @@ const parseField = (f, key, opts, listElement = false) => { } } - if (isNumber && !isNaN(f)) + if (isNumber && !isNaN(f)) { f = +f + } return f } |