()
| 38953 | var prevTime; |
| 38954 | |
| 38955 | function debug() { |
| 38956 | // disabled? |
| 38957 | if (!debug.enabled) return; |
| 38958 | |
| 38959 | var self = debug; |
| 38960 | |
| 38961 | // set `diff` timestamp |
| 38962 | var curr = +new Date(); |
| 38963 | var ms = curr - (prevTime || curr); |
| 38964 | self.diff = ms; |
| 38965 | self.prev = prevTime; |
| 38966 | self.curr = curr; |
| 38967 | prevTime = curr; |
| 38968 | |
| 38969 | // turn the `arguments` into a proper Array |
| 38970 | var args = new Array(arguments.length); |
| 38971 | for (var i = 0; i < args.length; i++) { |
| 38972 | args[i] = arguments[i]; |
| 38973 | } |
| 38974 | |
| 38975 | args[0] = exports.coerce(args[0]); |
| 38976 | |
| 38977 | if ('string' !== typeof args[0]) { |
| 38978 | // anything else let's inspect with %O |
| 38979 | args.unshift('%O'); |
| 38980 | } |
| 38981 | |
| 38982 | // apply any `formatters` transformations |
| 38983 | var index = 0; |
| 38984 | args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { |
| 38985 | // if we encounter an escaped % then don't increase the array index |
| 38986 | if (match === '%%') return match; |
| 38987 | index++; |
| 38988 | var formatter = exports.formatters[format]; |
| 38989 | if ('function' === typeof formatter) { |
| 38990 | var val = args[index]; |
| 38991 | match = formatter.call(self, val); |
| 38992 | |
| 38993 | // now we need to remove `args[index]` since it's inlined in the `format` |
| 38994 | args.splice(index, 1); |
| 38995 | index--; |
| 38996 | } |
| 38997 | return match; |
| 38998 | }); |
| 38999 | |
| 39000 | // apply env-specific formatting (colors, etc.) |
| 39001 | exports.formatArgs.call(self, args); |
| 39002 | |
| 39003 | var logFn = debug.log || exports.log || console.log.bind(console); |
| 39004 | logFn.apply(self, args); |
| 39005 | } |
| 39006 | |
| 39007 | debug.namespace = namespace; |
| 39008 | debug.enabled = exports.enabled(namespace); |
no test coverage detected