-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Currently, there are different ways to define optional parameters.
Many take one options object for these, but some have special string parameters like isIP, which has version. Other combine the two like isAlpha, which takes both a locale string and an options object. This is confusing and not consistent throughout the library.
I propose to unify this so that all optional parameters are put in an options object.
This will affect the following validators;
| Current syntax | Proposed new syntax | New options | Claimed by | PR |
|---|---|---|---|---|
| isAfter(str [, date]) | isAfter(str [, options]) | date | @WikiRik | #2075 (merged) |
| isAlpha(str [, locale, options]) | isAlpha(str [, options]) | locale | @pixelbucket-dev | #2086 |
| isAlphanumeric(str [, locale, options]) | isAlphanumeric(str [, options]) | locale | @pixelbucket-dev | #2087 |
| isBefore(str [, date]) | isBefore(str [, options]) | date | @pixelbucket-dev | #2088 |
| isIdentityCard(str [, locale]) | isIdentityCard(str [, options]) | locale | ||
| isIP(str [, version]) | isIP(str [, options]) | version | @pixelbucket-dev | #2089 |
| isIPRange(str [, version]) | isIPRange(str [, options]) | version | ||
| isISBN(str [, version]) | isISBN(str [, options]) | version | @WikiRik | #2157 (merged) |
| isLicensePlate(str [, locale]) | isLicensePlate(str [, options]) | locale | ||
| isMobilePhone(str [, locale [, options]]) | isMobilePhone(str [, options]) | locale | ||
| isRgbColor(str [, includePercentValues]) | isRgbColor(str [, options]) | includePercentValues | ||
| isTaxID(str, locale) | isTaxID(str, locale [, options]) | localeOption | @Santhosh-Kumar-99 | #2153 (new option) |
| isUUID(str [, version]) | isUUID(str [, options]) | version | ||
| matches(str, pattern [, modifiers]) | matches(str, pattern [, options]) | modifiers |
And the following sanitizers;
| Current syntax | Proposed new syntax | New options | Claimed by | PR |
|---|---|---|---|---|
| ltrim(input [, chars]) | ltrim(input [, options]) | chars | ||
| rtrim(input [, chars]) | rtrim(input [, options]) | chars | ||
| stripLow(input [, keep_new_lines]) | stripLow(input [, options]) | keepNewLines | ||
| toBoolean(input [, strict]) | toBoolean(input [, options]) | strict | ||
| toInt(input [, radix]) | toInt(input [, options]) | radix | ||
| trim(input [, chars]) | trim(input [, options]) | chars |
The idea is that the changes are backwards compatible, so after implementing this both isAlpha(str, locale, options) and isAlpha(str, options) are supported. There will be a message for the first one that the usage is deprecated and the new syntax would be shown.
I am willing to make all these changes and include tests for backwards compatibility, but I'm also willing to rewrite the README file and take up one of them as an example so the community can contribute to the others.
EDIT: I forgot about the TypeScript types, I'm not very knowledgeable about those so I will need help with those either way.
What do you think about this proposal? Is this a valid change, or are some of these not needed since they only allow one kind of option? Feel free to discuss.