-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathdev-warning.js
45 lines (34 loc) · 1.15 KB
/
dev-warning.js
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
// @flow
const isProduction: boolean = process.env.NODE_ENV === 'production';
// not replacing newlines (which \s does)
const spacesAndTabs: RegExp = /[ \t]{2,}/g;
// using .trim() to clear the any newlines before the first text and after last text
const clean = (value: string) => value.replace(spacesAndTabs, ' ').trim();
const getDevMessage = (message: string) =>
clean(`
%creact-beautiful-dnd
%c${clean(message)}
%c👷 This is a development only message. It will be removed in production builds.
`);
export const getFormattedMessage = (message: string): string[] => [
getDevMessage(message),
// title (green400)
'color: #00C584; font-size: 1.2em; font-weight: bold;',
// message
'line-height: 1.5',
// footer (purple300)
'color: #723874;',
];
const isDisabledFlag: string = '__react-beautiful-dnd-disable-dev-warnings';
export const warning = (message: string) => {
// no warnings in production
if (isProduction) {
return;
}
// manual opt out of warnings
if (typeof window !== 'undefined' && window[isDisabledFlag]) {
return;
}
// eslint-disable-next-line no-console
console.warn(...getFormattedMessage(message));
};