ufo icon indicating copy to clipboard operation
ufo copied to clipboard

Support `withoutQuery`

Open Mini-ghost opened this issue 9 months ago • 0 comments

Describe the feature

It would be helpful to introduce a utility named withoutQuery(input: string): string that removes the entire query string from a given URL.

While filterQuery(input, predicate) is already available and works well for selectively preserving query parameters, there is currently no dedicated function for simply stripping out the entire query section from a URL string. In cases where all query parameters need to be removed, having a simpler, more explicit utility could be beneficial.

Implementation

/**
 * Removes the query section of the URL.
 *
 * @example
 * withoutQuery("/foo?bar=1&baz=2") // "/foo"
 */
function withoutQuery(input: string): string {
  if (!input.includes("?")) {
    return input;
  }

  const parsed = parseURL(input);
  parsed.search = "";
  return stringifyParsedURL(parsed);
}

I'm not sure if this addition would be a good fit for the project, but please feel free to let me know if there’s anything I may have overlooked or if you have any concerns or suggestions.

Additional information

  • [x] Would you be willing to help implement this feature?

Mini-ghost avatar Jul 28 '25 11:07 Mini-ghost