@settlemint/sdk-utils
Version:
Shared utilities and helper functions for SettleMint SDK modules
1 lines • 1.23 kB
Source Map (JSON)
{"version":3,"file":"url.cjs","names":[],"sources":["../src/url.ts"],"sourcesContent":["/**\n * Extracts the base URL before a specific segment in a URL.\n *\n * @param baseUrl - The base URL to extract the path from\n * @param pathSegment - The path segment to start from\n * @returns The base URL before the specified segment\n * @example\n * ```typescript\n * import { extractBaseUrlBeforeSegment } from \"@settlemint/sdk-utils/url\";\n *\n * const baseUrl = extractBaseUrlBeforeSegment(\"https://example.com/api/v1/subgraphs/name/my-subgraph\", \"/subgraphs\");\n * // Returns: \"https://example.com/api/v1\"\n * ```\n */\nexport function extractBaseUrlBeforeSegment(baseUrl: string, pathSegment: string) {\n const url = new URL(baseUrl);\n if (pathSegment.trim() === \"\") {\n return url.toString();\n }\n const segmentIndex = url.pathname.indexOf(pathSegment);\n return url.origin + (segmentIndex >= 0 ? url.pathname.substring(0, segmentIndex) : url.pathname);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,4BAA4B,SAAiB,aAAqB;CAChF,MAAM,MAAM,IAAI,IAAI,QAAQ;AAC5B,KAAI,YAAY,MAAM,KAAK,IAAI;AAC7B,SAAO,IAAI,UAAU;;CAEvB,MAAM,eAAe,IAAI,SAAS,QAAQ,YAAY;AACtD,QAAO,IAAI,UAAU,gBAAgB,IAAI,IAAI,SAAS,UAAU,GAAG,aAAa,GAAG,IAAI"}