Skip to content

TypeError: Cannot set property 'namedColors' of undefined #1

@felixakiragreen

Description

@felixakiragreen

When I try to use this lib, I get that error: TypeError: Cannot set property 'namedColors' of undefined
(Regardless of whether I use the class or static method)

I can fix it by changing https://github.com/busterc/contrast-color/blob/main/lib/index.js#L211-L220 to:

function contrastColor({
  bgColor = '#FFFFFF',
  fgDarkColor = '#000000',
  fgLightColor = '#FFFFFF',
  defaultColor = '#000000',
  threshold = 128,
  customNamedColors = {},
} = {}) {
  const namedColors = { ...NAMED_COLORS, ...customNamedColors }

  const [
    namedBgColor,
    namedFgDarkColor,
    namedFgLightColor,
    namedDefaultColor,
  ] = [bgColor, fgDarkColor, fgLightColor, defaultColor].map(
    (p) => namedColors[p],
  )

(I'm just not calling this inside a function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions