Hacker Newsnew | past | comments | ask | show | jobs | submit | slev's commentslogin

Ack! Thanks for the info/link. I've now hidden this post.


'hide' only hides it from you but it really doesn't matter.

https://news.ycombinator.com/item?id=39991900

is definitely a Show HN and you could/should repost it as such. I'd upvote it, as a former OG parseURI user!


I created parseUri v1 17 years ago, but never hosted it on GitHub/npm because it's older than both of those tools. Nevertheless, it’s been used very widely due to it being tiny and predating JavaScript’s built-in `URL` constructor. After this short gap, I just released v2 with a ton of improvements: https://github.com/slevithan/parseuri

It’s still tiny (nothing similar comes close, even with libraries that support far fewer URI parts, types, and edge cases), and it includes several advantages over JavaScript's built-in `URL` constructor:

* parseUri gives you many additional properties (authority, userinfo, subdomain, domain, tld, resource, directory, filename, suffix) that aren’t available from `URL`.

* `URL` throws e.g. if not given a protocol, and in many other cases of valid (but not supported) and invalid URIs. parseUri makes a best case effort even with partial or invalid URIs and is extremely good with edge cases.

* `URL`’s rules don’t allow correctly handling many non-web protocols. For example, `URL` doesn’t throw on any of 'git://localhost:1234', 'ssh://myid@192.168.1.101', or 't2ab:///path/entry', but it also doesn’t get their details correct since it treats everything after : up to ? or # as part of the pathname.

* parseUri includes a “friendly” parsing mode (in addition to its default mode) that handles human-friendly URLs like 'example.com/index.html' as expected.

* parseUri includes partial/extensible support for second-level domains like in '//example.co.uk'.

So although it’s needed less often these days because of the built-in `URL`, if `URL` is ever not enough for your needs, this is an extremely accurate, flexible, and lightweight option.

The parseUri demo page lets you easily test results and compare them with `URL`: https://slevithan.github.io/parseuri/demo/


These days people study regular languages as part of the Chomsky hierarchy, but back when regular expressions were introduced into computing the term referred to Kleene’s regular expressions.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: