From 555e2f626d374d5777e57b1948bdc154449e7bcb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 22 Sep 2022 15:00:36 -0700 Subject: [PATCH] [Robustness] use `array.prototype.join`, `array.prototype.map`, `string.prototype.split`, `array.prototype.slice` --- index.js | 16 ++++++++++++---- package.json | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index fde199a..86fd080 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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; } @@ -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'); } }); diff --git a/package.json b/package.json index 7abdb50..580cc37 100644 --- a/package.json +++ b/package.json @@ -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",