File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,13 +42,20 @@ var prevTime;
4242
4343/**
4444 * Select a color.
45- *
45+ * @param { String } namespace
4646 * @return {Number }
4747 * @api private
4848 */
4949
50- function selectColor ( ) {
51- return exports . colors [ prevColor ++ % exports . colors . length ] ;
50+ function selectColor ( namespace ) {
51+ var hash = 0 , i ;
52+
53+ for ( i in namespace ) {
54+ hash = ( ( hash << 5 ) - hash ) + namespace . charCodeAt ( i ) ;
55+ hash |= 0 ; // Convert to 32bit integer
56+ }
57+
58+ return exports . colors [ Math . abs ( hash ) % exports . colors . length ] ;
5259}
5360
5461/**
@@ -81,7 +88,7 @@ function debug(namespace) {
8188
8289 // add the `color` if not set
8390 if ( null == self . useColors ) self . useColors = exports . useColors ( ) ;
84- if ( null == self . color && self . useColors ) self . color = selectColor ( ) ;
91+ if ( null == self . color && self . useColors ) self . color = selectColor ( namespace ) ;
8592
8693 var args = new Array ( arguments . length ) ;
8794 for ( var i = 0 ; i < args . length ; i ++ ) {
You can’t perform that action at this time.
0 commit comments