Eduard Kuzmenko
3 years ago
34 changed files with 98 additions and 111 deletions
@ -0,0 +1,4 @@ |
|||||||
|
export default function findAndSplice<T>(array: Array<T>, verify: (value: T, index?: number, array?: Array<T>) => boolean) { |
||||||
|
const index = array.findIndex(verify); |
||||||
|
return index !== -1 ? array.splice(index, 1)[0] : undefined; |
||||||
|
}; |
@ -0,0 +1,9 @@ |
|||||||
|
export default function randomize<T extends ArrayBufferView>(arr: T) { |
||||||
|
if(crypto && 'getRandomValues' in crypto) { |
||||||
|
crypto.getRandomValues(arr); |
||||||
|
} else { |
||||||
|
throw new Error('NO_SECURE_RANDOM'); |
||||||
|
} |
||||||
|
|
||||||
|
return arr; |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
export default function toHHMMSS(str: string | number, leadZero = false) { |
||||||
|
const sec_num = parseInt(str + '', 10); |
||||||
|
const hours = Math.floor(sec_num / 3600); |
||||||
|
let minutes: any = Math.floor((sec_num - (hours * 3600)) / 60); |
||||||
|
let seconds: any = sec_num - (hours * 3600) - (minutes * 60); |
||||||
|
|
||||||
|
if(hours) leadZero = true; |
||||||
|
if(minutes < 10) minutes = leadZero ? "0" + minutes : minutes; |
||||||
|
if(seconds < 10) seconds = "0" + seconds; |
||||||
|
return (hours ? /* ('0' + hours).slice(-2) */hours + ':' : '') + minutes + ':' + seconds; |
||||||
|
} |
Loading…
Reference in new issue