UNPKG

c0lor

Version:
53 lines (46 loc) 1.04 kB
var O, rgbPrototype, round, toByte, validRgbEl; O = require("ut1l/create/object"); round = Math.round; toByte = function(d) { if (d != null) { return round(d * 255); } }; validRgbEl = function(x) { return (isFinite(x)) && (0 <= x && x <= 1); }; rgbPrototype = { RGB: function(T) { if (T == null) { T = require("./RGBInt")(); } T.R = toByte(this.r); T.G = toByte(this.g); T.B = toByte(this.b); return T; }, set: function(r, g, b) { this.r = r; this.g = g; this.b = b; return this; }, isDefined: function() { return (this.r != null) && (this.g != null) && (this.b != null); }, isValid: function() { return this.isDefined() && (validRgbEl(this.r)) && (validRgbEl(this.g)) && (validRgbEl(this.b)); }, toString: function() { return "r=" + this.r + ", g=" + this.g + ", b=" + this.b; } }; module.exports = O({ extendRgb: function(f) { return f(rgbPrototype); } }, (function(r, g, b) { this.r = r; this.g = g; this.b = b; }), rgbPrototype);