@bnidev/js-utils
    Preparing search index...

    Function hexToRgb

    • Converts a hex color string to an RGB object.

      Parameters

      • hex: string

        The hex color string (with or without #).

      Returns RgbColor | null

      An RGB object with r, g, b values (0-255).

      // ES Module
      import { hexToRgb } from '@bnidev/js-utils'

      // CommonJS
      const { hexToRgb } = require('@bnidev/js-utils')
      hexToRgb('#ff0000') // { r: 255, g: 0, b: 0 }
      hexToRgb('00ff00') // { r: 0, g: 255, b: 0 }