@fluentui-react-native/experimental-avatar 0.14.41 → 0.14.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +52 -1
- package/CHANGELOG.md +27 -2
- package/FRNAvatar.podspec +0 -2
- package/MIGRATION.md +1 -2
- package/SPEC.md +1 -11
- package/lib/JSAvatar.d.ts +2 -2
- package/lib/JSAvatar.d.ts.map +1 -1
- package/lib/JSAvatar.js +17 -8
- package/lib/JSAvatar.js.map +1 -1
- package/lib/JSAvatar.styling.d.ts.map +1 -1
- package/lib/JSAvatar.styling.js +69 -25
- package/lib/JSAvatar.styling.js.map +1 -1
- package/lib/JSAvatar.types.d.ts +43 -22
- package/lib/JSAvatar.types.d.ts.map +1 -1
- package/lib/JSAvatarTokens.d.ts.map +1 -1
- package/lib/JSAvatarTokens.js +0 -2
- package/lib/JSAvatarTokens.js.map +1 -1
- package/lib/JSAvatarTokens.win32.d.ts.map +1 -1
- package/lib/JSAvatarTokens.win32.js +0 -2
- package/lib/JSAvatarTokens.win32.js.map +1 -1
- package/lib/useAvatar.d.ts +3 -5
- package/lib/useAvatar.d.ts.map +1 -1
- package/lib/useAvatar.js +27 -17
- package/lib/useAvatar.js.map +1 -1
- package/lib-commonjs/JSAvatar.d.ts +2 -2
- package/lib-commonjs/JSAvatar.d.ts.map +1 -1
- package/lib-commonjs/JSAvatar.js +16 -7
- package/lib-commonjs/JSAvatar.js.map +1 -1
- package/lib-commonjs/JSAvatar.styling.d.ts.map +1 -1
- package/lib-commonjs/JSAvatar.styling.js +69 -25
- package/lib-commonjs/JSAvatar.styling.js.map +1 -1
- package/lib-commonjs/JSAvatar.types.d.ts +43 -22
- package/lib-commonjs/JSAvatar.types.d.ts.map +1 -1
- package/lib-commonjs/JSAvatarTokens.d.ts.map +1 -1
- package/lib-commonjs/JSAvatarTokens.js +0 -2
- package/lib-commonjs/JSAvatarTokens.js.map +1 -1
- package/lib-commonjs/JSAvatarTokens.win32.d.ts.map +1 -1
- package/lib-commonjs/JSAvatarTokens.win32.js +0 -2
- package/lib-commonjs/JSAvatarTokens.win32.js.map +1 -1
- package/lib-commonjs/useAvatar.d.ts +3 -5
- package/lib-commonjs/useAvatar.d.ts.map +1 -1
- package/lib-commonjs/useAvatar.js +29 -19
- package/lib-commonjs/useAvatar.js.map +1 -1
- package/package.json +2 -2
- package/src/JSAvatar.styling.ts +74 -32
- package/src/JSAvatar.tsx +40 -24
- package/src/JSAvatar.types.ts +51 -24
- package/src/JSAvatarTokens.ts +0 -2
- package/src/JSAvatarTokens.win32.ts +0 -2
- package/src/__tests__/JSAvatar.test.jsx +48 -77
- package/src/__tests__/__snapshots__/JSAvatar.test.jsx.snap +52 -55
- package/src/useAvatar.ts +32 -16
- package/lib/JSAvatar.helpers.d.ts +0 -7
- package/lib/JSAvatar.helpers.d.ts.map +0 -1
- package/lib/JSAvatar.helpers.js +0 -28
- package/lib/JSAvatar.helpers.js.map +0 -1
- package/lib/utils/getInitials.d.ts +0 -15
- package/lib/utils/getInitials.d.ts.map +0 -1
- package/lib/utils/getInitials.js +0 -78
- package/lib/utils/getInitials.js.map +0 -1
- package/lib/utils/getInitials.test.d.ts +0 -2
- package/lib/utils/getInitials.test.d.ts.map +0 -1
- package/lib/utils/getInitials.test.js +0 -116
- package/lib/utils/getInitials.test.js.map +0 -1
- package/lib/utils/index.d.ts +0 -2
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/index.js +0 -2
- package/lib/utils/index.js.map +0 -1
- package/lib-commonjs/JSAvatar.helpers.d.ts +0 -7
- package/lib-commonjs/JSAvatar.helpers.d.ts.map +0 -1
- package/lib-commonjs/JSAvatar.helpers.js +0 -32
- package/lib-commonjs/JSAvatar.helpers.js.map +0 -1
- package/lib-commonjs/utils/getInitials.d.ts +0 -15
- package/lib-commonjs/utils/getInitials.d.ts.map +0 -1
- package/lib-commonjs/utils/getInitials.js +0 -82
- package/lib-commonjs/utils/getInitials.js.map +0 -1
- package/lib-commonjs/utils/getInitials.test.d.ts +0 -2
- package/lib-commonjs/utils/getInitials.test.d.ts.map +0 -1
- package/lib-commonjs/utils/getInitials.test.js +0 -118
- package/lib-commonjs/utils/getInitials.test.js.map +0 -1
- package/lib-commonjs/utils/index.d.ts +0 -2
- package/lib-commonjs/utils/index.d.ts.map +0 -1
- package/lib-commonjs/utils/index.js +0 -6
- package/lib-commonjs/utils/index.js.map +0 -1
- package/src/JSAvatar.helpers.ts +0 -35
- package/src/utils/getInitials.test.ts +0 -154
- package/src/utils/getInitials.ts +0 -92
- package/src/utils/index.ts +0 -1
package/src/utils/getInitials.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Regular expressions matching characters to ignore when calculating the initials.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Regular expression matching characters within various types of enclosures, including the enclosures themselves
|
|
7
|
-
* so for example, (xyz) [xyz] {xyz} all would be ignored
|
|
8
|
-
*/
|
|
9
|
-
const UNWANTED_ENCLOSURES_REGEX: RegExp = /[\(\[\{][^\)\]\}]*[\)\]\}]/g;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Regular expression matching special ASCII characters except space, plus some unicode special characters.
|
|
13
|
-
* Applies after unwanted enclosures have been removed
|
|
14
|
-
*/
|
|
15
|
-
const UNWANTED_CHARS_REGEX: RegExp = /[\0-\u001F\!-/:-@\[-`\{-\u00BF\u0250-\u036F\uD800-\uFFFF]/g;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Regular expression matching phone numbers. Applied after chars matching UNWANTED_CHARS_REGEX have been removed
|
|
19
|
-
* and number has been trimmed for whitespaces
|
|
20
|
-
*/
|
|
21
|
-
const PHONENUMBER_REGEX: RegExp = /^\d+[\d\s]*(:?ext|x|)\s*\d+$/i;
|
|
22
|
-
|
|
23
|
-
/** Regular expression matching one or more spaces. */
|
|
24
|
-
const MULTIPLE_WHITESPACES_REGEX: RegExp = /\s+/g;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Regular expression matching languages for which we currently don't support initials.
|
|
28
|
-
* Arabic: Arabic, Arabic Supplement, Arabic Extended-A.
|
|
29
|
-
* Korean: Hangul Jamo, Hangul Compatibility Jamo, Hangul Jamo Extended-A, Hangul Syllables, Hangul Jamo Extended-B.
|
|
30
|
-
* Japanese: Hiragana, Katakana.
|
|
31
|
-
* CJK: CJK Unified Ideographs Extension A, CJK Unified Ideographs, CJK Compatibility Ideographs,
|
|
32
|
-
* CJK Unified Ideographs Extension B
|
|
33
|
-
*/
|
|
34
|
-
// eslint-disable-next-line @fluentui/max-len
|
|
35
|
-
const UNSUPPORTED_TEXT_REGEX: RegExp =
|
|
36
|
-
/[\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]/;
|
|
37
|
-
|
|
38
|
-
function getInitialsLatin(displayName: string, isRtl: boolean): string {
|
|
39
|
-
let initials = '';
|
|
40
|
-
|
|
41
|
-
const splits: string[] = displayName.split(' ');
|
|
42
|
-
|
|
43
|
-
if (splits.length === 2) {
|
|
44
|
-
initials += splits[0].charAt(0).toUpperCase();
|
|
45
|
-
initials += splits[1].charAt(0).toUpperCase();
|
|
46
|
-
} else if (splits.length === 3) {
|
|
47
|
-
initials += splits[0].charAt(0).toUpperCase();
|
|
48
|
-
initials += splits[2].charAt(0).toUpperCase();
|
|
49
|
-
} else if (splits.length !== 0) {
|
|
50
|
-
initials += splits[0].charAt(0).toUpperCase();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (isRtl && initials.length > 1) {
|
|
54
|
-
return initials.charAt(1) + initials.charAt(0);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return initials;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function cleanupDisplayName(displayName: string): string {
|
|
61
|
-
displayName = displayName.replace(UNWANTED_ENCLOSURES_REGEX, '');
|
|
62
|
-
displayName = displayName.replace(UNWANTED_CHARS_REGEX, '');
|
|
63
|
-
displayName = displayName.replace(MULTIPLE_WHITESPACES_REGEX, ' ');
|
|
64
|
-
displayName = displayName.trim();
|
|
65
|
-
|
|
66
|
-
return displayName;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get (up to 2 characters) initials based on display name of the persona.
|
|
71
|
-
*
|
|
72
|
-
* @param displayName - The full name of the person or entity
|
|
73
|
-
* @param isRtl - Whether the display is in RTL
|
|
74
|
-
* @param allowPhoneInitials - Should initials be generated from phone numbers (default false)
|
|
75
|
-
*
|
|
76
|
-
* @returns The 1 or 2 character initials based on the name. Or an empty string if no initials
|
|
77
|
-
* could be derived from the name.
|
|
78
|
-
*/
|
|
79
|
-
export function getInitials(displayName: string | undefined | null, isRtl: boolean, allowPhoneInitials?: boolean): string {
|
|
80
|
-
if (!displayName) {
|
|
81
|
-
return '';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
displayName = cleanupDisplayName(displayName);
|
|
85
|
-
|
|
86
|
-
// For names containing CJK characters, and phone numbers, we don't display initials
|
|
87
|
-
if (UNSUPPORTED_TEXT_REGEX.test(displayName) || (!allowPhoneInitials && PHONENUMBER_REGEX.test(displayName))) {
|
|
88
|
-
return '';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return getInitialsLatin(displayName, isRtl);
|
|
92
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getInitials } from './getInitials';
|