UNPKG
sec
Version:
latest (2.0.0)
2.0.0
1.0.0
Convert a time string to seconds: `'00:22:17'` → `1337`
github.com/sindresorhus/sec
sindresorhus/sec
sec
/
index.js
13 lines
(10 loc)
•
246 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
export
default
function
toSeconds
(
string
) {
const
parts =
string
.
split
(
':'
);
let
seconds =
0
;
let
mininutes =
1
;
while
(parts.
length
>
0
) { seconds += mininutes *
Number
.
parseInt
(parts.
pop
(),
10
); mininutes *=
60
; }
return
seconds; }