@@ -48,25 +48,6 @@ const charDecode = Object.fromEntries(
4848 . map ( ( [ k , v ] ) => [ v , k ] )
4949)
5050
51- const hexDigitEncode = {
52- "0" : "A" ,
53- "1" : "B" ,
54- "2" : "C" ,
55- "3" : "D" ,
56- "4" : "E" ,
57- "5" : "F" ,
58- "6" : "G" ,
59- "7" : "H" ,
60- "8" : "I" ,
61- "9" : "J" ,
62- }
63-
64- const hexDigitDecode = Object . fromEntries (
65- Object
66- . entries ( hexDigitEncode )
67- . map ( ( [ k , v ] ) => [ v , k ] )
68- )
69-
7051const hexShiftEncode = {
7152 "0" : "a" ,
7253 "1" : "b" ,
@@ -102,9 +83,8 @@ export function doubleXEncode (
10283) : string {
10384 if ( options . encodeLeadingDigit ) {
10485 const firstChar = str . slice ( 0 , 1 )
105- const firstDigitHex = hexDigitEncode [ firstChar ]
106- const firstCharEncoded = firstDigitHex
107- ? "XXZ" + firstDigitHex
86+ const firstCharEncoded = / ^ [ 0 - 9 ] $ / . test ( firstChar )
87+ ? "XXZ" + firstChar
10888 : firstChar
10989
11090 options . encodeLeadingDigit = false
@@ -148,7 +128,7 @@ export function doubleXDecode (str: string): string {
148128 const strNorm = str . replaceAll ( "XXXXXX" , "XXYXXY" )
149129
150130 return strNorm
151- . split ( / ( X X Y | X X Z [ A - J ] | X X [ 0 - 9 A - W ] | X X [ a - p ] { 5 } ) / )
131+ . split ( / ( X X Y | X X Z [ 0 - 9 ] | X X [ 0 - 9 A - W ] | X X [ a - p ] { 5 } ) / )
152132 . filter ( Boolean ) // Remove empty strings
153133 . map ( word =>
154134 word . startsWith ( "XX" )
@@ -164,7 +144,7 @@ export function doubleXDecode (str: string): string {
164144 )
165145 )
166146 : ( word . slice ( 2 , 3 ) == "Z" )
167- ? hexDigitDecode [ word . slice ( 3 , 4 ) ]
147+ ? word . slice ( 3 , 4 )
168148 : charDecode [ word . slice ( 2 , 3 ) ]
169149 )
170150 : word
0 commit comments