-
Notifications
You must be signed in to change notification settings - Fork 178
/
warning.ts
42 lines (35 loc) · 993 Bytes
/
warning.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
/* eslint-disable no-console */
let warned: Record<string, boolean> = {};
export function warning(valid: boolean, message: string) {
// Support uglify
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
console.error(`Warning: ${message}`);
}
}
export function note(valid: boolean, message: string) {
// Support uglify
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
console.warn(`Note: ${message}`);
}
}
export function resetWarned() {
warned = {};
}
export function call(
method: (valid: boolean, message: string) => void,
valid: boolean,
message: string,
) {
if (!valid && !warned[message]) {
method(false, message);
warned[message] = true;
}
}
export function warningOnce(valid: boolean, message: string) {
call(warning, valid, message);
}
export function noteOnce(valid: boolean, message: string) {
call(note, valid, message);
}
export default warningOnce;
/* eslint-enable */