Skip to content

Commit d797c05

Browse files
fix: import only the used Validator.js function in decorators
1 parent 68d1303 commit d797c05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+140
-124
lines changed

src/decorator/common/IsLatLong.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from './ValidateBy';
3-
import validator from 'validator';
3+
import isLatLongValidator from 'validator/es/lib/isLatLong';
44

55
export const IS_LATLONG = 'isLatLong';
66

77
/**
88
* Checks if a value is string in format a "latitude,longitude".
99
*/
1010
export function isLatLong(value: string): boolean {
11-
return typeof value === 'string' && validator.isLatLong(value);
11+
return typeof value === 'string' && isLatLongValidator(value);
1212
}
1313

1414
/**

src/decorator/number/IsDivisibleBy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isDivisibleByValidator from 'validator/es/lib/isDivisibleBy';
44

55
export const IS_DIVISIBLE_BY = 'isDivisibleBy';
66

77
/**
88
* Checks if value is a number that's divisible by another.
99
*/
1010
export function isDivisibleBy(value: unknown, num: number): boolean {
11-
return typeof value === 'number' && typeof num === 'number' && validator.isDivisibleBy(String(value), num);
11+
return typeof value === 'number' && typeof num === 'number' && isDivisibleByValidator(String(value), num);
1212
}
1313

1414
/**

src/decorator/string/Contains.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import containsValidator from 'validator/es/lib//contains';
44

55
export const CONTAINS = 'contains';
66

@@ -9,7 +9,7 @@ export const CONTAINS = 'contains';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function contains(value: unknown, seed: string): boolean {
12-
return typeof value === 'string' && validator.contains(value, seed);
12+
return typeof value === 'string' && containsValidator(value, seed);
1313
}
1414

1515
/**

src/decorator/string/IsAlpha.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isAlphaValidator from 'validator/es/lib/isAlpha';
34
import ValidatorJS from 'validator';
45

56
export const IS_ALPHA = 'isAlpha';
@@ -9,7 +10,7 @@ export const IS_ALPHA = 'isAlpha';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isAlpha(value: unknown, locale?: ValidatorJS.AlphaLocale): boolean {
12-
return typeof value === 'string' && ValidatorJS.isAlpha(value, locale);
13+
return typeof value === 'string' && isAlphaValidator(value, locale);
1314
}
1415

1516
/**

src/decorator/string/IsAlphanumeric.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isAlphanumericValidator from 'validator/es/lib/isAlphanumeric';
34
import ValidatorJS from 'validator';
45

56
export const IS_ALPHANUMERIC = 'isAlphanumeric';
@@ -9,7 +10,7 @@ export const IS_ALPHANUMERIC = 'isAlphanumeric';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isAlphanumeric(value: unknown, locale?: ValidatorJS.AlphanumericLocale): boolean {
12-
return typeof value === 'string' && ValidatorJS.isAlphanumeric(value, locale);
13+
return typeof value === 'string' && isAlphanumericValidator(value, locale);
1314
}
1415

1516
/**

src/decorator/string/IsAscii.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isAsciiValidator from 'validator/es/lib/isAscii';
44

55
export const IS_ASCII = 'isAscii';
66

@@ -9,7 +9,7 @@ export const IS_ASCII = 'isAscii';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isAscii(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isAscii(value);
12+
return typeof value === 'string' && isAsciiValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsBIC.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isBICValidator from 'validator/es/lib/isBIC';
44

55
export const IS_BIC = 'isBIC';
66

@@ -9,7 +9,7 @@ export const IS_BIC = 'isBIC';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isBIC(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isBIC(value);
12+
return typeof value === 'string' && isBICValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsBase32.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isBase32Validator from 'validator/es/lib/isBase32';
44

55
export const IS_BASE32 = 'isBase32';
66

@@ -9,7 +9,7 @@ export const IS_BASE32 = 'isBase32';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isBase32(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isBase32(value);
12+
return typeof value === 'string' && isBase32Validator(value);
1313
}
1414

1515
/**

src/decorator/string/IsBase64.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isBase64Validator from 'validator/es/lib/isBase64';
44

55
export const IS_BASE64 = 'isBase64';
66

@@ -9,7 +9,7 @@ export const IS_BASE64 = 'isBase64';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isBase64(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isBase64(value);
12+
return typeof value === 'string' && isBase64Validator(value);
1313
}
1414

1515
/**

src/decorator/string/IsBooleanString.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isBooleanValidator from 'validator/es/lib/isBoolean';
44

55
export const IS_BOOLEAN_STRING = 'isBooleanString';
66

@@ -9,7 +9,7 @@ export const IS_BOOLEAN_STRING = 'isBooleanString';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isBooleanString(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isBoolean(value);
12+
return typeof value === 'string' && isBooleanValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsBtcAddress.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isBtcAddressValidator from 'validator/es/lib/isBtcAddress';
44

55
export const IS_BTC_ADDRESS = 'isBtcAddress';
66

@@ -9,7 +9,7 @@ export const IS_BTC_ADDRESS = 'isBtcAddress';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isBtcAddress(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isBtcAddress(value);
12+
return typeof value === 'string' && isBtcAddressValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsByteLength.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isByteLengthValidator from 'validator/es/lib/isByteLength';
44

55
export const IS_BYTE_LENGTH = 'isByteLength';
66

@@ -9,7 +9,7 @@ export const IS_BYTE_LENGTH = 'isByteLength';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isByteLength(value: unknown, min: number, max?: number): boolean {
12-
return typeof value === 'string' && validator.isByteLength(value, { min, max });
12+
return typeof value === 'string' && isByteLengthValidator(value, { min, max });
1313
}
1414

1515
/**

src/decorator/string/IsCreditCard.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isCreditCardValidator from 'validator/es/lib/isCreditCard';
44

55
export const IS_CREDIT_CARD = 'isCreditCard';
66

@@ -9,7 +9,7 @@ export const IS_CREDIT_CARD = 'isCreditCard';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isCreditCard(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isCreditCard(value);
12+
return typeof value === 'string' && isCreditCardValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsCurrency.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isCurrencyValidator from 'validator/es/lib/isCurrency';
34
import ValidatorJS from 'validator';
45

56
export const IS_CURRENCY = 'isCurrency';
@@ -9,7 +10,7 @@ export const IS_CURRENCY = 'isCurrency';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isCurrency(value: unknown, options?: ValidatorJS.IsCurrencyOptions): boolean {
12-
return typeof value === 'string' && ValidatorJS.isCurrency(value, options);
13+
return typeof value === 'string' && isCurrencyValidator(value, options);
1314
}
1415

1516
/**

src/decorator/string/IsDataURI.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isDataURIValidator from 'validator/es/lib/isDataURI';
44

55
export const IS_DATA_URI = 'isDataURI';
66

@@ -9,7 +9,7 @@ export const IS_DATA_URI = 'isDataURI';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isDataURI(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isDataURI(value);
12+
return typeof value === 'string' && isDataURIValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsDecimal.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isDecimalValidator from 'validator/es/lib/isDecimal';
34
import ValidatorJS from 'validator';
45

56
export const IS_DECIMAL = 'isDecimal';
@@ -9,7 +10,7 @@ export const IS_DECIMAL = 'isDecimal';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isDecimal(value: unknown, options?: ValidatorJS.IsDecimalOptions): boolean {
12-
return typeof value === 'string' && ValidatorJS.isDecimal(value, options);
13+
return typeof value === 'string' && isDecimalValidator(value, options);
1314
}
1415

1516
/**

src/decorator/string/IsEAN.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isEANValidator from 'validator/es/lib/isEAN';
44

55
export const IS_EAN = 'isEAN';
66

@@ -9,7 +9,7 @@ export const IS_EAN = 'isEAN';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isEAN(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isEAN(value);
12+
return typeof value === 'string' && isEANValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsEmail.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isEmailValidator from 'validator/es/lib/isEmail';
34
import ValidatorJS from 'validator';
45

56
export const IS_EMAIL = 'isEmail';
@@ -9,7 +10,7 @@ export const IS_EMAIL = 'isEmail';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isEmail(value: unknown, options?: ValidatorJS.IsEmailOptions): boolean {
12-
return typeof value === 'string' && ValidatorJS.isEmail(value, options);
13+
return typeof value === 'string' && isEmailValidator(value, options);
1314
}
1415

1516
/**

src/decorator/string/IsEthereumAddress.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isEthereumAddressValidator from 'validator/es/lib/isEthereumAddress';
44

55
export const IS_ETHEREUM_ADDRESS = 'isEthereumAddress';
66

@@ -9,7 +9,7 @@ export const IS_ETHEREUM_ADDRESS = 'isEthereumAddress';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isEthereumAddress(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isEthereumAddress(value);
12+
return typeof value === 'string' && isEthereumAddressValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsFQDN.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3+
import isFqdnValidator from 'validator/es/lib/isFQDN';
34
import ValidatorJS from 'validator';
45

56
export const IS_FQDN = 'isFqdn';
@@ -9,7 +10,7 @@ export const IS_FQDN = 'isFqdn';
910
* If given value is not a string, then it returns false.
1011
*/
1112
export function isFQDN(value: unknown, options?: ValidatorJS.IsFQDNOptions): boolean {
12-
return typeof value === 'string' && ValidatorJS.isFQDN(value, options);
13+
return typeof value === 'string' && isFqdnValidator(value, options);
1314
}
1415

1516
/**

src/decorator/string/IsFullWidth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isFullWidthValidator from 'validator/es/lib/isFullWidth';
44

55
export const IS_FULL_WIDTH = 'isFullWidth';
66

@@ -9,7 +9,7 @@ export const IS_FULL_WIDTH = 'isFullWidth';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isFullWidth(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isFullWidth(value);
12+
return typeof value === 'string' && isFullWidthValidator(value);
1313
}
1414

1515
/**

src/decorator/string/IsHSL.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isHSLValidator from 'validator/es/lib/isHSL';
44

55
export const IS_HSL = 'isHSL';
66

@@ -10,7 +10,7 @@ export const IS_HSL = 'isHSL';
1010
* If given value is not a string, then it returns false.
1111
*/
1212
export function isHSL(value: unknown): boolean {
13-
return typeof value === 'string' && validator.isHSL(value);
13+
return typeof value === 'string' && isHSLValidator(value);
1414
}
1515

1616
/**

src/decorator/string/IsHalfWidth.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ValidationOptions } from '../ValidationOptions';
22
import { buildMessage, ValidateBy } from '../common/ValidateBy';
3-
import validator from 'validator';
3+
import isHalfWidthValidator from 'validator/es/lib/isHalfWidth';
44

55
export const IS_HALF_WIDTH = 'isHalfWidth';
66

@@ -9,7 +9,7 @@ export const IS_HALF_WIDTH = 'isHalfWidth';
99
* If given value is not a string, then it returns false.
1010
*/
1111
export function isHalfWidth(value: unknown): boolean {
12-
return typeof value === 'string' && validator.isHalfWidth(value);
12+
return typeof value === 'string' && isHalfWidthValidator(value);
1313
}
1414

1515
/**

0 commit comments

Comments
 (0)