Skip to content

Commit 33b8ca3

Browse files
Revert "remove unnecessary if code , its breaking tests"
This reverts commit f465feb.
1 parent f465feb commit 33b8ca3

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

src/color/p5.Color.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,25 +330,27 @@ class Color {
330330
if (!colorString) {
331331
colorString = serialize(this._color, {
332332
format: outputFormat
333-
});
333+
});
334334

335-
colorString = String(colorString);
335+
if (format === '#rrggbb') {
336+
colorString = String(colorString);
336337

337-
if (colorString.length <= 5) {
338-
const match = colorString.match(/^#?([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/);
339-
if (match) {
340-
colorString = `#${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}`;
338+
if (colorString.length <= 5) {
339+
const match = colorString.match(/^#?([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/);
340+
if (match) {
341+
colorString = `#${match[1]}${match[1]}${match[2]}${match[2]}${match[3]}${match[3]}`;
342+
}
343+
}
344+
if (colorString.length > 7) {
345+
colorString = colorString.substring(0, 7);
346+
}
347+
colorString = colorString.toLowerCase();
341348
}
349+
350+
serializationMap[key] = colorString;
342351
}
343-
if (colorString.length > 7) {
344-
colorString = colorString.substring(0, 7);
345-
}
346-
colorString = colorString.toLowerCase();
347-
serializationMap[key] = colorString;
348-
349352
return colorString;
350353
}
351-
}
352354

353355
/**
354356
* Checks the contrast between two colors. This method returns a boolean

0 commit comments

Comments
 (0)