Urgent.News

the world's headlines, one feed

Editions

Tech

How I Built a Color Picker That Actually Converts Colors Correctly (HEX/RGB/HSL)

While working on a design system recently, I kept running into the same frustrating problem: I'd grab a color from Figma in HEX format, need it in HSL for a CSS variable, and end up bouncing between three different websites just to convert one value. Each site had its own UI quirks, some required JavaScript to be enabled, and none of them gave me a proper color scheme alongside the conversion. So…

While working on a design system, the reporter kept encountering the frustrating issue of constantly switching between different websites to convert colors between HEX, RGB, and HSL formats. Each site had its unique user interface, required JavaScript, and lacked a proper color scheme along with the conversion. Tired of this repetitive task, the reporter decided to create their own color picker tool.

The reporter identified several problems with existing color converter tools online: they were slow due to heavy JavaScript libraries, lacked context by not providing complementary colors and schemes, and were ad-heavy, which was distracting during the matching process. The reporter desired a single, instantaneous, and comprehensive HTML file that could be used offline without any ceremony.

For the architecture decision, the reporter chose to write the conversion logic using vanilla JavaScript instead of relying on libraries like color (npm). The core conversion logic was implemented in the form of two functions: hslToRgb and rgbToHsl. The hslToRgb function takes hue (h), saturation (s), and lightness (l) as parameters and returns an array with the corresponding RGB values.

The reporter also mentioned their honest take on AI-assisted development, explaining that they collaborated with AI to generate the initial code structure and design. However, they acknowledged that AI sometimes made mistakes in the output. In this case, the AI introduced subtle but critical bugs in the color conversion process, which the reporter had to address manually by rewriting the conversion functions using a more precise formula.

After iterating on the AI-generated code and verifying the output with specific test cases, the reporter arrived at a reliable RGB-to-HSL conversion function. With their new color picker tool, users can easily convert colors between HEX, RGB, and HSL formats without any distractions or errors.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.

Read the original at dev.to →

More in Tech

What Actually Happens When You Put a CDN in Front of Your Website?

If you've worked on web performance for any amount of time, you've probably heard the advice: “Put it behind a CDN.” But what does a CDN actually do between the browser and your server?

  • CDN creates edge servers closer to users, reducing latency
  • Without CDN, user in Singapore accesses US-origin server, increasing latency
  • CDN effectiveness depends on TTL, cache hits/misses, purge mechanism

How We Reset Monthly Quotas Without Race Conditions or Cron Drift

This article was originally published on Jo4 Blog . If you're billing monthly via Stripe or RevenueCat, it's tempting to reset usage quotas inside your webhook handler.

  • Reset monthly quotas without race conditions or cron drift
  • Use Spring Scheduler with 5-minute past midnight UTC cron
  • Instance-level advisory lock prevents simultaneous resets