Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 81fc405

Browse files
38elementsboneskull
authored andcommitted
remove unused code in ms module
* Remove unused argument of lib/ms * Remove unnecessary comment
1 parent b441749 commit 81fc405

File tree

2 files changed

+4
-65
lines changed

2 files changed

+4
-65
lines changed

lib/ms.js

+4-44
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ var y = d * 365.25;
1313
/**
1414
* Parse or format the given `val`.
1515
*
16-
* Options:
17-
*
18-
* - `long` verbose formatting [false]
19-
*
2016
* @api public
2117
* @param {string|number} val
22-
* @param {Object} options
2318
* @return {string|number}
2419
*/
25-
module.exports = function (val, options) {
26-
options = options || {};
20+
module.exports = function (val) {
2721
if (typeof val === 'string') {
2822
return parse(val);
2923
}
30-
// https://github.com/mochajs/mocha/pull/1035
31-
return options['long'] ? longFormat(val) : shortFormat(val);
24+
return format(val);
3225
};
3326

3427
/**
@@ -74,13 +67,13 @@ function parse (str) {
7467
}
7568

7669
/**
77-
* Short format for `ms`.
70+
* Format for `ms`.
7871
*
7972
* @api private
8073
* @param {number} ms
8174
* @return {string}
8275
*/
83-
function shortFormat (ms) {
76+
function format (ms) {
8477
if (ms >= d) {
8578
return Math.round(ms / d) + 'd';
8679
}
@@ -95,36 +88,3 @@ function shortFormat (ms) {
9588
}
9689
return ms + 'ms';
9790
}
98-
99-
/**
100-
* Long format for `ms`.
101-
*
102-
* @api private
103-
* @param {number} ms
104-
* @return {string}
105-
*/
106-
function longFormat (ms) {
107-
return plural(ms, d, 'day') ||
108-
plural(ms, h, 'hour') ||
109-
plural(ms, m, 'minute') ||
110-
plural(ms, s, 'second') ||
111-
ms + ' ms';
112-
}
113-
114-
/**
115-
* Pluralization helper.
116-
*
117-
* @api private
118-
* @param {number} ms
119-
* @param {number} n
120-
* @param {string} name
121-
*/
122-
function plural (ms, n, name) {
123-
if (ms < n) {
124-
return;
125-
}
126-
if (ms < n * 1.5) {
127-
return Math.floor(ms / n) + ' ' + name;
128-
}
129-
return Math.ceil(ms / n) + ' ' + name + 's';
130-
}

test/unit/ms.spec.js

-21
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,24 @@ describe('.ms()', function () {
2121
it('should return short format', function () {
2222
expect(ms(2000)).to.equal('2s');
2323
});
24-
25-
it('should return long format', function () {
26-
expect(ms(2000, { long: true })).to.equal('2 seconds');
27-
expect(ms(1000, { long: true })).to.equal('1 second');
28-
expect(ms(1010, { long: true })).to.equal('1 second');
29-
});
3024
});
3125

3226
describe('minutes representation', function () {
3327
it('should return short format', function () {
3428
expect(ms(time.minutes(1))).to.equal('1m');
3529
});
36-
37-
it('should return long format', function () {
38-
expect(ms(time.minutes(1), { long: true })).to.equal('1 minute');
39-
expect(ms(time.minutes(3), { long: true })).to.equal('3 minutes');
40-
});
4130
});
4231

4332
describe('hours representation', function () {
4433
it('should return short format', function () {
4534
expect(ms(time.hours(1))).to.equal('1h');
4635
});
47-
48-
it('should return long format', function () {
49-
expect(ms(time.hours(1), { long: true })).to.equal('1 hour');
50-
expect(ms(time.hours(3), { long: true })).to.equal('3 hours');
51-
});
5236
});
5337

5438
describe('days representation', function () {
5539
it('should return short format', function () {
5640
expect(ms(time.days(1))).to.equal('1d');
5741
});
58-
59-
it('should return long format', function () {
60-
expect(ms(time.days(1), { long: true })).to.equal('1 day');
61-
expect(ms(time.days(3), { long: true })).to.equal('3 days');
62-
});
6342
});
6443

6544
describe('Getting string value', function () {

0 commit comments

Comments
 (0)