Skip to content

Commit 3480dc5

Browse files
committed
fix: allow blank input
1 parent 77dab97 commit 3480dc5

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/format-input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ const matchers = {
105105
*/
106106
export function stringInputToObject(color: string): any {
107107
color = color.trim().toLowerCase();
108+
if (color.length === 0) {
109+
return false;
110+
}
108111
let named = false;
109112
if (names[color]) {
110113
color = names[color];

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ export class TinyColor {
4949
}
5050
this.originalInput = color;
5151
const rgb = inputToRGB(color);
52-
if (!color) {
53-
return;
54-
}
5552
this.originalInput = color;
5653
this.r = rgb.r;
5754
this.g = rgb.g;

test/index.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ describe('TinyColor', () => {
227227
invalidColor = new TinyColor({ h: 'invalid', s: 'invalid', v: 'invalid' } as any);
228228
expect(invalidColor.toHexString()).toBe('#000000');
229229
expect(invalidColor.isValid).toBe(false);
230+
231+
invalidColor = new TinyColor();
232+
expect(invalidColor.toHexString()).toBe('#000000');
233+
expect(invalidColor.isValid).toBe(false);
230234
});
231235
it('Named colors', () => {
232236
expect(new TinyColor('aliceblue').toHex()).toBe('f0f8ff');

0 commit comments

Comments
 (0)