- From: Viktor Kuroljov <notifications@github.com>
- Date: Wed, 03 Jul 2019 01:14:55 -0700
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/354/507990054@github.com>
Hello, everyone! I've implemented `URL.from` over in Node.js project ([PR](https://github.com/nodejs/node/pull/28482)), but we have a discussion there on to should we extend `URL` object or not. Good points are made for not doing so. However, it feels like it would be convenient to have an option of creating a url object not only from string that should represent a url, but also from an object (or any other alternative according to any language) allowing builder pattern.Also it can be much faster than parsing the string. I guess it would be a nice option in the browsers as well since making a url from an object-config is as common as making a url from string. @annevk input validation is an open question, but please note that input is not as complicated as I see in this thread. I would like to get focus on performance leaving most of the validation for users. You should *know* what you put there (also make writing 3rd party libraries easier). I'd like to do things like: ```js const input = {} // ... input.protocol = 'https' // ... input.host = 'localhost' // ... input.query = querystring.stringify({ a: 1, b: 2 }) // ... input.path = ['a', 'b'] // ... input.path.pop() // ... const myURL = URL.from(input) ``` If you did mistake you should get punished - sure. But what to do with users that are using typescript and checking things before using them in libraries? Punish them with double checks hurting performance? Anyway, if we can agree on the matter I am fine with strict checks (maybe with an option for `unsafe` for those who know what they are doing?). I'd love to see it in Node.js. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/354#issuecomment-507990054
Received on Wednesday, 3 July 2019 08:15:21 UTC