Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ var prevTime;

/**
* Select a color.
*
* @param {String} namespace
* @return {Number}
* @api private
*/

function selectColor() {
return exports.colors[prevColor++ % exports.colors.length];
function selectColor(namespace) {
var hash = 0, i;

for (i in namespace) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this algorithm for somewhere that we need to give credit for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}

return exports.colors[Math.abs(hash) % exports.colors.length];
}

/**
Expand Down Expand Up @@ -81,7 +88,7 @@ function debug(namespace) {

// add the `color` if not set
if (null == self.useColors) self.useColors = exports.useColors();
if (null == self.color && self.useColors) self.color = selectColor();
if (null == self.color && self.useColors) self.color = selectColor(namespace);

var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
Expand Down