console.js 797 B

12345678910111213141516171819202122232425262728293031
  1. let _console;
  2. let method;
  3. if (typeof console !== 'undefined') {
  4. _console = console;
  5. } else if (typeof global !== 'undefined' && global.console) {
  6. _console = global.console;
  7. } else if (typeof window !== 'undefined' && window.console) {
  8. _console = window.console;
  9. } else {
  10. _console = {};
  11. }
  12. const noop = function () {};
  13. const methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
  14. let {
  15. length
  16. } = methods;
  17. while (length--) {
  18. method = methods[length];
  19. if (!console[method]) {
  20. _console[method] = noop;
  21. }
  22. }
  23. _console.methods = methods;
  24. export default _console;