Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rechecking unchanged variable in .toString() #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
55 changes: 25 additions & 30 deletions tinycolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ tinycolor.prototype = {
var formatSet = !!format;
format = format || this._format;

var formattedString = false;
var hasAlpha = this._a < 1 && this._a >= 0;
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");

Expand All @@ -179,35 +178,26 @@ tinycolor.prototype = {
}
return this.toRgbString();
}
if (format === "rgb") {
formattedString = this.toRgbString();
switch(format){
case 'rgb':
return this.toRgbString();
case "prgb":
return this.toPercentageRgbString();
case "hex3":
return this.toHexString(true);
case "hex4":
return this.toHex8String(true);
case "hex8":
return this.toHex8String();
case "name":
return this.toName() || this.toHexString();
case "hsl":
return this.toHslString();
case "hsv":
return this.toHsvString();
// case "hex": case "hex6": case unknown:
default: return this.toHexString();
}
if (format === "prgb") {
formattedString = this.toPercentageRgbString();
}
if (format === "hex" || format === "hex6") {
formattedString = this.toHexString();
}
if (format === "hex3") {
formattedString = this.toHexString(true);
}
if (format === "hex4") {
formattedString = this.toHex8String(true);
}
if (format === "hex8") {
formattedString = this.toHex8String();
}
if (format === "name") {
formattedString = this.toName();
}
if (format === "hsl") {
formattedString = this.toHslString();
}
if (format === "hsv") {
formattedString = this.toHsvString();
}

return formattedString || this.toHexString();
},
clone: function() {
return tinycolor(this.toString());
Expand Down Expand Up @@ -1004,9 +994,14 @@ function bound01(n, max) {
return (n % max) / parseFloat(max);
}

// Force a numeric value within the inclusive lower and upper bounds
var clamp = function(lower, upper, numeric){
return mathMin(upper, mathMax(lower, numeric));
};

// Force a number between 0 and 1
function clamp01(val) {
return mathMin(1, mathMax(0, val));
return clamp(0, 1, val);
}

// Parse a base-16 hex value into a base-10 integer
Expand Down