1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var UNWANTED_ENCLOSURES_REGEX = /[\(\[\{][^\)\]\}]*[\)\]\}]/g;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var UNWANTED_CHARS_REGEX = /[\0-\u001F\!-/:-@\[-`\{-\u00BF\u0250-\u036F\uD800-\uFFFF]/g;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var PHONENUMBER_REGEX = /^\d+[\d\s]*(:?ext|x|)\s*\d+$/i;
|
21 |
|
22 | var MULTIPLE_WHITESPACES_REGEX = /\s+/g;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var UNSUPPORTED_TEXT_REGEX = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uAC00-\uD7AF\uD7B0-\uD7FF\u3040-\u309F\u30A0-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD869][\uDC00-\uDED6]/;
|
33 | function getInitialsLatin(displayName, isRtl) {
|
34 | var initials = '';
|
35 | var splits = displayName.split(' ');
|
36 | if (splits.length === 2) {
|
37 | initials += splits[0].charAt(0).toUpperCase();
|
38 | initials += splits[1].charAt(0).toUpperCase();
|
39 | }
|
40 | else if (splits.length === 3) {
|
41 | initials += splits[0].charAt(0).toUpperCase();
|
42 | initials += splits[2].charAt(0).toUpperCase();
|
43 | }
|
44 | else if (splits.length !== 0) {
|
45 | initials += splits[0].charAt(0).toUpperCase();
|
46 | }
|
47 | if (isRtl && initials.length > 1) {
|
48 | return initials.charAt(1) + initials.charAt(0);
|
49 | }
|
50 | return initials;
|
51 | }
|
52 | function cleanupDisplayName(displayName) {
|
53 | displayName = displayName.replace(UNWANTED_ENCLOSURES_REGEX, '');
|
54 | displayName = displayName.replace(UNWANTED_CHARS_REGEX, '');
|
55 | displayName = displayName.replace(MULTIPLE_WHITESPACES_REGEX, ' ');
|
56 | displayName = displayName.trim();
|
57 | return displayName;
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function getInitials(displayName, isRtl, allowPhoneInitials) {
|
65 | if (!displayName) {
|
66 | return '';
|
67 | }
|
68 | displayName = cleanupDisplayName(displayName);
|
69 |
|
70 | if (UNSUPPORTED_TEXT_REGEX.test(displayName) || (!allowPhoneInitials && PHONENUMBER_REGEX.test(displayName))) {
|
71 | return '';
|
72 | }
|
73 | return getInitialsLatin(displayName, isRtl);
|
74 | }
|
75 | exports.getInitials = getInitials;
|
76 |
|
\ | No newline at end of file |