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

Use readonly arrays for validator options #1061

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions declarations/validator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ declare module 'validator' {
export function isISO31661Alpha2(str: string): boolean;
export function isISO31661Alpha3(str: string): boolean;
export function isISRC(str: string): boolean;
export function isIn(str: string, values: any[]): boolean;
export function isIn(str: string, values: readonly any[]): boolean;
export function isInt(str: string, options?: import('../src/options').IsIntOptions): boolean;
export function isJSON(str: string, options?: import('../src/options').IsJSONOptions): boolean;
export function isJWT(str: string): boolean;
Expand All @@ -94,7 +94,7 @@ declare module 'validator' {
str: string,
locale:
| import('../src/options').MobilePhoneLocale
| import('../src/options').MobilePhoneLocale[],
| readonly import('../src/options').MobilePhoneLocale[],
options?: import('../src/options').IsMobilePhoneOptions,
): boolean;
export function isMongoId(str: string): boolean;
Expand Down Expand Up @@ -128,7 +128,7 @@ declare module 'validator' {
export function isUppercase(str: string): boolean;
export function isVariableWidth(str: string): boolean;
export function isVAT(str: string, countryCode: import('../src/options').VATCountryCode): boolean;
export function isWhitelisted(str: string, chars: string | string[]): boolean;
export function isWhitelisted(str: string, chars: string | readonly string[]): boolean;
export function matches(str: string, pattern: RegExp | string, modifiers?: string): boolean;

export function blacklist(str: string, chars: string): string;
Expand Down
6 changes: 3 additions & 3 deletions src/chain/validators-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class ValidatorsImpl<Chain> implements Validators<Chain> {
isISRC() {
return this.addStandardValidation(validator.isISRC);
}
isIn(values: any[]) {
isIn(values: readonly any[]) {
return this.addStandardValidation(validator.isIn, values);
}
isInt(options?: Options.IsIntOptions) {
Expand Down Expand Up @@ -255,7 +255,7 @@ export class ValidatorsImpl<Chain> implements Validators<Chain> {
return this.addStandardValidation(validator.isMimeType);
}
isMobilePhone(
locale: Options.MobilePhoneLocale | Options.MobilePhoneLocale[],
locale: Options.MobilePhoneLocale | readonly Options.MobilePhoneLocale[],
options?: Options.IsMobilePhoneOptions,
) {
return this.addStandardValidation(validator.isMobilePhone, locale, options);
Expand Down Expand Up @@ -317,7 +317,7 @@ export class ValidatorsImpl<Chain> implements Validators<Chain> {
isVAT(countryCode: Options.VATCountryCode) {
return this.addStandardValidation(validator.isVAT, countryCode);
}
isWhitelisted(chars: string | string[]) {
isWhitelisted(chars: string | readonly string[]) {
return this.addStandardValidation(validator.isWhitelisted, chars);
}
matches(pattern: RegExp | string, modifiers?: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/chain/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface Validators<Return> {
isISO31661Alpha2(): Return;
isISO31661Alpha3(): Return;
isISRC(): Return;
isIn(values: any[]): Return;
isIn(values: readonly any[]): Return;
isInt(options?: Options.IsIntOptions): Return;
isJSON(options?: Options.IsJSONOptions): Return;
isJWT(): Return;
Expand All @@ -76,7 +76,7 @@ export interface Validators<Return> {
isMD5(): Return;
isMimeType(): Return;
isMobilePhone(
locale: Options.MobilePhoneLocale | Options.MobilePhoneLocale[],
locale: Options.MobilePhoneLocale | readonly Options.MobilePhoneLocale[],
options?: Options.IsMobilePhoneOptions,
): Return;
isMongoId(): Return;
Expand All @@ -98,6 +98,6 @@ export interface Validators<Return> {
isUppercase(): Return;
isVariableWidth(): Return;
isVAT(countryCode: Options.VATCountryCode): Return;
isWhitelisted(chars: string | string[]): Return;
isWhitelisted(chars: string | readonly string[]): Return;
matches(pattern: RegExp | string, modifiers?: string): Return;
}