gh-here 2.1.0 → 3.0.0

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.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Utility functions for path and URL manipulation
3
+ */
4
+
5
+ export const PathUtils = {
6
+ getCurrentPath() {
7
+ const currentUrl = new URL(window.location.href);
8
+ return currentUrl.searchParams.get('path') || '';
9
+ },
10
+
11
+ getParentPath(currentPath) {
12
+ if (!currentPath || currentPath === '') {
13
+ return null;
14
+ }
15
+
16
+ const pathParts = currentPath.split('/').filter(p => p);
17
+ if (pathParts.length === 0) {
18
+ return null;
19
+ }
20
+
21
+ pathParts.pop();
22
+ return pathParts.join('/');
23
+ },
24
+
25
+ buildFilePath(currentPath, filename) {
26
+ return currentPath ? `${currentPath}/${filename}` : filename;
27
+ },
28
+
29
+ getFileName(filePath) {
30
+ return filePath.split('/').pop() || 'file.txt';
31
+ },
32
+
33
+ buildPathUrl(basePath, targetPath) {
34
+ return targetPath ? `${basePath}?path=${encodeURIComponent(targetPath)}` : basePath;
35
+ },
36
+
37
+ getDirectoryPath(filePath) {
38
+ const parts = filePath.split('/').filter(p => p);
39
+ if (parts.length <= 1) {
40
+ return '';
41
+ }
42
+ return parts.slice(0, -1).join('/');
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Language detection utility
48
+ */
49
+ export function getLanguageFromExtension(filename) {
50
+ const ext = filename.split('.').pop().toLowerCase();
51
+ const languageMap = {
52
+ js: 'javascript',
53
+ mjs: 'javascript',
54
+ jsx: 'javascript',
55
+ ts: 'typescript',
56
+ tsx: 'typescript',
57
+ html: 'html',
58
+ htm: 'html',
59
+ css: 'css',
60
+ scss: 'scss',
61
+ sass: 'sass',
62
+ less: 'less',
63
+ json: 'json',
64
+ xml: 'xml',
65
+ yaml: 'yaml',
66
+ yml: 'yaml',
67
+ py: 'python',
68
+ java: 'java',
69
+ go: 'go',
70
+ rs: 'rust',
71
+ php: 'php',
72
+ rb: 'ruby',
73
+ swift: 'swift',
74
+ kt: 'kotlin',
75
+ dart: 'dart',
76
+ c: 'c',
77
+ cpp: 'cpp',
78
+ cc: 'cpp',
79
+ cxx: 'cpp',
80
+ h: 'c',
81
+ hpp: 'cpp',
82
+ sh: 'shell',
83
+ bash: 'shell',
84
+ zsh: 'shell',
85
+ fish: 'shell',
86
+ ps1: 'powershell',
87
+ sql: 'sql',
88
+ r: 'r',
89
+ scala: 'scala',
90
+ clj: 'clojure',
91
+ lua: 'lua',
92
+ pl: 'perl',
93
+ groovy: 'groovy',
94
+ md: 'markdown',
95
+ txt: 'plaintext',
96
+ log: 'plaintext'
97
+ };
98
+
99
+ const basename = filename.toLowerCase();
100
+ if (basename === 'dockerfile' || basename.startsWith('dockerfile.')) {
101
+ return 'dockerfile';
102
+ }
103
+ if (basename === 'makefile') {
104
+ return 'makefile';
105
+ }
106
+ if (basename.startsWith('.env')) {
107
+ return 'dotenv';
108
+ }
109
+ if (basename === 'package.json' || basename === 'composer.json') {
110
+ return 'json';
111
+ }
112
+
113
+ return languageMap[ext] || 'plaintext';
114
+ }
115
+
116
+ /**
117
+ * HTML escaping utility
118
+ */
119
+ export function escapeHtml(text) {
120
+ const div = document.createElement('div');
121
+ div.textContent = text;
122
+ return div.innerHTML;
123
+ }