1+ "use strict" ;
2+
3+ exports . __esModule = true ;
4+ exports . default = void 0 ;
5+ // This implements the algorithm for path normalization described here:
6+ // https://www.files.com/docs/topics/file-system-semantics#exact-algorithm-for-path-normalization
7+
8+ /* eslint-disable sort-keys */
9+ var transliterationMap = {
10+ À : 'A' ,
11+ Á : 'A' ,
12+ Â : 'A' ,
13+ Ã : 'A' ,
14+ Ä : 'A' ,
15+ Å : 'A' ,
16+ Æ : 'AE' ,
17+ Ç : 'C' ,
18+ È : 'E' ,
19+ É : 'E' ,
20+ Ê : 'E' ,
21+ Ë : 'E' ,
22+ Ì : 'I' ,
23+ Í : 'I' ,
24+ Î : 'I' ,
25+ Ï : 'I' ,
26+ Ð : 'D' ,
27+ Ñ : 'N' ,
28+ Ò : 'O' ,
29+ Ó : 'O' ,
30+ Ô : 'O' ,
31+ Õ : 'O' ,
32+ Ö : 'O' ,
33+ Ø : 'O' ,
34+ Ù : 'U' ,
35+ Ú : 'U' ,
36+ Û : 'U' ,
37+ Ü : 'U' ,
38+ Ý : 'Y' ,
39+ ß : 'ss' ,
40+ à : 'a' ,
41+ á : 'a' ,
42+ â : 'a' ,
43+ ã : 'a' ,
44+ ä : 'a' ,
45+ å : 'a' ,
46+ æ : 'ae' ,
47+ ç : 'c' ,
48+ è : 'e' ,
49+ é : 'e' ,
50+ ê : 'e' ,
51+ ë : 'e' ,
52+ ì : 'i' ,
53+ í : 'i' ,
54+ î : 'i' ,
55+ ï : 'i' ,
56+ ð : 'd' ,
57+ ñ : 'n' ,
58+ ò : 'o' ,
59+ ó : 'o' ,
60+ ô : 'o' ,
61+ õ : 'o' ,
62+ ö : 'o' ,
63+ ø : 'o' ,
64+ ù : 'u' ,
65+ ú : 'u' ,
66+ û : 'u' ,
67+ ü : 'u' ,
68+ ý : 'y' ,
69+ ÿ : 'y' ,
70+ Ā : 'A' ,
71+ ā : 'a' ,
72+ Ă : 'A' ,
73+ ă : 'a' ,
74+ Ą : 'A' ,
75+ ą : 'a' ,
76+ Ć : 'C' ,
77+ ć : 'c' ,
78+ Ĉ : 'C' ,
79+ ĉ : 'c' ,
80+ Ċ : 'C' ,
81+ ċ : 'c' ,
82+ Č : 'C' ,
83+ č : 'c' ,
84+ Ď : 'D' ,
85+ ď : 'd' ,
86+ Đ : 'D' ,
87+ đ : 'd' ,
88+ Ē : 'E' ,
89+ ē : 'e' ,
90+ Ĕ : 'E' ,
91+ ĕ : 'e' ,
92+ Ė : 'E' ,
93+ ė : 'e' ,
94+ Ę : 'E' ,
95+ ę : 'e' ,
96+ Ě : 'E' ,
97+ ě : 'e' ,
98+ Ĝ : 'G' ,
99+ ĝ : 'g' ,
100+ Ğ : 'G' ,
101+ ğ : 'g' ,
102+ Ġ : 'G' ,
103+ ġ : 'g' ,
104+ Ģ : 'G' ,
105+ ģ : 'g' ,
106+ Ĥ : 'H' ,
107+ ĥ : 'h' ,
108+ Ħ : 'H' ,
109+ ħ : 'h' ,
110+ Ĩ : 'I' ,
111+ ĩ : 'i' ,
112+ Ī : 'I' ,
113+ ī : 'i' ,
114+ Ĭ : 'I' ,
115+ ĭ : 'i' ,
116+ Į : 'I' ,
117+ į : 'i' ,
118+ İ : 'I' ,
119+ IJ : 'IJ' ,
120+ ij : 'ij' ,
121+ Ĵ : 'J' ,
122+ ĵ : 'j' ,
123+ Ķ : 'K' ,
124+ ķ : 'k' ,
125+ Ĺ : 'L' ,
126+ ĺ : 'l' ,
127+ Ļ : 'L' ,
128+ ļ : 'l' ,
129+ Ľ : 'L' ,
130+ ľ : 'l' ,
131+ Ł : 'L' ,
132+ ł : 'l' ,
133+ Ń : 'N' ,
134+ ń : 'n' ,
135+ Ņ : 'N' ,
136+ ņ : 'n' ,
137+ Ň : 'N' ,
138+ ň : 'n' ,
139+ ʼn : '\'n' ,
140+ Ō : 'O' ,
141+ ō : 'o' ,
142+ Ŏ : 'O' ,
143+ ŏ : 'o' ,
144+ Ő : 'O' ,
145+ ő : 'o' ,
146+ Œ : 'OE' ,
147+ œ : 'oe' ,
148+ Ŕ : 'R' ,
149+ ŕ : 'r' ,
150+ Ŗ : 'R' ,
151+ ŗ : 'r' ,
152+ Ř : 'R' ,
153+ ř : 'r' ,
154+ Ś : 'S' ,
155+ ś : 's' ,
156+ Ŝ : 'S' ,
157+ ŝ : 's' ,
158+ Ş : 'S' ,
159+ ş : 's' ,
160+ Š : 'S' ,
161+ š : 's' ,
162+ Ţ : 'T' ,
163+ ţ : 't' ,
164+ Ť : 'T' ,
165+ ť : 't' ,
166+ Ũ : 'U' ,
167+ ũ : 'u' ,
168+ Ū : 'U' ,
169+ ū : 'u' ,
170+ Ŭ : 'U' ,
171+ ŭ : 'u' ,
172+ Ů : 'U' ,
173+ ů : 'u' ,
174+ Ű : 'U' ,
175+ ű : 'u' ,
176+ Ų : 'U' ,
177+ ų : 'u' ,
178+ Ŵ : 'W' ,
179+ ŵ : 'w' ,
180+ Ŷ : 'Y' ,
181+ ŷ : 'y' ,
182+ Ÿ : 'Y' ,
183+ Ź : 'Z' ,
184+ ź : 'z' ,
185+ Ż : 'Z' ,
186+ ż : 'z' ,
187+ Ž : 'Z' ,
188+ ž : 'z'
189+ } ;
190+ /* eslint-enable sort-keys */
191+
192+ var transliterate = function transliterate ( str ) {
193+ return Array . from ( str ) . map ( function ( char ) {
194+ return transliterationMap [ char ] || char ;
195+ } ) . join ( '' ) ;
196+ } ;
197+
198+ // converting the path to UTF-8 is not necessary in JS as it's the default
199+ var normalize = function normalize ( path ) {
200+ // Remove any characters with byte value of 0
201+ var cleaned = ( path || '' ) . replace ( / \0 / g, '' ) ;
202+
203+ // Convert any backslash (\) characters to a forward slash (/)
204+ cleaned = cleaned . replace ( / \\ / g, '/' ) ;
205+
206+ // Remove any trailing or leading slashes
207+ cleaned = cleaned . replace ( / ^ \/ + | \/ + $ / g, '' ) ;
208+
209+ // Remove any path parts that are . or ..
210+ cleaned = cleaned . split ( '/' ) . filter ( function ( part ) {
211+ return part !== '.' && part !== '..' ;
212+ } ) . join ( '/' ) ;
213+
214+ // Replace any duplicate forward slashes (such as ///) with a single forward slash (/)
215+ cleaned = cleaned . replace ( / \/ + / g, '/' ) ;
216+ return cleaned ;
217+ } ;
218+ var normalizeForComparisonCache = new Map ( ) ;
219+ var normalizeForComparison = function normalizeForComparison ( path ) {
220+ if ( normalizeForComparisonCache . has ( path ) ) {
221+ return normalizeForComparisonCache . get ( path ) ;
222+ }
223+
224+ // Run the path through the Normalize Algorithm
225+ var normalized = normalize ( path ) ;
226+
227+ // Unicode Normalize the Path using Unicode NFKC algorithm
228+ normalized = normalized . normalize ( 'NFKC' ) ;
229+
230+ // Transliterate and remove accent marks
231+ normalized = transliterate ( normalized ) ;
232+
233+ // Convert the Path to lowercase
234+ normalized = normalized . toLowerCase ( ) ;
235+
236+ // Remove any trailing whitespace (\r, \n, \t or the space character)
237+ normalized = normalized . replace ( / [ \r \n \t ] + $ / g, '' ) ;
238+ normalizeForComparisonCache . set ( path , normalized ) ;
239+ return normalized ;
240+ } ;
241+ var same = function same ( path1 , path2 ) {
242+ return normalizeForComparison ( path1 ) === normalizeForComparison ( path2 ) ;
243+ } ;
244+ var startsWith = function startsWith ( path1 , path2 ) {
245+ return normalizeForComparison ( path1 ) . startsWith ( normalizeForComparison ( path2 ) ) ;
246+ } ;
247+ var keyLookup = function keyLookup ( object , path ) {
248+ var key = Object . keys ( object ) . find ( function ( key ) {
249+ return same ( key , path ) ;
250+ } ) ;
251+ return typeof key === 'string' ? object [ key ] : undefined ;
252+ } ;
253+ var pathNormalizer = {
254+ keyLookup : keyLookup ,
255+ normalize : normalize ,
256+ same : same ,
257+ startsWith : startsWith
258+ } ;
259+ var _default = exports . default = pathNormalizer ;
260+ module . exports = pathNormalizer ;
261+ module . exports . default = pathNormalizer ;
0 commit comments