Global.String.prototype.toHexColor ()
converts a string into a hexadecimal color representation (e.g. "ffcc33"). also knows how to convert a color string like "rgb (255, 204, 51)".

  • Returns
    String the resulting hex color (w/o "#")
Sourcecode in /home/hannes/helma/modules/core/String.js:
225:   String.prototype.toHexColor = function() {
226:       if (this.startsWith("rgb")) {
227:           res.push();
228:           var col = this.replace(/[^0-9,]/g, String.NULL);
229:           var parts = col.split(",");
230:           for (var i in parts) {
231:               var num = parseInt(parts[i], 10);
232:               var hex = num.toString(16);
233:               res.write(hex.pad("0", 2, String.LEFT));
234:          }
235:          return res.pop();
236:      }
237:      var col = this.replace(new RegExp(String.HEXPATTERN.source), String.NULL);
238:      return col.toLowerCase().pad("0", 6, String.LEFT);
239:  }