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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

20.41
/src/avatar/avatar.pipe.ts
1
import { Pipe, PipeTransform } from '@angular/core';
2
import { ThyAvatarService } from './avatar.service';
3

4
/**
5
 * `\u4e00`: https://www.compart.com/en/unicode/U+4E00
6
 * `\u9fa5`: https://www.compart.com/en/unicode/U+9FA5
7
 */
8
const UNIFIED_IDEOGRAPHS_REGEX = /^[\u4e00-\u9fa5]+$/;
1✔
9

1✔
10
const SET_OF_LETTERS_REGEX = /^[a-zA-Z\/ ]+$/;
1✔
11

12
@Pipe({
×
13
    name: 'avatarShortName',
×
14
    standalone: true
15
})
×
16
export class AvatarShortNamePipe implements PipeTransform {
×
17
    transform(name: string | null | undefined): string {
×
18
        if (!name) {
19
            return '';
×
20
        }
×
21

×
22
        name = name.trim();
23

×
24
        if (UNIFIED_IDEOGRAPHS_REGEX.test(name) && name.length > 2) {
25
            return name.slice(name.length - 2);
26
        }
1✔
27

28
        if (SET_OF_LETTERS_REGEX.test(name) && name.indexOf(' ') > 0) {
29
            const words: string[] = name.split(' ');
30
            return (words[0].slice(0, 1) + words[1].slice(0, 1)).toUpperCase();
31
        }
32

33
        return name.length > 2 ? name.slice(0, 2).toUpperCase() : name.toUpperCase();
1✔
34
    }
35
}
×
36

×
37
@Pipe({
38
    name: 'avatarBgColor',
×
39
    standalone: true
×
40
})
×
41
export class AvatarBgColorPipe implements PipeTransform {
42
    transform(name: string) {
×
43
        if (!name) {
×
44
            return;
45
        }
46
        const colors = ['#56abfb', '#5dcfff', '#84e17e', '#73d897', '#ff9f73', '#fa8888', '#fb7fb7', '#9a7ef4', '#868af6'];
×
47
        const nameArray: string[] = name.split('');
48
        const code: number =
49
            name && name.length > 0
50
                ? nameArray.reduce(
51
                      function (result, item) {
1✔
52
                          result.value += item.charCodeAt(0);
53
                          return result;
54
                      },
55
                      { value: 0 }
56
                  ).value
57
                : 0;
58
        return {
1✔
59
            'background-color': colors[code % 9]
60
        };
×
61
    }
62
}
63

×
64
@Pipe({
65
    name: 'thyAvatarSrc',
66
    standalone: true
67
})
1✔
68
export class AvatarSrcPipe implements PipeTransform {
69
    constructor(private thyAvatarService: ThyAvatarService) {}
70
    transform(src: string, size: number) {
71
        return this.thyAvatarService.srcTransform
1✔
72
            ? this.thyAvatarService.srcTransform(src, size)
73
            : this.thyAvatarService.avatarSrcTransform(src, size);
74
    }
75
}
76

77
export const AvatarPipes = [AvatarShortNamePipe, AvatarBgColorPipe, AvatarSrcPipe];
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