-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.ts
59 lines (54 loc) · 1.33 KB
/
vue.ts
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
50
51
52
53
54
55
56
57
58
59
import { isRef, unref, isReactive, toValue, isReadonly } from 'vue'
import type { LoggerFunction } from './types'
export const VueLogFn: LoggerFunction = function (
method: 'log' | 'debug' | 'info' | 'warn' | 'error' | 'success' | 'critical',
message: any,
...optionalParams: any[]
) {
let logFn: (message: any, ...optionalParams: any[]) => void
switch (method) {
case 'log':
logFn = console.log
break
case 'debug':
logFn = console.debug
break
case 'info':
logFn = console.info
break
case 'warn':
logFn = console.warn
break
case 'error':
logFn = console.error
break
case 'critical':
logFn = console.error
break
default:
logFn = console.log
}
if (optionalParams) {
const parsedParams: any[] = []
let msg = ''
optionalParams.forEach((param) => {
if (isRef(param)) {
if (isReadonly(param)) {
msg = '(computed):'
parsedParams.push(msg, unref(param))
} else {
msg = '(ref):'
parsedParams.push(msg, unref(param))
}
} else if (isReactive(param)) {
msg = '(reactive):'
parsedParams.push(msg, toValue(param))
} else {
parsedParams.push(param)
}
})
logFn(message, ...parsedParams)
} else {
logFn(message)
}
}