Skip to content

Commit 5489eaf

Browse files
committed
Use String.endsWith shim
1 parent 3361aac commit 5489eaf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/assert/assertion_error.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const { codes: {
88
ERR_INVALID_ARG_TYPE
99
} } = require('../errors');
1010

11+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
12+
function endsWith(str, search, this_len) {
13+
if (this_len === undefined || this_len > str.length) {
14+
this_len = str.length;
15+
}
16+
return str.substring(this_len - search.length, this_len) === search;
17+
}
18+
1119
let blue = '';
1220
let green = '';
1321
let red = '';
@@ -230,7 +238,7 @@ function createErrDiff(actual, expected, operator) {
230238
// a trailing comma. In that case it is actually identical and we should
231239
// mark it as such.
232240
let divergingLines = actualLine !== expectedLine &&
233-
(!actualLine.endsWith(',') ||
241+
(!endsWith(actualLine, ',') ||
234242
actualLine.slice(0, -1) !== expectedLine);
235243
// If the expected line has a trailing comma but is otherwise identical,
236244
// add a comma at the end of the actual line. Otherwise the output could
@@ -242,7 +250,7 @@ function createErrDiff(actual, expected, operator) {
242250
// ]
243251
//
244252
if (divergingLines &&
245-
expectedLine.endsWith(',') &&
253+
endsWith(expectedLine, ',') &&
246254
expectedLine.slice(0, -1) === actualLine) {
247255
divergingLines = false;
248256
actualLine += ',';

internal/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ createErrorType('ERR_INVALID_ARG_TYPE',
102102
}
103103

104104
let msg;
105-
if (name.endsWith(' argument')) {
105+
if (endsWith(name, ' argument')) {
106106
// For cases like 'first argument'
107107
msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
108108
} else {

0 commit comments

Comments
 (0)