Skip to content

Support withoutQuery #297

@Mini-ghost

Description

@Mini-ghost

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

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions