• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 3301e8fe-9868-476c-990a-ab44e51f4a2d

pending completion
3301e8fe-9868-476c-990a-ab44e51f4a2d

push

circleci

GitHub
Merge pull request #3001 from mozilla/main

282 of 1768 branches covered (15.95%)

Branch coverage included in aggregate %.

451 of 451 new or added lines in 56 files covered. (100.0%)

959 of 4670 relevant lines covered (20.54%)

3.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/utils/breachLogo.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import AppConstants from '../appConstants.js'
6

7
/**
8
 * @param {object} breach
9
 * @param {Map<string, string>} logos Map of URLs to logos indexed by the domain name of the respective company
10
 * @returns {string} HTML for a breach logo (either an `img`, or a `span.breach-logo` containing the breached company's first letter)
11
 */
12
export function getBreachLogo (breach, logos) {
13
  const logoIsAvailable = logos?.has(breach.Domain)
×
14

15
  if (logoIsAvailable) {
×
16
    return `<img src='${AppConstants.SERVER_URL}${logos.get(breach.Domain)}' alt='' loading="lazy" class='breach-logo' height='32' />`
×
17
  }
18

19
  // Add CSS variable and a dedicated class for the logo placeholder
20
  // as fallback for emails
21
  const { className, variableName } = getColorForName(breach.Name)
×
22
  const classNames = `breach-logo breach-logo-email ${className}`
×
23
  const backgroundStyle = `background-color: var(${variableName});`
×
24

25
  return `<span role="img" aria-hidden='true' class='${classNames}' style='${backgroundStyle}'>${breach.Name.substring(0, 1)}</span>`
×
26
}
27

28
/**
29
 * @param {string} name
30
 * @returns {string} CSS variable for a string-specific color
31
 */
32
function getColorForName (name) {
33
  const logoColors = [
×
34
    {
35
      className: 'bg-blue-5',
36
      variableName: '--blue-5'
37
    },
38
    {
39
      className: 'bg-purple-5',
40
      variableName: '--purple-5'
41
    },
42
    {
43
      className: 'bg-green-05',
44
      variableName: '--green-05'
45
    },
46
    {
47
      className: 'bg-violet-5',
48
      variableName: '--violet-5'
49
    },
50
    {
51
      className: 'bg-orange-5',
52
      variableName: '--orange-5'
53
    },
54
    {
55
      className: 'bg-yellow-5',
56
      variableName: '--yellow-5'
57
    },
58
    {
59
      className: 'bg-red-5',
60
      variableName: '--red-5'
61
    },
62
    {
63
      className: 'bg-pink-5',
64
      variableName: '--pink-5'
65
    }
66
  ]
67

68
  const charValue = name
×
69
    .split('')
70
    .map(letter => letter.codePointAt(0))
×
71
    .reduce((sum, codePoint) => sum + codePoint)
×
72

73
  return logoColors[charValue % logoColors.length]
×
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc