Skip to content

Commit

Permalink
fix: fix number check issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yibn2008 committed Nov 18, 2021
1 parent 2a20559 commit 6e3f8b1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ function find (by, value, strict) {
if (!(by in findBy)) {
reject(new Error(`do not support find by "${by}"`))
} else {
if (by === 'pid' && typeof value !== 'number') { reject(new Error('pid must be a number')) } else if (by === 'port' && typeof value !== 'number') { reject(new Error('port must be a number')) } else { findBy[by](value, strict).then(resolve, reject) }
const isNumber = /^\d+$/.test(value)
if (by === 'pid' && !isNumber) {
reject(new Error('pid must be a number'))
} else if (by === 'port' && !isNumber) {
reject(new Error('port must be a number'))
} else {
findBy[by](value, strict).then(resolve, reject)
}
}
})
}
Expand Down

0 comments on commit 6e3f8b1

Please sign in to comment.