Skip to content

Implement Bun.color(input: string, outputFormat)#14170

Merged
Jarred-Sumner merged 18 commits intozack/cssfrom
jarred/bun-color
Sep 26, 2024
Merged

Implement Bun.color(input: string, outputFormat)#14170
Jarred-Sumner merged 18 commits intozack/cssfrom
jarred/bun-color

Conversation

@Jarred-Sumner
Copy link
Collaborator

What does this PR do?

Bun.color(input, outputFormat?) leverages Bun's CSS parser to parse, normalize, and convert colors from user input to a variety of output formats, including:

Format Example
"css" "red"
"ansi" "\x1b[38;2;255;0;0m"
"ansi-16" "\x1b[38;5;\tm"
"ansi-256" "\x1b[38;5;196m"
"ansi-16m" "\x1b[38;2;255;0;0m"
"number" 0x1a2b3c
"rgb" "rgb(255, 99, 71)"
"rgba" "rgba(255, 99, 71, 0.5)"
"hsl" "hsl(120, 50%, 50%)"
"hex" "#1a2b3c"
"HEX" "#1A2B3C"
"{rgb}" { r: 255, g: 99, b: 71 }
"{rgba}" { r: 255, g: 99, b: 71, a: 1 }
"[rgb]" [ 255, 99, 71 ]
"[rgba]" [ 255, 99, 71, 255]

How did you verify your code works?

Tests

@robobun
Copy link
Collaborator

robobun commented Sep 25, 2024

@Jarred-Sumner, your commit bae1e69 has 10 failures in #3952:

  • test/js/node/watch/fs.watch.test.ts - 2 failing on 🍎 14 x64
  • test/js/web/fetch/fetch-tcp-stress.test.ts - timeout on 🍎 13 x64
  • test/js/web/fetch/fetch-tcp-stress.test.ts - timeout on 🍎 14 x64
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🍎 14 aarch64
  • test/cli/install/bunx.test.ts - timeout on 🐧 12 aarch64
  • test/js/web/streams/streams.test.js - 1 failing on 🍎 14 aarch64
  • test/js/web/streams/streams.test.js - 1 failing on 🍎 13 x64
  • test/js/web/streams/streams.test.js - 1 failing on 🍎 14 x64
  • test/cli/install/registry/bun-install-registry.test.ts - 1 failing on 🍎 13 x64
  • test/cli/install/registry/bun-install-registry.test.ts - 1 failing on 🍎 14 x64
  • test/cli/hot/watch.test.ts - 1 failing on 🪟 x64
  • test/cli/hot/watch.test.ts - 1 failing on 🪟 x64-baseline
  • test/cli/watch/watch.test.ts - 2 failing on 🪟 x64
  • test/cli/watch/watch.test.ts - 2 failing on 🪟 x64-baseline
  • test/js/bun/http/fetch-file-upload.test.ts - 1 failing on 🪟 x64-baseline
  • test/js/bun/css/color.test.ts - annotation error on 🪟 x64-baseline
  • test/js/bun/css/color.test.ts - annotation error on 🪟 x64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 12 x64-baseline
  • test/js/bun/css/color.test.ts - annotation error on 🐧 22.04 x64-baseline
  • test/js/bun/css/color.test.ts - annotation error on 🐧 20.04 x64-baseline
  • test/js/bun/css/color.test.ts - annotation error on 🍎 13 aarch64
  • test/js/bun/css/color.test.ts - annotation error on 🍎 14 aarch64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 22.04 x64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 12 x64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 20.04 x64
  • test/js/bun/css/color.test.ts - annotation error on 🍎 13 x64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 22.04 aarch64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 20.04 aarch64
  • test/js/bun/css/color.test.ts - annotation error on 🐧 12 aarch64
  • test/js/bun/css/color.test.ts - annotation error on 🍎 14 x64

  • ```ts
    Bun.color("red", "css"); // "red"
    Bun.color(0xff0000, "css"); // "#f000"
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Isn't this wrong? #f000 (4 digits) is transparent but #ff0000 (6 digits) is opaque. Was the input meant to be #ff000000 (eight digits)?

    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    @zackradisic do you know

    @Jarred-Sumner Jarred-Sumner merged commit b7ab1fa into zack/css Sep 26, 2024
    @Jarred-Sumner Jarred-Sumner deleted the jarred/bun-color branch September 26, 2024 04:49
    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.

    4 participants