@matdata/yasgui 5.13.0 → 5.15.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,40 @@
1
+ /**
2
+ * Converts a relative or absolute URL to a fully qualified URL with protocol and host.
3
+ * Uses the current page's protocol and host for relative URLs.
4
+ *
5
+ * @param url - The URL to resolve (can be relative like "/sparql", or absolute like "http://example.com/sparql")
6
+ * @returns The fully qualified URL with protocol and host
7
+ *
8
+ * @example
9
+ * // On page https://example.com/yasgui/
10
+ * resolveEndpointUrl("/sparql") // returns "https://example.com/sparql"
11
+ * resolveEndpointUrl("sparql") // returns "https://example.com/yasgui/sparql"
12
+ * resolveEndpointUrl("http://other.com/sparql") // returns "http://other.com/sparql"
13
+ */
14
+ export function resolveEndpointUrl(url: string): string {
15
+ if (!url) return url;
16
+
17
+ // If URL already has a protocol (http: or https:), return as-is
18
+ if (url.startsWith("http://") || url.startsWith("https://")) {
19
+ return url;
20
+ }
21
+
22
+ // Build the base URL using current page's protocol and host
23
+ let fullUrl = `${window.location.protocol}//${window.location.host}`;
24
+
25
+ if (url.startsWith("/")) {
26
+ // Absolute path (starts with /)
27
+ fullUrl += url;
28
+ } else {
29
+ // Relative path - join with current page's directory
30
+ let currentDirectory = window.location.pathname;
31
+ // If pathname does not end with "/", treat it as a file and use its directory
32
+ if (!currentDirectory.endsWith("/")) {
33
+ const lastSlashIndex = currentDirectory.lastIndexOf("/");
34
+ currentDirectory = lastSlashIndex >= 0 ? currentDirectory.substring(0, lastSlashIndex + 1) : "/";
35
+ }
36
+ fullUrl += currentDirectory + url;
37
+ }
38
+
39
+ return fullUrl;
40
+ }
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // Version information for YASGUI
2
2
  // This file is auto-generated during build - do not edit manually
3
- export const VERSION = "5.13.0";
3
+ export const VERSION = "5.15.0";