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

Lenient input, strict output (Postel's law) #4

Closed
erikkemperman opened this issue Jul 14, 2016 · 1 comment
Closed

Lenient input, strict output (Postel's law) #4

erikkemperman opened this issue Jul 14, 2016 · 1 comment

Comments

@erikkemperman
Copy link
Member

This module currently returns the given value, as is, or null if it doesn't match the given type (or if the type is 'object' and the given value is actually null.)

For .date(), specifically, this means that the caller will still need to check whether it's a number, or a Number, or a Date. Would it make sense to have value-or-function always coerce to one type? E.g. always return Date objects from calls to date with valid argument?

Unlike .date(), the other functions currently are quite strict about their validation, for instance .number() will reject values like new Number(42) or '42'. Would it make sense to make this a bit more forgiving, and like the suggestion above to then coerce to the one type (number in this case)?

It would require a bit of refactoring, but I think it might be helpful (and also make the function name normalize live up to its name). If anyone agrees, I would gladly attempt the change and submit a PR.

@phated
Copy link
Member

phated commented Jul 14, 2016

Yeah, I like this suggestion. Feel free to submit a PR and we can discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants