| 11726 | let enabledCache; |
| 11727 | |
| 11728 | function debug(...args) { |
| 11729 | // Disabled? |
| 11730 | if (!debug.enabled) { |
| 11731 | return; |
| 11732 | } |
| 11733 | |
| 11734 | const self = debug; |
| 11735 | |
| 11736 | // Set `diff` timestamp |
| 11737 | const curr = Number(new Date()); |
| 11738 | const ms = curr - (prevTime || curr); |
| 11739 | self.diff = ms; |
| 11740 | self.prev = prevTime; |
| 11741 | self.curr = curr; |
| 11742 | prevTime = curr; |
| 11743 | |
| 11744 | args[0] = createDebug.coerce(args[0]); |
| 11745 | |
| 11746 | if (typeof args[0] !== 'string') { |
| 11747 | // Anything else let's inspect with %O |
| 11748 | args.unshift('%O'); |
| 11749 | } |
| 11750 | |
| 11751 | // Apply any `formatters` transformations |
| 11752 | let index = 0; |
| 11753 | args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { |
| 11754 | // If we encounter an escaped % then don't increase the array index |
| 11755 | if (match === '%%') { |
| 11756 | return '%'; |
| 11757 | } |
| 11758 | index++; |
| 11759 | const formatter = createDebug.formatters[format]; |
| 11760 | if (typeof formatter === 'function') { |
| 11761 | const val = args[index]; |
| 11762 | match = formatter.call(self, val); |
| 11763 | |
| 11764 | // Now we need to remove `args[index]` since it's inlined in the `format` |
| 11765 | args.splice(index, 1); |
| 11766 | index--; |
| 11767 | } |
| 11768 | return match; |
| 11769 | }); |
| 11770 | |
| 11771 | // Apply env-specific formatting (colors, etc.) |
| 11772 | createDebug.formatArgs.call(self, args); |
| 11773 | |
| 11774 | const logFn = self.log || createDebug.log; |
| 11775 | logFn.apply(self, args); |
| 11776 | } |
| 11777 | |
| 11778 | debug.namespace = namespace; |
| 11779 | debug.useColors = createDebug.useColors(); |