Skip to content

Commit

Permalink
feat: add hexa for backward compability
Browse files Browse the repository at this point in the history
  • Loading branch information
headwindz committed Jan 5, 2022
1 parent f9ef0e8 commit 2330748
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ Color.prototype = {
return new Color(value);
}

return colorString.to.hex(this.rgb().round().color);
},

hexa(value) {
if (arguments.length > 0) {
return new Color(value);
}

const rgbArray = this.rgb().round().color;
if (this.valpha !== 1) {
rgbArray.push(this.valpha);
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ it('Translate with channel setters', () => {

it('CSS String getters', () => {
equal(Color('rgb(10, 30, 25)').hex(), '#0A1E19');
equal(Color('rgb(10, 30, 25, 1)').hex(), '#0A1E19');
equal(Color('rgb(10, 30, 25, 0.4)').hex(), '#0A1E1966');
equal(Color('rgb(10, 30, 25, 1)').hexa(), '#0A1E19');
equal(Color('rgb(10, 30, 25, 0.4)').hexa(), '#0A1E1966');
equal(Color('rgb(10, 30, 25)').rgb().string(), 'rgb(10, 30, 25)');
equal(Color('rgb(10, 30, 25, 0.4)').rgb().string(), 'rgba(10, 30, 25, 0.4)');
equal(Color('rgb(10, 30, 25)').percentString(), 'rgb(4%, 12%, 10%)');
Expand Down

0 comments on commit 2330748

Please sign in to comment.