Skip to content

Commit

Permalink
remove unused code in ms module
Browse files Browse the repository at this point in the history
* Remove unused argument of lib/ms

* Remove unnecessary comment
  • Loading branch information
38elements authored and boneskull committed Dec 7, 2017
1 parent b954f69 commit 709a09e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
48 changes: 4 additions & 44 deletions lib/ms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down Expand Up @@ -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';
}
Expand All @@ -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';
}
21 changes: 0 additions & 21 deletions test/unit/ms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 709a09e

Please sign in to comment.