diff --git a/lib/bin.js b/lib/bin.js index 7258893b9c391..f4b77120a2a84 100644 --- a/lib/bin.js +++ b/lib/bin.js @@ -17,7 +17,7 @@ function bin (args, silent, cb) { if (!silent) output(b) process.nextTick(cb.bind(this, null, b)) - if (npm.config.get('global') && PATH.indexOf(b) === -1) { + if (npm.config.get('global') && !PATH.includes(b)) { npm.config.get('logstream').write('(not in PATH env variable)\n') } } diff --git a/lib/build.js b/lib/build.js index f8b3c4933ed1b..3919013896f05 100644 --- a/lib/build.js +++ b/lib/build.js @@ -121,9 +121,9 @@ function rebuildBundles (pkg, folder, cb) { // not a .folder, like .bin or .hooks return !file.match(/^[._-]/) && // not some old 0.x style bundle - file.indexOf('@') === -1 && + !file.includes('@') && // either not a dep, or explicitly bundled - (deps.indexOf(file) === -1 || bundles.indexOf(file) !== -1) + (!deps.includes(file) || bundles.includes(file)) }).map(function (file) { file = path.resolve(folder, 'node_modules', file) return function (cb) { diff --git a/lib/completion.js b/lib/completion.js index a682c134a7737..a0bbd63e50733 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -101,7 +101,7 @@ function completion (args, cb) { console.error(opts) - if (partialWords.slice(0, -1).indexOf('--') === -1) { + if (!partialWords.slice(0, -1).includes('--')) { if (word.charAt(0) === '-') return configCompl(opts, cb) if (words[w - 1] && words[w - 1].charAt(0) === '-' && diff --git a/lib/config.js b/lib/config.js index 5f9819879be23..5a569025b7407 100644 --- a/lib/config.js +++ b/lib/config.js @@ -143,7 +143,7 @@ function set (key, val, cb) { return unknown('', cb) } if (val === undefined) { - if (key.indexOf('=') !== -1) { + if (key.includes('=')) { var k = key.split('=') key = k.shift() val = k.join('=') @@ -176,7 +176,7 @@ function sort (a, b) { } function publicVar (k) { - return !(k.charAt(0) === '_' || k.indexOf(':_') !== -1) + return !(k.charAt(0) === '_' || k.includes(':_')) } function getKeys (data) { diff --git a/lib/config/core.js b/lib/config/core.js index 36420b3450163..e5d7e83be9649 100644 --- a/lib/config/core.js +++ b/lib/config/core.js @@ -361,11 +361,11 @@ function parseField (f, k) { // type can be an array or single thing. var typeList = [].concat(types[k]) - var isPath = typeList.indexOf(path) !== -1 - var isBool = typeList.indexOf(Boolean) !== -1 - var isString = typeList.indexOf(String) !== -1 - var isUmask = typeList.indexOf(Umask) !== -1 - var isNumber = typeList.indexOf(Number) !== -1 + var isPath = typeList.includes(path) + var isBool = typeList.includes(Boolean) + var isString = typeList.includes(String) + var isUmask = typeList.includes(Umask) + var isNumber = typeList.includes(Number) f = ('' + f).trim() diff --git a/lib/config/defaults.js b/lib/config/defaults.js index e07da3aaf97f4..ae7ee428a08c5 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -45,8 +45,8 @@ nopt.invalidHandler = function (k, val, type) { log.warn('invalid config', k + '=' + JSON.stringify(val)) if (Array.isArray(type)) { - if (type.indexOf(url) !== -1) type = url - else if (type.indexOf(path) !== -1) type = path + if (type.includes(url)) type = url + else if (type.includes(path)) type = path } switch (type) { diff --git a/lib/help-search.js b/lib/help-search.js index 475f305e49103..c2de0ef30f3d1 100644 --- a/lib/help-search.js +++ b/lib/help-search.js @@ -51,7 +51,7 @@ function searchFiles (args, files, cb) { // skip if no matches at all var match for (var a = 0, l = args.length; a < l && !match; a++) { - match = data.toLowerCase().indexOf(args[a].toLowerCase()) !== -1 + match = data.toLowerCase().includes(args[a].toLowerCase()) } if (!match) return @@ -69,8 +69,7 @@ function searchFiles (args, files, cb) { match = false if (nextLine) { for (a = 0, ll = args.length; a < ll && !match; a++) { - match = nextLine.toLowerCase() - .indexOf(args[a].toLowerCase()) !== -1 + match = nextLine.toLowerCase().includes(args[a].toLowerCase()) } if (match) { // skip over the next line, and the line after it. @@ -81,7 +80,7 @@ function searchFiles (args, files, cb) { match = false for (a = 0, ll = args.length; a < ll && !match; a++) { - match = line.toLowerCase().indexOf(args[a].toLowerCase()) !== -1 + match = line.toLowerCase().includes(args[a].toLowerCase()) } if (match) { // skip over the next line diff --git a/lib/help.js b/lib/help.js index 61f1f3f94cc66..2f95d11ce5ef3 100644 --- a/lib/help.js +++ b/lib/help.js @@ -50,7 +50,7 @@ function help (args, cb) { } // npm apihelp
: Prefer section 3 over section 1 - var apihelp = argv.length && argv[0].indexOf('api') !== -1 + var apihelp = argv.length && argv[0].includes('api') var pref = apihelp ? [3, 1, 5, 7] : [1, 3, 5, 7] if (argnum) { pref = [ argnum ].concat(pref.filter(function (n) { diff --git a/lib/install.js b/lib/install.js index 378ada7b05c06..9b66eacccc3c5 100644 --- a/lib/install.js +++ b/lib/install.js @@ -67,7 +67,7 @@ install.completion = function (opts, cb) { null, { fullPath: fullPath, - isPackage: contents.indexOf('package.json') !== -1 + isPackage: contents.includes('package.json') } ) }) diff --git a/lib/install/diff-trees.js b/lib/install/diff-trees.js index 147aa9b8e74f3..3a83eff264793 100644 --- a/lib/install/diff-trees.js +++ b/lib/install/diff-trees.js @@ -168,7 +168,7 @@ var sortActions = module.exports.sortActions = function (differences) { // safety net, anything excluded above gets tacked on the end differences.forEach((_) => { - if (sorted.indexOf(_) === -1) sorted.push(_) + if (!sorted.includes(_)) sorted.push(_) }) return sorted diff --git a/lib/link.js b/lib/link.js index e05526c4080d3..acf57c700b27c 100644 --- a/lib/link.js +++ b/lib/link.js @@ -87,7 +87,7 @@ function linkInstall (pkgs, cb) { // if it's a folder, a random not-installed thing, or not a scoped package, // then link or install it first - if (pkg[0] !== '@' && (pkg.indexOf('/') !== -1 || pkg.indexOf('\\') !== -1)) { + if (pkg[0] !== '@' && (pkg.includes('/') || pkg.includes('\\'))) { return fs.lstat(path.resolve(pkg), function (er, st) { if (er || !st.isDirectory()) { npm.commands.install(t, pkg, n) diff --git a/lib/ls.js b/lib/ls.js index 78a2b1d791c7d..0913166d42948 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -46,7 +46,7 @@ function ls (args, silent, cb) { } function inList (list, value) { - return list.indexOf(value) !== -1 + return list.includes(value) } var lsFromTree = ls.fromTree = function (dir, physicalTree, args, silent, cb) { @@ -125,7 +125,7 @@ function pruneNestedExtraneous (data, visited) { for (var i in data.dependencies) { if (data.dependencies[i].extraneous) { data.dependencies[i].dependencies = {} - } else if (visited.indexOf(data.dependencies[i]) === -1) { + } else if (!visited.includes(data.dependencies[i])) { pruneNestedExtraneous(data.dependencies[i], visited) } } diff --git a/lib/npm.js b/lib/npm.js index 74ef6ad2c6e74..fc1a90fa0954f 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -94,13 +94,13 @@ var littleGuys = [ 'isntall', 'verison' ] var fullList = cmdList.concat(aliasNames).filter(function (c) { - return plumbing.indexOf(c) === -1 + return !plumbing.includes(c) }) var abbrevs = abbrev(fullList) // we have our reasons fullList = npm.fullList = fullList.filter(function (c) { - return littleGuys.indexOf(c) === -1 + return !littleGuys.includes(c) }) var registryRefer @@ -162,7 +162,7 @@ return commandCache[a] }, - enumerable: fullList.indexOf(c) !== -1, + enumerable: fullList.includes(c), configurable: true }) // make css-case commands callable via camelCase as well @@ -186,7 +186,7 @@ return '-' + m.toLowerCase() }) } - if (plumbing.indexOf(c) !== -1) return c + if (plumbing.includes(c)) return c var a = abbrevs[c] while (aliases[a]) { a = aliases[a] diff --git a/lib/outdated.js b/lib/outdated.js index 5b84ae35587c8..5c0c19480c3c5 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -352,7 +352,7 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, opts, cb, type cb) } - if (args.length && args.indexOf(dep) === -1) return skip() + if (args.length && !args.includes(dep)) return skip() if (tree.isLink && req == null) return skip() diff --git a/lib/owner.js b/lib/owner.js index a64cb5e14ccef..a565b0500f04f 100644 --- a/lib/owner.js +++ b/lib/owner.js @@ -46,7 +46,7 @@ owner.completion = function (opts, cb) { return npmFetch.json(byUser, opts).then(d => { return d[theUser].filter( // kludge for server adminery. - p => un === 'isaacs' || d[un].indexOf(p) === -1 + p => un === 'isaacs' || !d[un].includes(p) ) }) } @@ -59,7 +59,7 @@ owner.completion = function (opts, cb) { return npmFetch.json(byUser, opts).then(d => { var mine = d[un] || [] var theirs = d[theUser] || [] - return mine.filter(p => theirs.indexOf(p) === -1) + return mine.filter(p => !theirs.includes(p)) }) } else { // just list all users who aren't me. diff --git a/lib/profile.js b/lib/profile.js index 7ce9cb5cce5df..8d03ee57d8cd1 100644 --- a/lib/profile.js +++ b/lib/profile.js @@ -150,7 +150,7 @@ function set (args) { 'npm profile set password\n' + 'Do not include your current or new passwords on the command line.')) } - if (writableProfileKeys.indexOf(prop) === -1) { + if (!writableProfileKeys.includes(prop)) { return Promise.reject(Error(`"${prop}" is not a property we can set. Valid properties are: ` + writableProfileKeys.join(', '))) } return BB.try(() => { diff --git a/lib/prune.js b/lib/prune.js index 010e471e4b328..3de9609120ca5 100644 --- a/lib/prune.js +++ b/lib/prune.js @@ -50,7 +50,7 @@ Pruner.prototype.loadAllDepsIntoIdealTree = function (cb) { return moduleName(child) } function matchesArg (name) { - return self.args.length === 0 || self.args.indexOf(name) !== -1 + return self.args.length === 0 || self.args.includes(name) } function nameObj (name) { return {name: name} diff --git a/lib/run-script.js b/lib/run-script.js index 476591c051e73..bc57e5952fa3d 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -31,7 +31,7 @@ runScript.completion = function (opts, cb) { if (er) d = {} var scripts = Object.keys(d.scripts || {}) console.error('local scripts', scripts) - if (scripts.indexOf(argv[2]) !== -1) return cb() + if (scripts.includes(argv[2])) return cb() // ok, try to find out which package it was, then var pref = npm.config.get('global') ? npm.config.get('prefix') : npm.localPrefix @@ -85,7 +85,7 @@ function list (cb) { var scripts = [] var runScripts = [] allScripts.forEach(function (script) { - if (cmdList.indexOf(script) !== -1) scripts.push(script) + if (cmdList.includes(script)) scripts.push(script) else runScripts.push(script) }) diff --git a/lib/search/package-filter.js b/lib/search/package-filter.js index 892adb08c96a5..ded46bbe0cbad 100644 --- a/lib/search/package-filter.js +++ b/lib/search/package-filter.js @@ -37,5 +37,5 @@ function match (words, pattern) { pattern = new RegExp(pattern.substr(1, pattern.length - 1)) return words.match(pattern) } - return words.indexOf(pattern) !== -1 + return words.includes(pattern) } diff --git a/lib/update.js b/lib/update.js index fdb934fac6730..9956debfeb52e 100644 --- a/lib/update.js +++ b/lib/update.js @@ -61,7 +61,7 @@ function update_ (args) { const isTransitive = !(ww.dep.requiredBy || []).some((p) => p.isTop) const key = where + ':' + String(isTransitive) if (!toInstall[key]) toInstall[key] = {where: where, opts: {saveOnlyLock: isTransitive}, what: []} - if (toInstall[key].what.indexOf(ww.what) === -1) toInstall[key].what.push(ww.what) + if (!toInstall[key].what.includes(ww.what)) toInstall[key].what.push(ww.what) }) return Bluebird.each(Object.keys(toInstall), (key) => { const deps = toInstall[key] diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 12f304d1e894a..fa6a7b7f5c21d 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -157,7 +157,7 @@ function errorMessage (er) { // npm ERR! code E401 // npm ERR! Unable to authenticate, need: Basic const auth = (er.headers && er.headers['www-authenticate'] && er.headers['www-authenticate'].map((au) => au.split(/,\s*/))[0]) || [] - if (auth.indexOf('Bearer') !== -1) { + if (auth.includes('Bearer')) { short.push(['', 'Unable to authenticate, your authentication token seems to be invalid.']) detail.push([ '', @@ -166,7 +166,7 @@ function errorMessage (er) { ' npm login' ].join('\n') ]) - } else if (auth.indexOf('Basic') !== -1) { + } else if (auth.includes('Basic')) { short.push(['', 'Incorrect or missing password.']) detail.push([ '', diff --git a/lib/utils/open-url.js b/lib/utils/open-url.js index e1ed2b3fab76d..fe4534ef83e06 100644 --- a/lib/utils/open-url.js +++ b/lib/utils/open-url.js @@ -17,7 +17,7 @@ module.exports = function open (url, errMsg, cb, browser = npm.config.get('brows output(alternateMsg) } - const skipBrowser = process.argv.indexOf('--no-browser') > -1 + const skipBrowser = process.argv.includes('--no-browser') if (skipBrowser) { printAlternateMsg() diff --git a/lib/version.js b/lib/version.js index 6619a8ba9d0d7..672bbf4a5051e 100644 --- a/lib/version.js +++ b/lib/version.js @@ -74,7 +74,7 @@ function parseLastGitTag (cb) { var options = { env: process.env } git.whichAndExec(['describe', '--abbrev=0'], options, function (er, stdout) { if (er) { - if (er.message.indexOf('No names found') !== -1) return cb(new Error('No tags found')) + if (er.message.includes('No names found')) return cb(new Error('No tags found')) return cb(er) } diff --git a/lib/view.js b/lib/view.js index a16884e25f647..2904a882c2b9d 100644 --- a/lib/view.js +++ b/lib/view.js @@ -56,7 +56,7 @@ view.completion = function (opts, cb) { if (!d) return f pref = pref || [] Object.keys(d).forEach(function (k) { - if (k.charAt(0) === '_' || k.indexOf('.') !== -1) return + if (k.charAt(0) === '_' || k.includes('.')) return const p = pref.concat(k).join('.') f.push(p) if (Array.isArray(d[k])) { @@ -162,7 +162,7 @@ function fetchAndRead (nv, args, silent, opts, cb) { if (!args.length) args = [''] // remove readme unless we asked for it - if (args.indexOf('readme') === -1) { + if (!args.includes('readme')) { delete data.readme } @@ -170,7 +170,7 @@ function fetchAndRead (nv, args, silent, opts, cb) { if (semver.satisfies(v, version, true)) { args.forEach(function (args) { // remove readme unless we asked for it - if (args.indexOf('readme') !== -1) { + if (args.includes('readme')) { delete versions[v].readme } results.push(showFields(data, versions[v], args)) @@ -447,7 +447,7 @@ function printData (data, name, opts, cb) { } if (!opts.json) { if (f && includeFields) f += ' = ' - if (d.indexOf('\n') !== -1) d = ' \n' + d + if (d.includes('\n')) d = ' \n' + d msg += (includeVersions ? name + '@' + v + ' ' : '') + (includeFields ? f : '') + d + '\n' } diff --git a/test/tap/00-verify-bundle-deps.js b/test/tap/00-verify-bundle-deps.js index 75ea81c593e76..88507492778a1 100644 --- a/test/tap/00-verify-bundle-deps.js +++ b/test/tap/00-verify-bundle-deps.js @@ -7,7 +7,7 @@ var bundled = manifest.bundleDependencies test('all deps are bundled deps or dev deps', function (t) { deps.forEach(function (name) { t.assert( - bundled.indexOf(name) !== -1, + bundled.includes(name), name + ' is in bundledDependencies' ) }) diff --git a/test/tap/config-meta.js b/test/tap/config-meta.js index a98d5e6c4dabd..c6b83ad8b8f56 100644 --- a/test/tap/config-meta.js +++ b/test/tap/config-meta.js @@ -72,7 +72,7 @@ test('get lines', function (t) { line: i } } - } else if (exceptions.indexOf(f) === -1 && f.indexOf('.cache') === -1) { + } else if (!exceptions.includes(f) && !f.includes('.cache')) { t.fail('non-string-literal config used in ' + f + ':' + i) } }) @@ -105,8 +105,8 @@ test('check configs', function (t) { if (CONFS[c1].file.indexOf(lib) === 0) { t.ok(DOC[c1], 'should be documented ' + c1 + ' ' + CONFS[c1].file + ':' + CONFS[c1].line) - t.ok(types.indexOf(c1) !== -1, 'should be defined in npmconf ' + c1) - t.ok(defaults.indexOf(c1) !== -1, 'should have default in npmconf ' + c1) + t.ok(types.includes(c1), 'should be defined in npmconf ' + c1) + t.ok(defaults.includes(c1), 'should have default in npmconf ' + c1) } } diff --git a/test/tap/gist-short-shortcut-package.js b/test/tap/gist-short-shortcut-package.js index 601d53a827666..3f216eba853ef 100644 --- a/test/tap/gist-short-shortcut-package.js +++ b/test/tap/gist-short-shortcut-package.js @@ -33,7 +33,7 @@ test('gist-short-shortcut-package', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/gist-short-shortcut.js b/test/tap/gist-short-shortcut.js index 82c9ae17502dd..2f5b4f8c13cbd 100644 --- a/test/tap/gist-short-shortcut.js +++ b/test/tap/gist-short-shortcut.js @@ -30,7 +30,7 @@ test('gist-shortcut', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/gist-shortcut-package.js b/test/tap/gist-shortcut-package.js index 28e57357cc393..ee902f40cfa41 100644 --- a/test/tap/gist-shortcut-package.js +++ b/test/tap/gist-shortcut-package.js @@ -28,7 +28,7 @@ test('gist-shortcut-package', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/gist-shortcut.js b/test/tap/gist-shortcut.js index ca86d6bc55058..aa0ad5ce1e674 100644 --- a/test/tap/gist-shortcut.js +++ b/test/tap/gist-shortcut.js @@ -29,7 +29,7 @@ test('gist-shortcut', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/github-shortcut-package.js b/test/tap/github-shortcut-package.js index 444520308a245..40852569ec508 100644 --- a/test/tap/github-shortcut-package.js +++ b/test/tap/github-shortcut-package.js @@ -32,7 +32,7 @@ test('github-shortcut-package', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/gitlab-shortcut-package.js b/test/tap/gitlab-shortcut-package.js index 9b431ff7b66f0..40e7f686950dc 100644 --- a/test/tap/gitlab-shortcut-package.js +++ b/test/tap/gitlab-shortcut-package.js @@ -31,7 +31,7 @@ test('gitlab-shortcut-package', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/gitlab-shortcut.js b/test/tap/gitlab-shortcut.js index 344311b45f26c..2b50d0eb48a0f 100644 --- a/test/tap/gitlab-shortcut.js +++ b/test/tap/gitlab-shortcut.js @@ -28,7 +28,7 @@ test('gitlab-shortcut', function (t) { 'child_process': { 'execFile': function (cmd, args, options, cb) { process.nextTick(function () { - if (args.indexOf('clone') === -1) return cb(null, '', '') + if (!args.includes('clone')) return cb(null, '', '') var cloneUrl = cloneUrls.shift() if (cloneUrl) { t.is(args[args.length - 2], cloneUrl[0], cloneUrl[1]) diff --git a/test/tap/version-from-git.js b/test/tap/version-from-git.js index e63865a73378a..087402e6b3d5a 100644 --- a/test/tap/version-from-git.js +++ b/test/tap/version-from-git.js @@ -39,7 +39,7 @@ test('npm version from-git with a valid tag creates a new commit', function (t) function checkCommit (er, log, stderr) { t.ifError(er, 'git log ran without issue') t.notOk(stderr, 'no error output') - t.ok(log.indexOf(version) !== -1, 'commit was created') + t.ok(log.includes(version), 'commit was created') t.end() } }) @@ -95,8 +95,8 @@ test('npm version from-git strips tag-version-prefix', function (t) { function checkCommit (er, log, stderr) { t.ifError(er, 'git log ran without issue') t.notOk(stderr, 'no error output') - t.ok(log.indexOf(tag) === -1, 'commit should not include prefix') - t.ok(log.indexOf(version) !== -1, 'commit should include version') + t.ok(!log.includes(tag), 'commit should not include prefix') + t.ok(log.includes(version), 'commit should include version') t.end() } }) @@ -128,7 +128,7 @@ test('npm version from-git only strips tag-version-prefix if it is a prefix', fu function checkCommit (er, log, stderr) { t.ifError(er, 'git log ran without issue') t.notOk(stderr, 'no error output') - t.ok(log.indexOf(version) !== -1, 'commit should include the full version') + t.ok(log.includes(version), 'commit should include the full version') t.end() } })