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

Can I use version 7 in the browser? #140

Closed
charbugs opened this issue Jul 14, 2021 · 4 comments
Closed

Can I use version 7 in the browser? #140

charbugs opened this issue Jul 14, 2021 · 4 comments

Comments

@charbugs
Copy link

The readme says:

If you need to use this in the browser, use version 4: npm i normalize-url@4

I scanned the index.js of version 7 and it seems to me that there are no Node-specific APIs involved. I also did a quick check which seems to work at first glance:

<script type="module">
    import normalizeUrl from './node_modules/normalize-url/index.js'
    console.log(normalizeUrl('foo.bar'))
</script>

So is it save to use version 7 in the browser?

@sindresorhus
Copy link
Owner

It depends on which browsers you need to support. See: #105

@charbugs
Copy link
Author

Thanks for the pointer!

@loynoir
Copy link

loynoir commented Aug 7, 2021

Hi, @sindresorhus
Is js-regexp-lookbehind the only limitation prevent using v7 in browser?
Might be better to document the reason behind

If you need to use this in the browser, use version 4: npm i normalize-url@4

loynoir added a commit to loynoir/normalize-url that referenced this issue Aug 9, 2021
1. [test] Move `ava` to `mocha+chai` to test in real browser.
(sindresorhus#105) (sindresorhus#140) (sindresorhus#142)
2. [test] seprate non special-protocol-schemes(sindresorhus#147)
3. [doc] Update readme
@loynoir
Copy link

loynoir commented Aug 9, 2021

For any seeing this, after I migrate test.js from ava to mocha+chai, I would say

Q: Can I use sindresorhus/[email protected] in the browser?
A:

  1. No if your browser don't support js-regexp-lookbehind
  2. No if you use custom scheme outside of url_special_schemes, aka outside of https/http/wss/ws/ftp/file, tested with latest chrome and firefox.

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

No branches or pull requests

3 participants