2
2
* Helpers.
3
3
*/
4
4
5
- var s = 1000
6
- var m = s * 60
7
- var h = m * 60
8
- var d = h * 24
9
- var y = d * 365.25
5
+ var s = 1000 ;
6
+ var m = s * 60 ;
7
+ var h = m * 60 ;
8
+ var d = h * 24 ;
9
+ var y = d * 365.25 ;
10
10
11
11
/**
12
12
* Parse or format the given `val`.
@@ -22,18 +22,19 @@ var y = d * 365.25
22
22
* @api public
23
23
*/
24
24
25
- module . exports = function ( val , options ) {
26
- options = options || { }
27
- var type = typeof val
25
+ module . exports = function ( val , options ) {
26
+ options = options || { } ;
27
+ var type = typeof val ;
28
28
if ( type === 'string' && val . length > 0 ) {
29
- return parse ( val )
29
+ return parse ( val ) ;
30
30
} else if ( type === 'number' && isNaN ( val ) === false ) {
31
- return options . long ?
32
- fmtLong ( val ) :
33
- fmtShort ( val )
31
+ return options . long ? fmtLong ( val ) : fmtShort ( val ) ;
34
32
}
35
- throw new Error ( 'val is not a non-empty string or a valid number. val=' + JSON . stringify ( val ) )
36
- }
33
+ throw new Error (
34
+ 'val is not a non-empty string or a valid number. val=' +
35
+ JSON . stringify ( val )
36
+ ) ;
37
+ } ;
37
38
38
39
/**
39
40
* Parse the given `str` and return milliseconds.
@@ -44,53 +45,55 @@ module.exports = function (val, options) {
44
45
*/
45
46
46
47
function parse ( str ) {
47
- str = String ( str )
48
+ str = String ( str ) ;
48
49
if ( str . length > 10000 ) {
49
- return
50
+ return ;
50
51
}
51
- var match = / ^ ( (?: \d + ) ? \. ? \d + ) * ( m i l l i s e c o n d s ? | m s e c s ? | m s | s e c o n d s ? | s e c s ? | s | m i n u t e s ? | m i n s ? | m | h o u r s ? | h r s ? | h | d a y s ? | d | y e a r s ? | y r s ? | y ) ? $ / i. exec ( str )
52
+ var match = / ^ ( (?: \d + ) ? \. ? \d + ) * ( m i l l i s e c o n d s ? | m s e c s ? | m s | s e c o n d s ? | s e c s ? | s | m i n u t e s ? | m i n s ? | m | h o u r s ? | h r s ? | h | d a y s ? | d | y e a r s ? | y r s ? | y ) ? $ / i. exec (
53
+ str
54
+ ) ;
52
55
if ( ! match ) {
53
- return
56
+ return ;
54
57
}
55
- var n = parseFloat ( match [ 1 ] )
56
- var type = ( match [ 2 ] || 'ms' ) . toLowerCase ( )
58
+ var n = parseFloat ( match [ 1 ] ) ;
59
+ var type = ( match [ 2 ] || 'ms' ) . toLowerCase ( ) ;
57
60
switch ( type ) {
58
61
case 'years' :
59
62
case 'year' :
60
63
case 'yrs' :
61
64
case 'yr' :
62
65
case 'y' :
63
- return n * y
66
+ return n * y ;
64
67
case 'days' :
65
68
case 'day' :
66
69
case 'd' :
67
- return n * d
70
+ return n * d ;
68
71
case 'hours' :
69
72
case 'hour' :
70
73
case 'hrs' :
71
74
case 'hr' :
72
75
case 'h' :
73
- return n * h
76
+ return n * h ;
74
77
case 'minutes' :
75
78
case 'minute' :
76
79
case 'mins' :
77
80
case 'min' :
78
81
case 'm' :
79
- return n * m
82
+ return n * m ;
80
83
case 'seconds' :
81
84
case 'second' :
82
85
case 'secs' :
83
86
case 'sec' :
84
87
case 's' :
85
- return n * s
88
+ return n * s ;
86
89
case 'milliseconds' :
87
90
case 'millisecond' :
88
91
case 'msecs' :
89
92
case 'msec' :
90
93
case 'ms' :
91
- return n
94
+ return n ;
92
95
default :
93
- return undefined
96
+ return undefined ;
94
97
}
95
98
}
96
99
@@ -104,18 +107,18 @@ function parse(str) {
104
107
105
108
function fmtShort ( ms ) {
106
109
if ( ms >= d ) {
107
- return Math . round ( ms / d ) + 'd'
110
+ return Math . round ( ms / d ) + 'd' ;
108
111
}
109
112
if ( ms >= h ) {
110
- return Math . round ( ms / h ) + 'h'
113
+ return Math . round ( ms / h ) + 'h' ;
111
114
}
112
115
if ( ms >= m ) {
113
- return Math . round ( ms / m ) + 'm'
116
+ return Math . round ( ms / m ) + 'm' ;
114
117
}
115
118
if ( ms >= s ) {
116
- return Math . round ( ms / s ) + 's'
119
+ return Math . round ( ms / s ) + 's' ;
117
120
}
118
- return ms + 'ms'
121
+ return ms + 'ms' ;
119
122
}
120
123
121
124
/**
@@ -131,7 +134,7 @@ function fmtLong(ms) {
131
134
plural ( ms , h , 'hour' ) ||
132
135
plural ( ms , m , 'minute' ) ||
133
136
plural ( ms , s , 'second' ) ||
134
- ms + ' ms'
137
+ ms + ' ms' ;
135
138
}
136
139
137
140
/**
@@ -140,10 +143,10 @@ function fmtLong(ms) {
140
143
141
144
function plural ( ms , n , name ) {
142
145
if ( ms < n ) {
143
- return
146
+ return ;
144
147
}
145
148
if ( ms < n * 1.5 ) {
146
- return Math . floor ( ms / n ) + ' ' + name
149
+ return Math . floor ( ms / n ) + ' ' + name ;
147
150
}
148
- return Math . ceil ( ms / n ) + ' ' + name + 's'
151
+ return Math . ceil ( ms / n ) + ' ' + name + 's' ;
149
152
}
0 commit comments