Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Array.prototype.includes() to simplify code logic #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

w2xi
Copy link

@w2xi w2xi commented Feb 28, 2024

raw code:

if (wantedPM !== 'npm' && wantedPM !== 'cnpm' && wantedPM !== 'pnpm' && wantedPM !== 'yarn' && wantedPM !== 'bun') {
  // ...
}

for perhaps, use Array.prototype.includes() to be able to simplify code logic:

if (!['npm', 'cnpm', 'pnpm', 'yarn', 'bun'].includes(wantedPM)) {
  // ...
}

bin.js Outdated
@@ -18,7 +18,7 @@ if (argv.length === 0) {
process.exit(1)
}
const wantedPM = argv[0]
if (wantedPM !== 'npm' && wantedPM !== 'cnpm' && wantedPM !== 'pnpm' && wantedPM !== 'yarn' && wantedPM !== 'bun') {
if (!['npm', 'cnpm', 'pnpm', 'yarn', 'bun'].includes(wantedPM)) {
console.log(`"${wantedPM}" is not a valid package manager. Available package managers are: npm, cnpm, pnpm, yarn or bun.`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, then reuse the array in the error message too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will do some changes soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants