Skip to content

Commit adbed02

Browse files
committed
errors: refactor invalidArgType()
`invalidArgType()` uses `includes()` in two places where `startsWith()` and `endsWith()` are more appropriate (at least in my opinion). Switch to those more specific functions.
1 parent 66e45b8 commit adbed02

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/internal/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function invalidArgType(name, expected, actual) {
309309

310310
// determiner: 'must be' or 'must not be'
311311
let determiner;
312-
if (expected.includes('not ')) {
312+
if (typeof expected === 'string' && expected.startsWith('not ')) {
313313
determiner = 'must not be';
314314
expected = expected.split('not ')[1];
315315
} else {
@@ -320,7 +320,7 @@ function invalidArgType(name, expected, actual) {
320320
if (Array.isArray(name)) {
321321
var names = name.map((val) => `"${val}"`).join(', ');
322322
msg = `The ${names} arguments ${determiner} ${oneOf(expected, 'type')}`;
323-
} else if (name.includes(' argument')) {
323+
} else if (name.endsWith(' argument')) {
324324
// for the case like 'first argument'
325325
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
326326
} else {

0 commit comments

Comments
 (0)