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

is[Byte]Length() should accept {min, max} as options #474

Closed
franciscolourenco opened this issue Jan 18, 2016 · 2 comments · Fixed by #475
Closed

is[Byte]Length() should accept {min, max} as options #474

franciscolourenco opened this issue Jan 18, 2016 · 2 comments · Fixed by #475

Comments

@franciscolourenco
Copy link
Contributor

Because:

  • Consistency with isInt({min:0, max:0}) and isFloat({min:0, max: 0})
  • Consistency with isCurrency(str, {options})
  • Avoids confusions like isLength fails #465
  • Better readability:
    • isLength(str, 4) reads like (str.length == 4), but actually is (str.length >= 4)
    • Before: isLength(str, 4, 10) what do 4 and 10 mean?
    • After: isLength(str, {min: 4, max:10})

Also (edit):

  • Backward compatibility can be maintained.
  • Allows isLength({max: 10})
@franciscolourenco franciscolourenco changed the title isLenght()/ isByteLenght() should accept {min: 0, max: 0} as options. isLenght()/isByteLenght() should accept {min, max} as options Jan 18, 2016
@franciscolourenco franciscolourenco changed the title isLenght()/isByteLenght() should accept {min, max} as options is[Byte]Lenght() should accept {min, max} as options Jan 18, 2016
@chriso
Copy link
Collaborator

chriso commented Jan 18, 2016

Agreed, I'd be happy to accept a PR to add this form, as long as backwards compatibility is maintained.

@franciscolourenco
Copy link
Contributor Author

Working on PR.

@franciscolourenco franciscolourenco changed the title is[Byte]Lenght() should accept {min, max} as options is[Byte]Length() should accept {min, max} as options Jan 18, 2016
franciscolourenco added a commit to franciscolourenco/validator.js that referenced this issue Jan 19, 2016
…n, max}`

Usage:
- `isLength(str, {min: 4, max: 6})`;
- `isLength(str, {min: 4})`;
- `isLength(str, {max: 10})`;

Because:
- More consitent with `isInt({min:0, max:0})` and `isFloat({min:0, max: 0})`
- More consitent with `isCurrency(str, options)`
- Avoids confusions like validatorjs#465
- Allows `isLength({max: 10})`
- Backwards compatible.
- Better readability:
   - `isLength(str, 4)` reads like `(str.length == 4)`, but actually is `(str.length >= 4)`
   - Before: `isLength(str, 4, 10)` what do 4 and 10 mean?
   - After: `isLength(str, {min: 4, max:10})`

closes validatorjs#474
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

Successfully merging a pull request may close this issue.

2 participants