MCPcopy Index your code
hub / github.com/massCodeIO/massCode / splitUrlAndQuery

Function splitUrlAndQuery

src/main/http/import/normalize.ts:101–133  ·  view source on GitHub ↗
(rawUrl: string)

Source from the content-addressed store, hash-verified

99}
100
101export function splitUrlAndQuery(rawUrl: string): {
102 url: string
103 query: HttpQueryEntry[]
104} {
105 const hashIndex = rawUrl.indexOf('#')
106 const withoutFragment
107 = hashIndex === -1 ? rawUrl : rawUrl.slice(0, hashIndex)
108 const queryIndex = withoutFragment.indexOf('?')
109
110 if (queryIndex === -1) {
111 return { query: [], url: withoutFragment }
112 }
113
114 const url = withoutFragment.slice(0, queryIndex)
115 const rawQuery = withoutFragment.slice(queryIndex + 1)
116 const query = rawQuery
117 .split('&')
118 .filter(Boolean)
119 .map((entry) => {
120 const separatorIndex = entry.indexOf('=')
121 const key
122 = separatorIndex === -1 ? entry : entry.slice(0, separatorIndex)
123 const value
124 = separatorIndex === -1 ? '' : entry.slice(separatorIndex + 1)
125
126 return {
127 key: decodeQueryPart(key),
128 value: decodeQueryPart(value),
129 }
130 })
131
132 return { query, url }
133}
134
135export function normalizeEntries<T extends HttpHeaderEntry | HttpQueryEntry>(
136 entries: T[],

Callers 3

parseOperationFunction · 0.90
parseUrlFunction · 0.90
parseRequestFunction · 0.90

Calls 1

decodeQueryPartFunction · 0.85

Tested by

no test coverage detected