interface-forge - v2.5.0
    Preparing search index...

    Class ColorModule

    Module to generate colors.

    For a human-readable color like 'red', use human().

    For a hex color like #ff0000 used in HTML/CSS, use rgb(). There are also methods for other color formats such as hsl(), cmyk(), hwb(), lab(), and lch().

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    faker: Faker

    Methods

    • Returns a CMYK color.

      Returns number[]

      faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
      

      7.0.0

    • Returns a CMYK color.

      Parameters

      Returns string

      faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
      faker.color.cmyk({ format: 'css' }) // 'cmyk(35%, 39%, 68%, 60%)'
      faker.color.cmyk({ format: 'binary' }) // (8-32 bits) x 4

      7.0.0

    • Returns a CMYK color.

      Parameters

      • Optionaloptions: { format?: "decimal" }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated CMYK color.

          'decimal'
          

      Returns number[]

      faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
      faker.color.cmyk({ format: 'decimal' }) // [0.31, 0.52, 0.32, 0.43]

      7.0.0

    • Returns a CMYK color.

      Parameters

      • Optionaloptions: { format?: ColorFormat }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated CMYK color.

          'decimal'
          

      Returns string | number[]

      faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
      faker.color.cmyk({ format: 'decimal' }) // [0.31, 0.52, 0.32, 0.43]
      faker.color.cmyk({ format: 'css' }) // 'cmyk(35%, 39%, 68%, 60%)'
      faker.color.cmyk({ format: 'binary' }) // (8-32 bits) x 4

      7.0.0

    • Returns a random color based on CSS color space specified.

      Returns number[]

      faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
      

      7.0.0

    • Returns a random color based on CSS color space specified.

      Parameters

      • Optionaloptions: {
            format?: StringColorFormat;
            space?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb";
        }

        Options object.

        • Optionalformat?: StringColorFormat

          Format of generated RGB color.

          'decimal'
          
        • Optionalspace?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb"

          Color space to generate the color for.

          'sRGB'
          

      Returns string

      faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
      faker.color.colorByCSSColorSpace({ format: 'css', space: 'display-p3' }) // color(display-p3 0.12 1 0.23)
      faker.color.colorByCSSColorSpace({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns a random color based on CSS color space specified.

      Parameters

      • Optionaloptions: {
            format?: "decimal";
            space?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb";
        }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated RGB color.

          'decimal'
          
        • Optionalspace?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb"

          Color space to generate the color for.

          'sRGB'
          

      Returns number[]

      faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
      faker.color.colorByCSSColorSpace({ format: 'decimal' }) // [0.12, 0.21, 0.31]

      7.0.0

    • Returns a random color based on CSS color space specified.

      Parameters

      • Optionaloptions: {
            format?: ColorFormat;
            space?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb";
        }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated RGB color.

          'decimal'
          
        • Optionalspace?: "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb"

          Color space to generate the color for.

          'sRGB'
          

      Returns string | number[]

      faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
      faker.color.colorByCSSColorSpace({ format: 'decimal' }) // [0.12, 0.21, 0.31]
      faker.color.colorByCSSColorSpace({ format: 'css', space: 'display-p3' }) // color(display-p3 0.12 1 0.23)
      faker.color.colorByCSSColorSpace({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns a random css supported color function name.

      Returns "color" | "rgb" | "rgba" | "hsl" | "hsla" | "hwb" | "cmyk" | "lab" | "lch"

      faker.color.cssSupportedFunction() // 'rgb'
      

      7.0.0

    • Returns a random css supported color space name.

      Returns "sRGB" | "display-p3" | "rec2020" | "a98-rgb" | "prophoto-rgb"

      faker.color.cssSupportedSpace() // 'display-p3'
      

      7.0.0

    • Returns an HSL color.

      Returns number[]

      faker.color.hsl() // [201, 0.23, 0.32]
      

      7.0.0

    • Returns an HSL color.

      Parameters

      • Optionaloptions: { format?: StringColorFormat; includeAlpha?: boolean }

        Options object.

        • Optionalformat?: StringColorFormat

          Format of generated HSL color.

          'decimal'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          

      Returns string

      faker.color.hsl() // [201, 0.23, 0.32]
      faker.color.hsl({ format: 'css' }) // hsl(0deg, 100%, 80%)
      faker.color.hsl({ format: 'css', includeAlpha: true }) // hsl(0deg 100% 50% / 0.5)
      faker.color.hsl({ format: 'binary' }) // (8-32 bits) x 3
      faker.color.hsl({ format: 'binary', includeAlpha: true }) // (8-32 bits) x 4

      7.0.0

    • Returns an HSL color.

      Parameters

      • Optionaloptions: { format?: "decimal"; includeAlpha?: boolean }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated HSL color.

          'decimal'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          

      Returns number[]

      faker.color.hsl() // [201, 0.23, 0.32]
      faker.color.hsl({ format: 'decimal' }) // [300, 0.21, 0.52]
      faker.color.hsl({ format: 'decimal', includeAlpha: true }) // [300, 0.21, 0.52, 0.28]

      7.0.0

    • Returns an HSL color.

      Parameters

      • Optionaloptions: { format?: ColorFormat; includeAlpha?: boolean }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated HSL color.

          'decimal'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          

      Returns string | number[]

      faker.color.hsl() // [201, 0.23, 0.32]
      faker.color.hsl({ format: 'decimal' }) // [300, 0.21, 0.52]
      faker.color.hsl({ format: 'decimal', includeAlpha: true }) // [300, 0.21, 0.52, 0.28]
      faker.color.hsl({ format: 'css' }) // hsl(0deg, 100%, 80%)
      faker.color.hsl({ format: 'css', includeAlpha: true }) // hsl(0deg 100% 50% / 0.5)
      faker.color.hsl({ format: 'binary' }) // (8-32 bits) x 3
      faker.color.hsl({ format: 'binary', includeAlpha: true }) // (8-32 bits) x 4

      7.0.0

    • Returns a random human-readable color name.

      Returns string

      faker.color.human() // 'red'
      

      7.0.0

    • Returns an HWB color.

      Returns number[]

      faker.color.hwb() // [201, 0.21, 0.31]
      

      7.0.0

    • Returns an HWB color.

      Parameters

      Returns string

      faker.color.hwb() // [201, 0.21, 0.31]
      faker.color.hwb({ format: 'css' }) // 'hwb(354 72% 41%)'
      faker.color.hwb({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns an HWB color.

      Parameters

      • Optionaloptions: { format?: "decimal" }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated RGB color.

          'decimal'
          

      Returns number[]

      faker.color.hwb() // [201, 0.21, 0.31]
      faker.color.hwb({ format: 'decimal' }) // [201, 0.21, 0.31]

      7.0.0

    • Returns an HWB color.

      Parameters

      • Optionaloptions: { format?: ColorFormat }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated RGB color.

          'decimal'
          

      Returns string | number[]

      faker.color.hwb() // [201, 0.21, 0.31]
      faker.color.hwb({ format: 'decimal' }) // [201, 0.21, 0.31]
      faker.color.hwb({ format: 'css' }) // 'hwb(354 72% 41%)'
      faker.color.hwb({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns a LAB (CIELAB) color.

      Returns number[]

      faker.color.lab() // [0.832133, -80.3245, 100.1234]
      

      7.0.0

    • Returns a LAB (CIELAB) color.

      Parameters

      Returns string

      faker.color.lab() // [0.832133, -80.3245, 100.1234]
      faker.color.lab({ format: 'css' }) // 'lab(29.2345% 39.3825 20.0664)'
      faker.color.lab({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns a LAB (CIELAB) color.

      Parameters

      • Optionaloptions: { format?: "decimal" }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated RGB color.

          'decimal'
          

      Returns number[]

      faker.color.lab() // [0.832133, -80.3245, 100.1234]
      faker.color.lab({ format: 'decimal' }) // [0.856773, -80.2345, 100.2341]

      7.0.0

    • Returns a LAB (CIELAB) color.

      Parameters

      • Optionaloptions: { format?: ColorFormat }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated RGB color.

          'decimal'
          

      Returns string | number[]

      faker.color.lab() // [0.832133, -80.3245, 100.1234]
      faker.color.lab({ format: 'decimal' }) // [0.856773, -80.2345, 100.2341]
      faker.color.lab({ format: 'css' }) // 'lab(29.2345% 39.3825 20.0664)'
      faker.color.lab({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns an LCH color. Even though upper bound of chroma in LCH color space is theoretically unbounded, it is bounded to 230 as anything above will not make a noticeable difference in the browser.

      Returns number[]

      faker.color.lch() // [0.522345, 72.2, 56.2]
      

      7.0.0

    • Returns an LCH color. Even though upper bound of chroma in LCH color space is theoretically unbounded, it is bounded to 230 as anything above will not make a noticeable difference in the browser.

      Parameters

      Returns string

      faker.color.lch() // [0.522345, 72.2, 56.2]
      faker.color.lch({ format: 'css' }) // 'lch(52.2345% 72.2 56.2)'
      faker.color.lch({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns an LCH color. Even though upper bound of chroma in LCH color space is theoretically unbounded, it is bounded to 230 as anything above will not make a noticeable difference in the browser.

      Parameters

      • Optionaloptions: { format?: "decimal" }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated RGB color.

          'decimal'
          

      Returns number[]

      faker.color.lch() // [0.522345, 72.2, 56.2]
      faker.color.lch({ format: 'decimal' }) // [0.522345, 72.2, 56.2]

      7.0.0

    • Returns an LCH color. Even though upper bound of chroma in LCH color space is theoretically unbounded, it is bounded to 230 as anything above will not make a noticeable difference in the browser.

      Parameters

      • Optionaloptions: { format?: ColorFormat }

        Options object.

        • Optionalformat?: ColorFormat

          Format of generated RGB color.

          'decimal'
          

      Returns string | number[]

      faker.color.lch() // [0.522345, 72.2, 56.2]
      faker.color.lch({ format: 'decimal' }) // [0.522345, 72.2, 56.2]
      faker.color.lch({ format: 'css' }) // 'lch(52.2345% 72.2 56.2)'
      faker.color.lch({ format: 'binary' }) // (8-32 bits x 3)

      7.0.0

    • Returns an RGB color.

      Returns string

      faker.color.rgb() // '#8be4ab'
      

      7.0.0

    • Returns an RGB color.

      Parameters

      • Optionaloptions: {
            casing?: Casing$1;
            format?: "hex" | StringColorFormat;
            includeAlpha?: boolean;
            prefix?: string;
        }

        Options object.

        • Optionalcasing?: Casing$1

          Letter type case of the generated hex color. Only applied when 'hex' format is used.

          'lower'
          
        • Optionalformat?: "hex" | StringColorFormat

          Format of generated RGB color.

          'hex'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          
        • Optionalprefix?: string

          Prefix of the generated hex color. Only applied when 'hex' format is used.

          '#'
          

      Returns string

      faker.color.rgb() // '#0d7f26'
      faker.color.rgb({ prefix: '0x' }) // '0x9ddc8b'
      faker.color.rgb({ casing: 'upper' }) // '#B8A51E'
      faker.color.rgb({ casing: 'lower' }) // '#b12f8b'
      faker.color.rgb({ prefix: '#', casing: 'lower' }) // '#eb0c16'
      faker.color.rgb({ format: 'hex', casing: 'lower' }) // '#bb9d17'
      faker.color.rgb({ format: 'css' }) // 'rgb(216, 17, 192)'
      faker.color.rgb({ format: 'binary' }) // '00110010 00001000 01110110'
      faker.color.rgb({ includeAlpha: true }) // '#f96efb5e'
      faker.color.rgb({ format: 'css', includeAlpha: true }) // 'rgba(180, 158, 24, 0.75)'

      7.0.0

    • Returns an RGB color.

      Parameters

      • Optionaloptions: { format?: "decimal"; includeAlpha?: boolean }

        Options object.

        • Optionalformat?: "decimal"

          Format of generated RGB color.

          'hex'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          

      Returns number[]

      faker.color.rgb() // '0x8be4ab'
      faker.color.rgb({ format: 'decimal' }) // [64, 192,174]
      faker.color.rgb({ format: 'decimal', includeAlpha: true }) // [52, 250, 209, 0.21]

      7.0.0

    • Returns an RGB color.

      Parameters

      • Optionaloptions: {
            casing?: Casing$1;
            format?: "hex" | ColorFormat;
            includeAlpha?: boolean;
            prefix?: string;
        }

        Options object.

        • Optionalcasing?: Casing$1

          Letter type case of the generated hex color. Only applied when 'hex' format is used.

          'lower'
          
        • Optionalformat?: "hex" | ColorFormat

          Format of generated RGB color.

          'hex'
          
        • OptionalincludeAlpha?: boolean

          Adds an alpha value to the color (RGBA).

          false
          
        • Optionalprefix?: string

          Prefix of the generated hex color. Only applied when 'hex' format is used.

          '#'
          

      Returns string | number[]

      faker.color.rgb() // '#0d7f26'
      faker.color.rgb({ prefix: '0x' }) // '0x9ddc8b'
      faker.color.rgb({ casing: 'upper' }) // '#B8A51E'
      faker.color.rgb({ casing: 'lower' }) // '#b12f8b'
      faker.color.rgb({ prefix: '#', casing: 'lower' }) // '#eb0c16'
      faker.color.rgb({ format: 'hex', casing: 'lower' }) // '#bb9d17'
      faker.color.rgb({ format: 'decimal' }) // [64, 192,174]
      faker.color.rgb({ format: 'css' }) // 'rgb(216, 17, 192)'
      faker.color.rgb({ format: 'binary' }) // '00110010 00001000 01110110'
      faker.color.rgb({ includeAlpha: true }) // '#f96efb5e'
      faker.color.rgb({ format: 'css', includeAlpha: true }) // 'rgba(180, 158, 24, 0.75)'
      faker.color.rgb({ format: 'decimal', includeAlpha: true }) // [52, 250, 209, 0.21]

      7.0.0

    • Returns a random color space name from the worldwide accepted color spaces. Source: https://en.wikipedia.org/wiki/List_of_color_spaces_and_their_uses

      Returns string

      faker.color.space() // 'sRGB'
      

      7.0.0