Skip to content

Commit

Permalink
fix: allow blank input
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed May 2, 2018
1 parent 77dab97 commit 3480dc5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/format-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const matchers = {
*/
export function stringInputToObject(color: string): any {
color = color.trim().toLowerCase();
if (color.length === 0) {
return false;
}
let named = false;
if (names[color]) {
color = names[color];
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export class TinyColor {
}
this.originalInput = color;
const rgb = inputToRGB(color);
if (!color) {
return;
}
this.originalInput = color;
this.r = rgb.r;
this.g = rgb.g;
Expand Down
4 changes: 4 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ describe('TinyColor', () => {
invalidColor = new TinyColor({ h: 'invalid', s: 'invalid', v: 'invalid' } as any);
expect(invalidColor.toHexString()).toBe('#000000');
expect(invalidColor.isValid).toBe(false);

invalidColor = new TinyColor();
expect(invalidColor.toHexString()).toBe('#000000');
expect(invalidColor.isValid).toBe(false);
});
it('Named colors', () => {
expect(new TinyColor('aliceblue').toHex()).toBe('f0f8ff');
Expand Down

0 comments on commit 3480dc5

Please sign in to comment.