Skip to content

Conversation

NickCrews
Copy link

I wanted to be able to convert between formats on the command line, eg
pnpx culori convert '#12ff45' --to oklch

This implements this, along with a few other useful util commands. This is current usage text:

usage: ${binString} <command> [options]
Commands:
  convert <color> --to <format>     Convert color to a different format
  brighten <color>                  Adjust brightness of a color using CSS brightness() filter
    --amount <float>                An amount of 1 leaves the color unchanged.
    [--to <format>]                 Smaller values darken the color (with 0 being fully black), while larger values brighten it.
  blend <color1> <color2>           Blend two colors
    [--mode <mode='multiply'>]
    [--to <format>]
  info <color>                      Show info about color
  luminance <color>                 Show luminance based on WCAG
  contrast <color1> <color2>        Show contrast ratio based on WCAG
  help                              Show help
  version                           Show version

Supported formats: hex, rgb, hsl, lab, lch, oklch, oklab, etc.
Supported blend modes: multiply, screen, overlay, etc.

I'm not sure if this is quite the right semantics of when I log to console.error vs console.log.

This is decently well tested. This would need some documentation, but I wanted to start with this and get verification that this has some hope of getting merged before I put more effort in.

@danburzo
Copy link
Collaborator

danburzo commented Oct 3, 2025

Hi Nick, thanks for this! A CLI for color operations has been sitting on my Someday list, so I’m glad to see it here.

If that’s fine with you, I’d like to bikeshed the names of the commands and options a bit to see if we can find a good mapping to the programmatic API. I’ll get back with a proposal, and other (stylistic) notes I will add as code comments.

@NickCrews
Copy link
Author

Yes, please bikeshed those names, I wasn't totally happy with them either. Also curious to hear if you would want to pull in a CLI library to make the arg parsing better (my vanilla implementation is probably full of bugs)

@danburzo
Copy link
Collaborator

danburzo commented Oct 3, 2025

Also curious to hear if you would want to pull in a CLI library to make the arg parsing better (my vanilla implementation is probably full of bugs)

I was actually happily surprised by the no-dep approach! I wanted to suggest Node’s built-in utils.parseArgs() for even simpler code. The ability to use multiple occurrences of the same option might come in handy, e.g. to specify multiple output formats.

@NickCrews
Copy link
Author

NickCrews commented Oct 4, 2025

EDIT: I'm sorry I was lazy here, I can answer that myself with a google. The answer is yes, those APIs are implemented in bun and deno.

I'm not actually that familiar with the node ecosystem, if we use that node API, does that make this incompatible with other runtimes eg bun, deno? I would not want to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants