From 709a09efd74ee4a83fbfbe0236fab3443c65cda0 Mon Sep 17 00:00:00 2001 From: 38elements <38elements@users.noreply.github.com> Date: Thu, 7 Dec 2017 09:16:51 +0900 Subject: [PATCH] remove unused code in ms module * Remove unused argument of lib/ms * Remove unnecessary comment --- lib/ms.js | 48 ++++---------------------------------------- test/unit/ms.spec.js | 21 ------------------- 2 files changed, 4 insertions(+), 65 deletions(-) diff --git a/lib/ms.js b/lib/ms.js index 9590856052..2fdcaf3242 100644 --- a/lib/ms.js +++ b/lib/ms.js @@ -13,22 +13,15 @@ var y = d * 365.25; /** * Parse or format the given `val`. * - * Options: - * - * - `long` verbose formatting [false] - * * @api public * @param {string|number} val - * @param {Object} options * @return {string|number} */ -module.exports = function (val, options) { - options = options || {}; +module.exports = function (val) { if (typeof val === 'string') { return parse(val); } - // https://github.com/mochajs/mocha/pull/1035 - return options['long'] ? longFormat(val) : shortFormat(val); + return format(val); }; /** @@ -74,13 +67,13 @@ function parse (str) { } /** - * Short format for `ms`. + * Format for `ms`. * * @api private * @param {number} ms * @return {string} */ -function shortFormat (ms) { +function format (ms) { if (ms >= d) { return Math.round(ms / d) + 'd'; } @@ -95,36 +88,3 @@ function shortFormat (ms) { } return ms + 'ms'; } - -/** - * Long format for `ms`. - * - * @api private - * @param {number} ms - * @return {string} - */ -function longFormat (ms) { - return plural(ms, d, 'day') || - plural(ms, h, 'hour') || - plural(ms, m, 'minute') || - plural(ms, s, 'second') || - ms + ' ms'; -} - -/** - * Pluralization helper. - * - * @api private - * @param {number} ms - * @param {number} n - * @param {string} name - */ -function plural (ms, n, name) { - if (ms < n) { - return; - } - if (ms < n * 1.5) { - return Math.floor(ms / n) + ' ' + name; - } - return Math.ceil(ms / n) + ' ' + name + 's'; -} diff --git a/test/unit/ms.spec.js b/test/unit/ms.spec.js index e7b1d358be..0844391258 100644 --- a/test/unit/ms.spec.js +++ b/test/unit/ms.spec.js @@ -21,45 +21,24 @@ describe('.ms()', function () { it('should return short format', function () { expect(ms(2000)).to.equal('2s'); }); - - it('should return long format', function () { - expect(ms(2000, { long: true })).to.equal('2 seconds'); - expect(ms(1000, { long: true })).to.equal('1 second'); - expect(ms(1010, { long: true })).to.equal('1 second'); - }); }); describe('minutes representation', function () { it('should return short format', function () { expect(ms(time.minutes(1))).to.equal('1m'); }); - - it('should return long format', function () { - expect(ms(time.minutes(1), { long: true })).to.equal('1 minute'); - expect(ms(time.minutes(3), { long: true })).to.equal('3 minutes'); - }); }); describe('hours representation', function () { it('should return short format', function () { expect(ms(time.hours(1))).to.equal('1h'); }); - - it('should return long format', function () { - expect(ms(time.hours(1), { long: true })).to.equal('1 hour'); - expect(ms(time.hours(3), { long: true })).to.equal('3 hours'); - }); }); describe('days representation', function () { it('should return short format', function () { expect(ms(time.days(1))).to.equal('1d'); }); - - it('should return long format', function () { - expect(ms(time.days(1), { long: true })).to.equal('1 day'); - expect(ms(time.days(3), { long: true })).to.equal('3 days'); - }); }); describe('Getting string value', function () {