MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseCcshareId

Function parseCcshareId

src/utils/ccshareResume.ts:23–63  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

21}
22
23export function parseCcshareId(input: string): string | null {
24 const trimmed = input.trim()
25 if (!trimmed) {
26 return null
27 }
28
29 const directMatch = trimmed.match(CCSHARE_ID_RE)
30 if (directMatch) {
31 return directMatch[0]!
32 }
33
34 try {
35 const url = new URL(trimmed)
36 if (
37 (url.hostname === 'go' ||
38 url.hostname.startsWith('go.') ||
39 url.hostname.endsWith('.anthropic.com') ||
40 url.hostname === 'claude.ai' ||
41 url.hostname.endsWith('.claude.ai')) &&
42 url.pathname.startsWith('/ccshare/')
43 ) {
44 const candidate = decodeURIComponent(
45 url.pathname.slice('/ccshare/'.length).split('/')[0] ?? '',
46 )
47 if (CCSHARE_ID_RE.test(candidate)) {
48 return candidate
49 }
50 }
51 } catch {
52 // Fall through to shortlink-without-scheme parsing.
53 }
54
55 const shortlinkMatch = trimmed.match(
56 /^(?:go(?:\.[^/\s]+)?|claude\.ai)\/ccshare\/([^/?#]+)\/?(?:[?#].*)?$/i,
57 )
58 if (shortlinkMatch?.[1] && CCSHARE_ID_RE.test(shortlinkMatch[1])) {
59 return shortlinkMatch[1]
60 }
61
62 return null
63}
64
65export async function loadCcshare(ccshareId: string): Promise<LogOption> {
66 if (!CCSHARE_ID_RE.test(ccshareId)) {

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected