Skip to content

Commit

Permalink
errors: refactor invalidArgType()
Browse files Browse the repository at this point in the history
`invalidArgType()` uses `includes()` in two places where `startsWith()`
and `endsWith()` are more appropriate (at least in my opinion). Switch
to those more specific functions.
  • Loading branch information
Trott committed Sep 21, 2017
1 parent 66e45b8 commit adbed02
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function invalidArgType(name, expected, actual) {

// determiner: 'must be' or 'must not be'
let determiner;
if (expected.includes('not ')) {
if (typeof expected === 'string' && expected.startsWith('not ')) {
determiner = 'must not be';
expected = expected.split('not ')[1];
} else {
Expand All @@ -320,7 +320,7 @@ function invalidArgType(name, expected, actual) {
if (Array.isArray(name)) {
var names = name.map((val) => `"${val}"`).join(', ');
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
} else if (name.includes(' argument')) {
} else if (name.endsWith(' argument')) {
// for the case like 'first argument'
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
} else {
Expand Down

0 comments on commit adbed02

Please sign in to comment.