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

BigInt support #1531

Closed
kanongil opened this issue Jun 22, 2018 · 4 comments
Closed

BigInt support #1531

kanongil opened this issue Jun 22, 2018 · 4 comments
Assignees
Labels
feature New functionality or improvement

Comments

@kanongil
Copy link
Contributor

Describe the problem you are trying to fix (provide as much context as possible)

Support BigInt integers. See outmoded/hapi-contrib#119.

Which API (or modification of the current API) do you suggest to solve that problem ?

I would like Joi to support the BigInt type. This involves accepting it as input for number() validation (when convert is enabled), and probably as a new validation type.

Are you ready to work on a pull request if your suggestion is accepted ?

Yes. See kanongil@fa53259.

@Marsup
Copy link
Collaborator

Marsup commented Aug 1, 2018

Your commit seems reasonable, why didn't you PR ?

The question of whether it needs a new type or not is indeed a good one, I haven't used it enough to see the practical pitfalls we'd fall into if we regrouped those under the same type, have you ?

@kanongil
Copy link
Contributor Author

kanongil commented Aug 1, 2018

I just wanted to gather a bit of feedback before revising / adding relevant doc updates.

Semantically, it would make sense to add a new bigint() type, as many of the other types map to a native type. It should be relatively simple to clone the number() implementation and create a bigint() type from it.

Actually, one idea that could bring us closer: Allow entries to have a post validation conversion step.

const schema = Joi.number().integer().convert(BigInt);

This would also enable a Joi schema to output Set from an array:

const schema = Joi.array().unique().convert((arr) => new Set(arr));

…or if you like moment.js:

const schema = Joi.date().convert(moment);

@Marsup
Copy link
Collaborator

Marsup commented Aug 1, 2018

This is getting close to what extensions already do, plus it wouldn't solve your current problem.

@hueniverse
Copy link
Contributor

I don't see the value of the proposed change. It just loses the bigint precision by forcing it into a number. It does the least intuitive thing here. A new bigint type would make more sense but also feels like an overkill and a lot of duplicated code.

I am going to close this due to lack of progress in almost a year.

@hueniverse hueniverse self-assigned this May 31, 2019
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

4 participants