-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathtimer.ts
More file actions
49 lines (43 loc) · 853 Bytes
/
timer.ts
File metadata and controls
49 lines (43 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Copyright (c) 2021 Hengyang Zhang
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
import { getUsedStorage } from "@db/memory-detector"
import { openLog, closeLog } from "./logger"
/**
* Show the memory info
*
* @since 0.0.9
*/
export function showMemory() {
getUsedStorage().then(({ used, total }) => {
console.log(`\t${used} / ${total} = ${Math.round(used * 100.0 / total * 100) / 100}%`)
})
return 'Memory used:'
}
export type Timer = {
openLog: () => string
closeLog: () => string
showMemory: () => void
}
/**
* @since 0.0.8
*/
const timer = {
openLog,
closeLog,
showMemory
} as Timer
declare global {
interface Window {
timer: Timer
}
}
/**
* Manually open and close the log
*
* @since 0.0.8
*/
window.timer = timer