* This is the common logic for both the Node.js and web browser * implementations of `debug()`.
(env)
| 2519 | */ |
| 2520 | |
| 2521 | function setup(env) { |
| 2522 | createDebug.debug = createDebug; |
| 2523 | createDebug["default"] = createDebug; |
| 2524 | createDebug.coerce = coerce; |
| 2525 | createDebug.disable = disable; |
| 2526 | createDebug.enable = enable; |
| 2527 | createDebug.enabled = enabled; |
| 2528 | createDebug.humanize = requireMs(); |
| 2529 | createDebug.destroy = destroy; |
| 2530 | Object.keys(env).forEach(function (key) { |
| 2531 | createDebug[key] = env[key]; |
| 2532 | }); |
| 2533 | |
| 2534 | /** |
| 2535 | * The currently active debug mode names, and names to skip. |
| 2536 | */ |
| 2537 | |
| 2538 | createDebug.names = []; |
| 2539 | createDebug.skips = []; |
| 2540 | |
| 2541 | /** |
| 2542 | * Map of special "%n" handling functions, for the debug "format" argument. |
| 2543 | * |
| 2544 | * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". |
| 2545 | */ |
| 2546 | createDebug.formatters = {}; |
| 2547 | |
| 2548 | /** |
| 2549 | * Selects a color for a debug namespace |
| 2550 | * @param {String} namespace The namespace string for the debug instance to be colored |
| 2551 | * @return {Number|String} An ANSI color code for the given namespace |
| 2552 | * @api private |
| 2553 | */ |
| 2554 | function selectColor(namespace) { |
| 2555 | var hash = 0; |
| 2556 | for (var i = 0; i < namespace.length; i++) { |
| 2557 | hash = (hash << 5) - hash + namespace.charCodeAt(i); |
| 2558 | hash |= 0; // Convert to 32bit integer |
| 2559 | } |
| 2560 | return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; |
| 2561 | } |
| 2562 | createDebug.selectColor = selectColor; |
| 2563 | |
| 2564 | /** |
| 2565 | * Create a debugger with the given `namespace`. |
| 2566 | * |
| 2567 | * @param {String} namespace |
| 2568 | * @return {Function} |
| 2569 | * @api public |
| 2570 | */ |
| 2571 | function createDebug(namespace) { |
| 2572 | var prevTime; |
| 2573 | var enableOverride = null; |
| 2574 | var namespacesCache; |
| 2575 | var enabledCache; |
| 2576 | function debug() { |
| 2577 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 2578 | args[_key] = arguments[_key]; |