Z User
phase7: MCP stdio smoke test (handshake + tools/list + get_roots 6:74) — 4/4 tests PASS
54a6341 Download node_modules/hono/dist/client/utils.js from bravesigma/quran-md-plugin: direct link, hf CLI and curl.
- Browser
- Download file 2.5 kB
-
https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/hono/dist/client/utils.js
- Command line
-
hf download hf://datasets/bravesigma/quran-md-plugin/node_modules/hono/dist/client/utils.js
-
curl -L -o utils.js https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/hono/dist/client/utils.js
2.5 kB
| import { DetailedError, fetchRP } from "./fetch-result-please.js"; | |
| //#region src/client/utils.ts | |
| const mergePath = (base, path) => { | |
| let end = base.length; | |
| while (base[end - 1] === "/") end--; | |
| path = path.replace(/^\/+/, ""); | |
| return base.slice(0, end) + "/" + path; | |
| }; | |
| const networkPathRegExp = /^(?:[/\\][\t\n\r]*){2}/; | |
| const replaceUrlParam = (urlString, params) => { | |
| const isNetworkPath = networkPathRegExp.test(urlString); | |
| for (const [k, v] of Object.entries(params)) { | |
| const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)"); | |
| urlString = urlString.replace(reg, () => v ? `/${v}` : ""); | |
| } | |
| return !isNetworkPath && networkPathRegExp.test(urlString) ? urlString.replace(/^[/\\\t\n\r]+/, "/") : urlString; | |
| }; | |
| const buildSearchParams = (query) => { | |
| const searchParams = new URLSearchParams(); | |
| for (const [k, v] of Object.entries(query)) { | |
| if (v === void 0) continue; | |
| if (Array.isArray(v)) for (const v2 of v) { | |
| if (v2 === void 0) continue; | |
| searchParams.append(k, v2); | |
| } | |
| else searchParams.set(k, v); | |
| } | |
| return searchParams; | |
| }; | |
| const replaceUrlProtocol = (urlString, protocol) => { | |
| switch (protocol) { | |
| case "ws": return urlString.replace(/^http/, "ws"); | |
| case "http": return urlString.replace(/^ws/, "http"); | |
| } | |
| }; | |
| const removeIndexString = (urlString) => { | |
| if (/^https?:\/\/[^\/]+?\/index(?=\?|$)/.test(urlString)) return urlString.replace(/\/index(?=\?|$)/, "/"); | |
| return urlString.replace(/\/index(?=\?|$)/, ""); | |
| }; | |
| function isObject(item) { | |
| if (typeof item !== "object" || item === null) return false; | |
| const proto = Object.getPrototypeOf(item); | |
| return proto === null || Object.getPrototypeOf(proto) === null; | |
| } | |
| function deepMerge(target, source) { | |
| if (!isObject(target) && !isObject(source)) return source; | |
| const merged = { ...target }; | |
| for (const key in source) { | |
| const value = source[key]; | |
| if (isObject(merged[key]) && isObject(value)) merged[key] = deepMerge(merged[key], value); | |
| else merged[key] = value; | |
| } | |
| return merged; | |
| } | |
| /** | |
| * Shortcut to get a consumable response from `hc`'s fetch calls (Response), with types inference. | |
| * | |
| * Smartly parse the response data, throwing a structured error if the response is not `ok`. ({@link DetailedError}) | |
| * | |
| * @example const result = await parseResponse(client.posts.$get()) | |
| */ | |
| async function parseResponse(fetchRes) { | |
| return fetchRP(fetchRes); | |
| } | |
| //#endregion | |
| export { DetailedError, buildSearchParams, deepMerge, mergePath, parseResponse, removeIndexString, replaceUrlParam, replaceUrlProtocol }; | |