spamscanner/url-regex-safe

Browser support

Richienb opened this issue · 7 comments

To properly support browsers, replace re2 with re2-wasm

PR welcome

Are you interested in dropping pre-build tooling and switching to ESM? This would make it easier to get the wasm-reliant code to work.

@Richienb I tried to understand the difference between re2 and re2-wasm, but the second one seems to be based on the first and does not seem to have any major differences. Both modules seem to be useful on the Node.js server side and will not work within a browser. Why prefer second over the first?

Why prefer second over the first?

You can not run native modules in the browser. You can run WASM though.

When would we need url-regex-safe in the browser? Curious what the use cases are. Could just have an API endpoint that takes a string and parses it and returns it and then calls new RegExp with value?

For libraries that validate urls before sending a request to them, making the validation an API endpoint would make this redundant. In this case, you might as well send the request in the first place and handle the error.

I'm using it in the browser to create a version of the text that will have any URL's converted into HTML with newlines converted to line breaks. Using a module, which was url-regex, instead of my own regular expression made sense.

Having an API endpoint do that for each of the items in the listing does not seem like a good idea.