sindresorhus / normalize-url

Normalize a URL
MIT License
837 stars 123 forks source link

Can I use version 7 in the browser? #140

Closed charbugs closed 3 years ago

charbugs commented 3 years ago

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 commented 3 years ago

It depends on which browsers you need to support. See: https://github.com/sindresorhus/normalize-url/issues/105

charbugs commented 3 years ago

Thanks for the pointer!

loynoir commented 3 years ago

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 commented 3 years ago

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

Q: Can I use sindresorhus/normalize-url@7.0.0 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.