Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ color.toHex8String(); // "#ff0000ff"
var color = tinycolor("red");
color.toRgb(); // { r: 255, g: 0, b: 0, a: 1 }
```
### toRgbValues
Like `toRgb` but values are not rounded.
```js
var color = tinycolor("rgb(33.3, 66.7, 1)");
color.toRgbValues(); // { r: 33.3, g: 66.7, b: 1, a: 1 }
```
### toRgbString
```js
var color = tinycolor("red");
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ Deno.test("RGB Text Parsing", function () {
"#ff0000",
"parenthesized spaced input"
);
assertEquals(
tinycolor("rgba(33.3, 66.7, 1, 0.5)").toRgbValues(),
{
r: 33.3,
g: 66.7,
b: 1,
a: 0.5,
},
"toRgbValues"
);
assertEquals(
tinycolor({ r: 255, g: 0, b: 0 }).toHexString(),
"#ff0000",
Expand Down
8 changes: 8 additions & 0 deletions tinycolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@
a: this._a
};
},
toRgbValues: function toRgbValues() {
return {
r: this._r,
g: this._g,
b: this._b,
a: this._a
};
},
toRgbString: function toRgbString() {
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
},
Expand Down