Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ideas] Get value as number, date & boolean #702

Closed
jimmywarting opened this issue Aug 28, 2022 · 1 comment
Closed

[ideas] Get value as number, date & boolean #702

jimmywarting opened this issue Aug 28, 2022 · 1 comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@jimmywarting
Copy link

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?

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
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?
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) 
@annevk annevk added topic: api needs implementer interest Moving the issue forward requires implementers to express interest addition/proposal New features or enhancements labels Aug 29, 2022
@annevk
Copy link
Member

annevk commented Jan 16, 2023

I'm going to duplicate this into #732 (comment). I think in principle there is something here, but I would want to see more evidence of widespread support for typed values before going there.

@annevk annevk closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

2 participants