Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support URL instance as to parameter. #963

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

tomalec
Copy link

@tomalec tomalec commented Oct 31, 2022

The issue to be addressed

push, replace, and createPath methods accept to parameter which is string or Partial<Path>. The Path seems to be a partial to the native URL which also contains pathname: string, search: string, hash: string.

Also, given the library is used to work with URLs it's tempting to provide the actual URL instances. I often use URL, and its .searchParams to construct, change and manipulate URLs.

Currently, createURL works fine if given an URL instance, however push and replace takes new URL('/foo?bar=biz', 'http://my.base/path') as {}.

What's changed

This PR makes getNextLocation normalize given to to be always a plain object.
(Plus, it makes getNextLocation a bit DRYier)

Possible improvements

If this library aims to support environments without URL, we could add typeof URL === 'function', then assume the given to object is just a Path literal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant