Support 3-digit shorthand hex colors in templates#20
Open
mahmoodhamdi wants to merge 1 commit into
Open
Conversation
The shorthand hex syntax ({#F00 text}) was not supported, throwing
"Unknown Chalk style: undefined". This updates the style regex and
parseHex to handle 3-digit hex by expanding each digit (F00 → FF0000),
matching chalk's own hex() behavior.
Works for foreground ({#F00}), background ({#:0F0}), and combined
({#F00:0F0}) shorthand, including mixed 3/6-digit combinations.
Member
|
I think this introduces a regression for invalid hex lengths. I manually checked Could you tighten the parsing so the whole hex token has to match, and add a couple of tests for invalid 4 and 5 digit values? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While using chalk-template for a terminal dashboard, I noticed that 3-digit shorthand hex colors like
{#F00 text}throw an error, even though chalk itself supportschalk.hex('#F00').Before:
{#F00 hello}→Unknown Chalk style: undefinedAfter:
{#F00 hello}→ works, same as{#FF0000 hello}The fix updates the style regex to match 3-digit hex and expands shorthand digits in
parseHex(F00 → FF0000), matching chalk's own behavior.Supported:
{#F00 text}{#:0F0 text}{#F00:0F0 text}{#F00:00FF00 text}{bold.#F00 text}All existing tests pass, new tests added for both tagged template and
template()function.