mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-11 12:21:37 +02:00
Parse duration strings for /fseek and /seek (#565)
This commit is contained in:
parent
03d5cfffd1
commit
6c00727a4a
7 changed files with 58 additions and 13 deletions
21
src/utils/duration-string-to-seconds.ts
Normal file
21
src/utils/duration-string-to-seconds.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import parse from 'parse-duration';
|
||||
|
||||
/**
|
||||
* Parse duration strings to seconds.
|
||||
* @param str any common duration format, like 1m or 1hr 30s. If the input is a number it's assumed to be in seconds.
|
||||
* @returns seconds
|
||||
*/
|
||||
const durationStringToSeconds = (str: string) => {
|
||||
let seconds;
|
||||
const isInputSeconds = Boolean(/\d+$/.exec(str));
|
||||
|
||||
if (isInputSeconds) {
|
||||
seconds = Number.parseInt(str, 10);
|
||||
} else {
|
||||
seconds = parse(str) / 1000;
|
||||
}
|
||||
|
||||
return seconds;
|
||||
};
|
||||
|
||||
export default durationStringToSeconds;
|
Loading…
Add table
Add a link
Reference in a new issue