Skip to content

Commit 09120b7

Browse files
committed
feat: sync validatorjs version from v10.11.3 to v13.0.0
added new valdiators: `IsBase32`, `IsBIC`, `IsBtcAddress`, `IsDataURI`, `IsEAN`, `IsEthereumAddress`, `IsHSL`, `IsIBAN`, IsIdentityCard`, `IsISRC`, `IsLocale`, `IsMagnetURI`, `IsMimeType`, `IsOctal`, `IsPassportNumber`, `IsPostalCode`, `IsRFC3339`, `IsRgbColor`, `IsSemVer` BREAKING CHANGE: Validatorjs releases contain some breaking changes e.g. `IsMobileNumber` or `IsHexColor`. Please check validatorjs [CHANGELOG] Closes #576, #425
1 parent 11a7b8b commit 09120b7

26 files changed

+1439
-22
lines changed

Diff for: README.md

+19
Original file line numberDiff line numberDiff line change
@@ -837,21 +837,34 @@ isBoolean(value);
837837
| `@IsAlphanumeric()` | Checks if the string contains only letters and numbers.
838838
| `@IsDecimal(options?: IsDecimalOptions)` | Checks if the string is a valid decimal value. Default IsDecimalOptions are `force_decimal=False`, `decimal_digits: '1,'`, `locale: 'en-US',` |
839839
| `@IsAscii()` | Checks if the string contains ASCII chars only. |
840+
| `@IsBase32()` | Checks if a string is base32 encoded. |
840841
| `@IsBase64()` | Checks if a string is base64 encoded. |
842+
| `@IsIBAN()` | Checks if a string is a IBAN (International Bank Account Number). |
843+
| `@IsBIC()` | Checks if a string is a BIC (Bank Identification Code) or SWIFT code. |
841844
| `@IsByteLength(min: number, max?: number)` | Checks if the string's length (in bytes) falls in a range. |
842845
| `@IsCreditCard()` | Checks if the string is a credit card. |
843846
| `@IsCurrency(options?: IsCurrencyOptions)` | Checks if the string is a valid currency amount. |
847+
| `@IsEthereumAddress()` | Checks if the string is an Ethereum address using basic regex. Does not validate address checksums. |
848+
| `@IsBtcAddress()` | Checks if the string is a valid BTC address. |
849+
| `@IsDataURI()` | Checks if the string is a data uri format. |
844850
| `@IsEmail(options?: IsEmailOptions)` | Checks if the string is an email. |
845851
| `@IsFQDN(options?: IsFQDNOptions)` | Checks if the string is a fully qualified domain name (e.g. domain.com). |
846852
| `@IsFullWidth()` | Checks if the string contains any full-width chars. |
847853
| `@IsHalfWidth()` | Checks if the string contains any half-width chars. |
848854
| `@IsVariableWidth()` | Checks if the string contains a mixture of full and half-width chars. |
849855
| `@IsHexColor()` | Checks if the string is a hexadecimal color. |
856+
| `@IsHSLColor()` | Checks if the string is an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). |
857+
| `@IsRgbColor(options?: IsRgbOptions)` | Checks if the string is a rgb or rgba color. |
858+
| `@IsIdentityCard(locale?: string)` | Checks if the string is a valid identity card code. |
859+
| `@IsPassportNumber(countryCode?: string)` | Checks if the string is a valid passport number relative to a specific country code. |
860+
| `@IsPostalCode(locale?: string)` | Checks if the string is a postal code. |
850861
| `@IsHexadecimal()` | Checks if the string is a hexadecimal number. |
862+
| `@IsOctal()` | Checks if the string is a octal number. |
851863
| `@IsMACAddress(options?: IsMACAddressOptions)` | Checks if the string is a MAC Address. |
852864
| `@IsIP(version?: "4"\|"6")` | Checks if the string is an IP (version 4 or 6). |
853865
| `@IsPort()` | Check if the string is a valid port number. |
854866
| `@IsISBN(version?: "10"\|"13")` | Checks if the string is an ISBN (version 10 or 13). |
867+
| `@IsEAN()` | Checks if the string is an if the string is an EAN (European Article Number). |
855868
| `@IsISIN()` | Checks if the string is an ISIN (stock/security identifier). |
856869
| `@IsISO8601(options?: IsISO8601Options)` | Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29. |
857870
| `@IsJSON()` | Checks if the string is valid JSON. |
@@ -865,12 +878,14 @@ isBoolean(value);
865878
| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. |
866879
| `@IsISO31661Alpha2()` | Checks if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. |
867880
| `@IsISO31661Alpha3()` | Checks if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. |
881+
| `@IsLocale()` | Checks if the string is a locale. |
868882
| `@IsPhoneNumber(region: string)` | Checks if the string is a valid phone number. "region" accepts 2 characters uppercase country code (e.g. DE, US, CH).If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region. See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github](https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33) |
869883
| `@IsMongoId()` | Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. |
870884
| `@IsMultibyte()` | Checks if the string contains one or more multibyte chars. |
871885
| `@IsNumberString(options?: IsNumericOptions)` | Checks if the string is numeric. |
872886
| `@IsSurrogatePair()` | Checks if the string contains any surrogate pairs chars. |
873887
| `@IsUrl(options?: IsURLOptions)` | Checks if the string is an url. |
888+
| `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). |
874889
| `@IsUUID(version?: "3"\|"4"\|"5"\|"all")` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
875890
| `@IsFirebasePushId()` | Checks if the string is a [Firebase Push id](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) |
876891
| `@IsUppercase()` | Checks if the string is uppercase. |
@@ -880,7 +895,11 @@ isBoolean(value);
880895
| `@Matches(pattern: RegExp, modifiers?: string)` | Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').
881896
| `@IsMilitaryTime()` | Checks if the string is a valid representation of military time in the format HH:MM. |
882897
| `@IsHash(algorithm: string)` | Checks if the string is a hash of type algorithm. <br/><br/>Algorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']` |
898+
| `@IsMimeType()` | Checks if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format |
899+
| `@IsSemVer()` | Checks if the string is a Semantic Versioning Specification (SemVer). |
883900
| `@IsISSN(options?: IsISSNOptions)` | Checks if the string is a ISSN. |
901+
| `@IsISRC()` | Checks if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). |
902+
| `@IsRFC3339()` | Checks f the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. |
884903
| **Array validation decorators** |
885904
| `@ArrayContains(values: any[])` | Checks if array contains all values from the given array of values. |
886905
| `@ArrayNotContains(values: any[])` | Checks if array does not contain any of the given values. |

Diff for: package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"tslib": ">=1.9.0"
3232
},
3333
"dependencies": {
34-
"@types/validator": "12.0.1",
34+
"@types/validator": "13.0.0",
3535
"google-libphonenumber": "^3.2.8",
36-
"validator": "12.2.0"
36+
"validator": "13.0.0"
3737
},
3838
"devDependencies": {
3939
"@types/chai": "^4.2.0",

Diff for: src/decorator/decorators.ts

+19
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ export * from "./string/IsISSN";
9292
export * from "./string/IsDateString";
9393
export * from "./string/IsBooleanString";
9494
export * from "./string/IsNumberString";
95+
export * from "./string/IsBase32";
96+
export * from "./string/IsBIC";
97+
export * from "./string/IsBtcAddress";
98+
export * from "./string/IsDataURI";
99+
export * from "./string/IsEAN";
100+
export * from "./string/IsEthereumAddress";
101+
export * from "./string/IsHSL";
102+
export * from "./string/IsIBAN";
103+
export * from "./string/IsIdentityCard";
104+
export * from "./string/IsISRC";
105+
export * from "./string/IsLocale";
106+
export * from "./string/IsMagnetURI";
107+
export * from "./string/IsMimeType";
108+
export * from "./string/IsOctal";
109+
export * from "./string/IsPassportNumber";
110+
export * from "./string/IsPostalCode";
111+
export * from "./string/IsRFC3339";
112+
export * from "./string/IsRgbColor";
113+
export * from "./string/IsSemVer";
95114

96115
// -------------------------------------------------------------------------
97116
// Type checkers

Diff for: src/decorator/string/IsBIC.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ValidationOptions } from "../ValidationOptions";
2+
import { buildMessage, ValidateBy } from "../common/ValidateBy";
3+
import validator from "validator";
4+
5+
export const IS_BIC = "isBIC";
6+
7+
/**
8+
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
9+
* If given value is not a string, then it returns false.
10+
*/
11+
export function isBIC(value: unknown): boolean {
12+
return typeof value === "string" && validator.isBIC(value);
13+
}
14+
15+
/**
16+
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
17+
* If given value is not a string, then it returns false.
18+
*/
19+
export function IsBIC(validationOptions?: ValidationOptions): PropertyDecorator {
20+
return ValidateBy(
21+
{
22+
name: IS_BIC,
23+
validator: {
24+
validate: (value, args) => isBIC(value),
25+
defaultMessage: buildMessage(
26+
(eachPrefix) => eachPrefix + "$property must be a BIC or SWIFT code",
27+
validationOptions
28+
)
29+
}
30+
},
31+
validationOptions
32+
);
33+
}

Diff for: src/decorator/string/IsBase32.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ValidationOptions } from "../ValidationOptions";
2+
import { buildMessage, ValidateBy } from "../common/ValidateBy";
3+
import validator from "validator";
4+
5+
export const IS_BASE32 = "isBase32";
6+
7+
/**
8+
* Checks if a string is base32 encoded.
9+
* If given value is not a string, then it returns false.
10+
*/
11+
export function isBase32(value: unknown): boolean {
12+
return typeof value === "string" && validator.isBase32(value);
13+
}
14+
15+
/**
16+
* Check if a string is base32 encoded.
17+
* If given value is not a string, then it returns false.
18+
*/
19+
export function IsBase32(validationOptions?: ValidationOptions): PropertyDecorator {
20+
return ValidateBy(
21+
{
22+
name: IS_BASE32,
23+
validator: {
24+
validate: (value, args) => isBase32(value),
25+
defaultMessage: buildMessage(
26+
(eachPrefix) => eachPrefix + "$property must be base32 encoded",
27+
validationOptions
28+
)
29+
}
30+
},
31+
validationOptions
32+
);
33+
}

Diff for: src/decorator/string/IsBtcAddress.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ValidationOptions } from "../ValidationOptions";
2+
import { buildMessage, ValidateBy } from "../common/ValidateBy";
3+
import validator from "validator";
4+
5+
export const IS_BTC_ADDRESS = "isBtcAddress";
6+
7+
/**
8+
* Check if the string is a valid BTC address.
9+
* If given value is not a string, then it returns false.
10+
*/
11+
export function isBtcAddress(value: unknown): boolean {
12+
return typeof value === "string" && validator.isBtcAddress(value);
13+
}
14+
15+
/**
16+
* Check if the string is a valid BTC address.
17+
* If given value is not a string, then it returns false.
18+
*/
19+
export function IsBtcAddress(validationOptions?: ValidationOptions): PropertyDecorator {
20+
return ValidateBy(
21+
{
22+
name: IS_BTC_ADDRESS,
23+
validator: {
24+
validate: (value, args) => isBtcAddress(value),
25+
defaultMessage: buildMessage(
26+
(eachPrefix) => eachPrefix + "$property must be a BTC address",
27+
validationOptions
28+
)
29+
}
30+
},
31+
validationOptions
32+
);
33+
}

Diff for: src/decorator/string/IsDataURI.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ValidationOptions } from "../ValidationOptions";
2+
import { buildMessage, ValidateBy } from "../common/ValidateBy";
3+
import validator from "validator";
4+
5+
export const IS_DATA_URI = "isDataURI";
6+
7+
/**
8+
* Check if the string is a data uri format.
9+
* If given value is not a string, then it returns false.
10+
*/
11+
export function isDataURI(value: unknown): boolean {
12+
return typeof value === "string" && validator.isDataURI(value);
13+
}
14+
15+
/**
16+
* Check if the string is a data uri format.
17+
* If given value is not a string, then it returns false.
18+
*/
19+
export function IsDataURI(validationOptions?: ValidationOptions): PropertyDecorator {
20+
return ValidateBy(
21+
{
22+
name: IS_DATA_URI,
23+
validator: {
24+
validate: (value, args) => isDataURI(value),
25+
defaultMessage: buildMessage(
26+
(eachPrefix) => eachPrefix + "$property must be a data uri format",
27+
validationOptions
28+
)
29+
}
30+
},
31+
validationOptions
32+
);
33+
}

Diff for: src/decorator/string/IsEAN.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ValidationOptions } from "../ValidationOptions";
2+
import { buildMessage, ValidateBy } from "../common/ValidateBy";
3+
import validator from "validator";
4+
5+
export const IS_EAN = "isEAN";
6+
7+
/**
8+
* Check if the string is an EAN (European Article Number).
9+
* If given value is not a string, then it returns false.
10+
*/
11+
export function isEAN(value: unknown): boolean {
12+
return typeof value === "string" && validator.isEAN(value);
13+
}
14+
15+
/**
16+
* Check if the string is an EAN (European Article Number).
17+
* If given value is not a string, then it returns false.
18+
*/
19+
export function IsEAN(validationOptions?: ValidationOptions): PropertyDecorator {
20+
return ValidateBy(
21+
{
22+
name: IS_EAN,
23+
validator: {
24+
validate: (value, args) => isEAN(value),
25+
defaultMessage: buildMessage(
26+
(eachPrefix) => eachPrefix + "$property must be an EAN (European Article Number)",
27+
validationOptions
28+
)
29+
}
30+
},
31+
validationOptions
32+
);
33+
}

0 commit comments

Comments
 (0)