Open History to see the last commit
1/** Checks for a query parameter without rewriting the opaque module ID. */
2export function hasIdQueryFlag(id: string, flag: string): boolean {
3 const queryIndex = id.indexOf('?')
4 if (queryIndex === -1) {
5 return false
6 }
7β
8 return new URLSearchParams(id.slice(queryIndex + 1)).has(flag)
9}
10β
11/** Appends an owned query flag without normalizing the existing query. */
12export function appendIdQueryFlag(id: string, flag: string): string {
13 if (!id.includes('?')) {
14 return `${id}?${flag}`
15 }
16β
17 const separator = id.endsWith('&') ? '' : '&'
18 return `${id}${separator}${flag}`
19}
20β
21/** Removes the owned query flag appended by {@link appendIdQueryFlag}. */
22export function removeIdQueryFlag(id: string, flag: string): string {
23 for (const separator of ['?', '&']) {
24 const suffix = `${separator}${flag}`
25 if (id.endsWith(suffix)) {
26 return id.slice(0, -suffix.length)
27 }
28 }
29β
30 return id
31}