@scalar/helpers 0.2.15 → 0.2.16
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.
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the server from a string, used to check for servers in paths during migration
|
|
3
|
+
*
|
|
4
|
+
* @param path - The URL string to parse. If no protocol is provided, the URL API will throw an error.
|
|
5
|
+
* @returns A tuple of [origin, remainingPath] or null if the input is empty, whitespace-only, or invalid.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* extractServer('https://api.example.com/v1/users?id=123')
|
|
9
|
+
* // Returns: ['https://api.example.com', '/v1/users?id=123']
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* extractServer('/users')
|
|
13
|
+
* // Returns: null
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* extractServer('/users')
|
|
17
|
+
* // Returns: null
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* extractServer('//api.example.com/v1/users')
|
|
21
|
+
* // Returns: ['//api.example.com', '/v1/users']
|
|
22
|
+
*/
|
|
23
|
+
export declare const extractServerFromPath: (path?: string) => [string, string] | null;
|
|
24
|
+
//# sourceMappingURL=extract-server-from-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-server-from-path.d.ts","sourceRoot":"","sources":["../../src/url/extract-server-from-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAS,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAmCpE,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const extractServerFromPath = (path = "") => {
|
|
2
|
+
if (!path.trim()) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
if (path.startsWith("//")) {
|
|
6
|
+
try {
|
|
7
|
+
const url = new URL(`https:${path}`);
|
|
8
|
+
if (url.origin === "null") {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const origin = url.origin.replace(/^https?:/, "");
|
|
12
|
+
const remainingPath = decodeURIComponent(url.pathname) + url.search + url.hash;
|
|
13
|
+
return [origin, remainingPath];
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const url = new URL(path);
|
|
20
|
+
if (url.origin === "null") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const remainingPath = decodeURIComponent(url.pathname) + url.search + url.hash;
|
|
24
|
+
return [url.origin, remainingPath];
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
extractServerFromPath
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=extract-server-from-path.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/url/extract-server-from-path.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Extracts the server from a string, used to check for servers in paths during migration\n *\n * @param path - The URL string to parse. If no protocol is provided, the URL API will throw an error.\n * @returns A tuple of [origin, remainingPath] or null if the input is empty, whitespace-only, or invalid.\n *\n * @example\n * extractServer('https://api.example.com/v1/users?id=123')\n * // Returns: ['https://api.example.com', '/v1/users?id=123']\n *\n * @example\n * extractServer('/users')\n * // Returns: null\n *\n * @example\n * extractServer('/users')\n * // Returns: null\n *\n * @example\n * extractServer('//api.example.com/v1/users')\n * // Returns: ['//api.example.com', '/v1/users']\n */\nexport const extractServerFromPath = (path = ''): [string, string] | null => {\n if (!path.trim()) {\n return null\n }\n\n /** Handle protocol-relative URLs (e.g., \"//api.example.com\") */\n if (path.startsWith('//')) {\n try {\n /** Use dummy protocol to parse, then strip it */\n const url = new URL(`https:${path}`)\n if (url.origin === 'null') {\n return null\n }\n const origin = url.origin.replace(/^https?:/, '')\n\n /** Decode pathname to preserve OpenAPI template variables like {userId} */\n const remainingPath = decodeURIComponent(url.pathname) + url.search + url.hash\n return [origin, remainingPath]\n } catch {\n return null\n }\n }\n\n try {\n const url = new URL(path)\n /** URL API returns \"null\" for file:// and other invalid protocols */\n if (url.origin === 'null') {\n return null\n }\n /** Decode pathname to preserve OpenAPI template variables like {userId} */\n const remainingPath = decodeURIComponent(url.pathname) + url.search + url.hash\n return [url.origin, remainingPath]\n } catch {\n return null\n }\n}\n"],
|
|
5
|
+
"mappings": "AAsBO,MAAM,wBAAwB,CAAC,OAAO,OAAgC;AAC3E,MAAI,CAAC,KAAK,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,WAAW,IAAI,GAAG;AACzB,QAAI;AAEF,YAAM,MAAM,IAAI,IAAI,SAAS,IAAI,EAAE;AACnC,UAAI,IAAI,WAAW,QAAQ;AACzB,eAAO;AAAA,MACT;AACA,YAAM,SAAS,IAAI,OAAO,QAAQ,YAAY,EAAE;AAGhD,YAAM,gBAAgB,mBAAmB,IAAI,QAAQ,IAAI,IAAI,SAAS,IAAI;AAC1E,aAAO,CAAC,QAAQ,aAAa;AAAA,IAC/B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,IAAI;AAExB,QAAI,IAAI,WAAW,QAAQ;AACzB,aAAO;AAAA,IACT;AAEA,UAAM,gBAAgB,mBAAmB,IAAI,QAAQ,IAAI,IAAI,SAAS,IAAI;AAC1E,WAAO,CAAC,IAAI,QAAQ,aAAa;AAAA,EACnC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|