Skip to content

Commit

Permalink
[Robustness] use array.prototype.join, array.prototype.map, `stri…
Browse files Browse the repository at this point in the history
…ng.prototype.split`, `array.prototype.slice`
  • Loading branch information
ljharb committed Sep 22, 2022
1 parent f88d449 commit 555e2f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions index.js
Expand Up @@ -5,7 +5,11 @@ var duplexer = require('duplexer');
var parser = require('tap-parser');
var sprintf = require('sprintf-js').sprintf;
var forEach = require('array.prototype.foreach');
var join = require('array.prototype.join');
var map = require('array.prototype.map');
var push = require('array.prototype.push');
var slice = require('array.prototype.slice');
var split = require('string.prototype.split');
var trim = require('string.prototype.trim');
var regexTester = require('safe-regex-test');

Expand All @@ -19,7 +23,7 @@ module.exports = function (opts) {
function trimWidth(s, ok) {
if (opts && opts.width && s.length > opts.width - 2) {
var more = ok ? 0 : 4;
return s.slice(0, opts.width - 5 - more) + '...';
return slice(s, 0, opts.width - 5 - more) + '...';
}
return s;
}
Expand Down Expand Up @@ -86,9 +90,13 @@ module.exports = function (opts) {
if (!test || test.assertions.length === 0) { return; }
var last = test.assertions[test.assertions.length - 1];
if (!last.ok) {
push(out, extra.split('\n').map(function (line) {
return ' ' + line;
}).join('\n') + '\n');
push(out, join(
map(
split(extra, '\n'),
function (line) { return ' ' + line; }
),
'\n'
) + '\n');
}
});

Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -14,13 +14,17 @@
},
"dependencies": {
"array.prototype.foreach": "^1.0.2",
"array.prototype.join": "^1.0.0",
"array.prototype.map": "^1.0.4",
"array.prototype.push": "^1.0.2",
"array.prototype.slice": "^1.0.0",
"defined": "^0.0.0",
"duplexer": "^0.1.2",
"minimist": "^1.2.6",
"npm-which": "^1.0.2",
"safe-regex-test": "^1.0.0",
"sprintf-js": "^1.1.2",
"string.prototype.split": "^1.0.6",
"string.prototype.trim": "^1.2.6",
"tap-parser": "^0.4.3",
"tape": "^5.6.1",
Expand Down

0 comments on commit 555e2f6

Please sign in to comment.