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

sugar feature: string length #53

Closed
Eomm opened this issue Nov 18, 2019 · 1 comment
Closed

sugar feature: string length #53

Eomm opened this issue Nov 18, 2019 · 1 comment

Comments

@Eomm
Copy link
Member

Eomm commented Nov 18, 2019

🚀 Feature Proposal

Add a .length(24) method as a shortcut for min + max length.

Motivation

Right now to add a check for a string I need to write:

S.string().minLength(24).maxLength(24)

Example

S.string().length(24)

WDYT?

@aboutlo
Copy link
Collaborator

aboutlo commented Nov 20, 2019

I like the idea of having shortcuts. However, diverging from the JSON Schema API could bring issues in the future.
What if length would be added in the spec with a different meaning?
As well the saving or the productivity boost isn't that much.

Maybe you could have a shortcut definition for your usecase

const sLenght = (length) => S.string().minLength(length).maxLength(length)
S.object().prop('foo', sLenght(24))

@aboutlo aboutlo closed this as completed Jan 24, 2020
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