-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
23 lines (20 loc) · 996 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"use strict";
module.exports = function (timeString) {
let timeArray = timeString.split(":");
if (timeArray.some((val) => Number.isNaN(Number(val))))
throw new TypeError(
'time-to-seconds: wrong argument type - something else than a number string in format "number", "number:number" or "number:number:number" was passed. See documentation for more information on argument formatting: https://www.npmjs.com/package/time-to-seconds.'
);
switch (timeArray.length) {
case 3:
return +timeArray[0] * 3600 + +timeArray[1] * 60 + +timeArray[2];
case 2:
return +timeArray[0] * 60 + +timeArray[1];
case 1:
return +timeArray[0];
default:
throw new TypeError(
'time-to-seconds: too many colons - make sure the function argument is a number string in format "number", "number:number" or "number:number:number". See documentation for more information on argument formatting: https://www.npmjs.com/package/time-to-seconds.'
);
}
};