MCPcopy Index your code
hub / github.com/debug-js/debug / useColors

Function useColors

src/browser.js:115–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

113
114// eslint-disable-next-line complexity
115function useColors() {
116 // NB: In an Electron preload script, document will be defined but not fully
117 // initialized. Since we know we're in Chrome, we'll just detect this case
118 // explicitly
119 if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
120 return true;
121 }
122
123 // Internet Explorer and Edge do not support colors.
124 if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
125 return false;
126 }
127
128 let m;
129
130 // Is webkit? http://stackoverflow.com/a/16459606/376773
131 // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
132 // eslint-disable-next-line no-return-assign
133 return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
134 // Is firebug? http://stackoverflow.com/a/398120/376773
135 (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
136 // Is firefox >= v31?
137 // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
138 (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
139 // Double check webkit in userAgent just in case we are in a worker
140 (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
141}
142
143/**
144 * Colorize log arguments if enabled.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…