- From: Jimmy Wärting <notifications@github.com>
- Date: Sun, 28 Aug 2022 08:44:53 -0700
- To: whatwg/url <url@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/url/issues/702@github.com>
just considered that input has things like `input.valueAsNumber` and `input.valueAsDate` and i thought to my self, hmm why don't `URLSearchParams` have something like that? `URLSearchParams.prototype.get` only return strings. what would you think if URLSearchParams was extended to support getAsNumber and more? ```js new URLSearchParams('debug').getAsBoolean('debug') // true (just being absent means true) new URLSearchParams('debug=1').getAsBoolean('debug') // true new URLSearchParams('debug=true').getAsBoolean('debug') // true new URLSearchParams('debug=somethingelse').getAsBoolean('debug') // ??? new URLSearchParams('debug=0').getAsBoolean('debug') // false new URLSearchParams('debug=false').getAsBoolean('debug') // false new URLSearchParams('').getAsBoolean('debug') // false ``` ```js new URLSearchParams('limit=10').getAsNumber('limit') // 10 new URLSearchParams('limit').getAsNumber('limit') // 0 or NaN new URLSearchParams('limit=1e2').getAsNumber('limit') // 100 new URLSearchParams('').getAsNumber('limit') // 0 or NaN new URLSearchParams('limit=0b11').getAsNumber('limit') // 3 new URLSearchParams('limit=abc').getAsNumber('limit') // NaN // Maybe also want to get it as BigInt too? // What about using parseInt and parseFloat? ``` ```js new URLSearchParams('created=2022-03-20').getAsDate('created') // new Date('2022-03-20') // it would try first to get it as a number and if it's NaN then it use the value as a string to the constructor new URLSearchParams('created=0').getAsDate('created') // new Date(0) ``` -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/702 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/url/issues/702@github.com>
Received on Sunday, 28 August 2022 15:45:06 UTC