diff --git a/src/format-input.ts b/src/format-input.ts index f99a451..dbe4854 100644 --- a/src/format-input.ts +++ b/src/format-input.ts @@ -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]; diff --git a/src/index.ts b/src/index.ts index 42afbe6..d82e265 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; diff --git a/test/index.spec.ts b/test/index.spec.ts index d7b61cf..edb8849 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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');