File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @internetarchive/ia-topnav" ,
3- "version" : " 1.1.30-alpha.0 " ,
3+ "version" : " 1.1.30-alpha.1 " ,
44 "description" : " Top nav for Internet Archive" ,
55 "license" : " AGPL-3.0-only" ,
66 "main" : " index.js" ,
Original file line number Diff line number Diff line change @@ -79,9 +79,23 @@ class PrimaryNav extends TrackedElement {
7979 ) ;
8080 }
8181
82+ get isRTL ( ) {
83+ const ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF' + '\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF' ;
84+ const rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC' ;
85+ const rtlCheck = new RegExp ( '^[^' + ltrChars + ']*[' + rtlChars + ']' ) ;
86+
87+ return rtlCheck . test ( this . screenName ) ;
88+ }
89+
8290 get truncatedScreenName ( ) {
83- if ( this . screenName && this . screenName . length > 10 ) {
84- return `${ this . screenName . substr ( 0 , 9 ) } …` ;
91+ if ( this . screenName && [ ...this . screenName ] . length > 10 ) {
92+ // Works with RTL and Unicode
93+ const truncated = [ ...this . screenName ] . slice ( 0 , 9 ) . join ( '' ) ;
94+ if ( this . isRTL ) {
95+ return `…${ truncated } ` ;
96+ } else {
97+ return `${ truncated } …` ;
98+ }
8599 }
86100 return this . screenName ;
87101 }
You can’t perform that action at this time.
0 commit comments