Skip to content

Commit

Permalink
feat: sync validatorjs version from v10.11.3 to v13.0.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vlapo committed Apr 18, 2020
1 parent 11a7b8b commit 09120b7
Show file tree
Hide file tree
Showing 26 changed files with 1,439 additions and 22 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -837,21 +837,34 @@ isBoolean(value);
| `@IsAlphanumeric()` | Checks if the string contains only letters and numbers.
| `@IsDecimal(options?: IsDecimalOptions)` | Checks if the string is a valid decimal value. Default IsDecimalOptions are `force_decimal=False`, `decimal_digits: '1,'`, `locale: 'en-US',` |
| `@IsAscii()` | Checks if the string contains ASCII chars only. |
| `@IsBase32()` | Checks if a string is base32 encoded. |
| `@IsBase64()` | Checks if a string is base64 encoded. |
| `@IsIBAN()` | Checks if a string is a IBAN (International Bank Account Number). |
| `@IsBIC()` | Checks if a string is a BIC (Bank Identification Code) or SWIFT code. |
| `@IsByteLength(min: number, max?: number)` | Checks if the string's length (in bytes) falls in a range. |
| `@IsCreditCard()` | Checks if the string is a credit card. |
| `@IsCurrency(options?: IsCurrencyOptions)` | Checks if the string is a valid currency amount. |
| `@IsEthereumAddress()` | Checks if the string is an Ethereum address using basic regex. Does not validate address checksums. |
| `@IsBtcAddress()` | Checks if the string is a valid BTC address. |
| `@IsDataURI()` | Checks if the string is a data uri format. |
| `@IsEmail(options?: IsEmailOptions)` | Checks if the string is an email. |
| `@IsFQDN(options?: IsFQDNOptions)` | Checks if the string is a fully qualified domain name (e.g. domain.com). |
| `@IsFullWidth()` | Checks if the string contains any full-width chars. |
| `@IsHalfWidth()` | Checks if the string contains any half-width chars. |
| `@IsVariableWidth()` | Checks if the string contains a mixture of full and half-width chars. |
| `@IsHexColor()` | Checks if the string is a hexadecimal color. |
| `@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). |
| `@IsRgbColor(options?: IsRgbOptions)` | Checks if the string is a rgb or rgba color. |
| `@IsIdentityCard(locale?: string)` | Checks if the string is a valid identity card code. |
| `@IsPassportNumber(countryCode?: string)` | Checks if the string is a valid passport number relative to a specific country code. |
| `@IsPostalCode(locale?: string)` | Checks if the string is a postal code. |
| `@IsHexadecimal()` | Checks if the string is a hexadecimal number. |
| `@IsOctal()` | Checks if the string is a octal number. |
| `@IsMACAddress(options?: IsMACAddressOptions)` | Checks if the string is a MAC Address. |
| `@IsIP(version?: "4"\|"6")` | Checks if the string is an IP (version 4 or 6). |
| `@IsPort()` | Check if the string is a valid port number. |
| `@IsISBN(version?: "10"\|"13")` | Checks if the string is an ISBN (version 10 or 13). |
| `@IsEAN()` | Checks if the string is an if the string is an EAN (European Article Number). |
| `@IsISIN()` | Checks if the string is an ISIN (stock/security identifier). |
| `@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. |
| `@IsJSON()` | Checks if the string is valid JSON. |
Expand All @@ -865,12 +878,14 @@ isBoolean(value);
| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. |
| `@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. |
| `@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. |
| `@IsLocale()` | Checks if the string is a locale. |
| `@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) |
| `@IsMongoId()` | Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. |
| `@IsMultibyte()` | Checks if the string contains one or more multibyte chars. |
| `@IsNumberString(options?: IsNumericOptions)` | Checks if the string is numeric. |
| `@IsSurrogatePair()` | Checks if the string contains any surrogate pairs chars. |
| `@IsUrl(options?: IsURLOptions)` | Checks if the string is an url. |
| `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). |
| `@IsUUID(version?: "3"\|"4"\|"5"\|"all")` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
| `@IsFirebasePushId()` | Checks if the string is a [Firebase Push id](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) |
| `@IsUppercase()` | Checks if the string is uppercase. |
Expand All @@ -880,7 +895,11 @@ isBoolean(value);
| `@Matches(pattern: RegExp, modifiers?: string)` | Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').
| `@IsMilitaryTime()` | Checks if the string is a valid representation of military time in the format HH:MM. |
| `@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']` |
| `@IsMimeType()` | Checks if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format |
| `@IsSemVer()` | Checks if the string is a Semantic Versioning Specification (SemVer). |
| `@IsISSN(options?: IsISSNOptions)` | Checks if the string is a ISSN. |
| `@IsISRC()` | Checks if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code). |
| `@IsRFC3339()` | Checks f the string is a valid [RFC 3339](https://tools.ietf.org/html/rfc3339) date. |
| **Array validation decorators** |
| `@ArrayContains(values: any[])` | Checks if array contains all values from the given array of values. |
| `@ArrayNotContains(values: any[])` | Checks if array does not contain any of the given values. |
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -31,9 +31,9 @@
"tslib": ">=1.9.0"
},
"dependencies": {
"@types/validator": "12.0.1",
"@types/validator": "13.0.0",
"google-libphonenumber": "^3.2.8",
"validator": "12.2.0"
"validator": "13.0.0"
},
"devDependencies": {
"@types/chai": "^4.2.0",
Expand Down
19 changes: 19 additions & 0 deletions src/decorator/decorators.ts
Expand Up @@ -92,6 +92,25 @@ export * from "./string/IsISSN";
export * from "./string/IsDateString";
export * from "./string/IsBooleanString";
export * from "./string/IsNumberString";
export * from "./string/IsBase32";
export * from "./string/IsBIC";
export * from "./string/IsBtcAddress";
export * from "./string/IsDataURI";
export * from "./string/IsEAN";
export * from "./string/IsEthereumAddress";
export * from "./string/IsHSL";
export * from "./string/IsIBAN";
export * from "./string/IsIdentityCard";
export * from "./string/IsISRC";
export * from "./string/IsLocale";
export * from "./string/IsMagnetURI";
export * from "./string/IsMimeType";
export * from "./string/IsOctal";
export * from "./string/IsPassportNumber";
export * from "./string/IsPostalCode";
export * from "./string/IsRFC3339";
export * from "./string/IsRgbColor";
export * from "./string/IsSemVer";

// -------------------------------------------------------------------------
// Type checkers
Expand Down
33 changes: 33 additions & 0 deletions src/decorator/string/IsBIC.ts
@@ -0,0 +1,33 @@
import { ValidationOptions } from "../ValidationOptions";
import { buildMessage, ValidateBy } from "../common/ValidateBy";
import validator from "validator";

export const IS_BIC = "isBIC";

/**
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
* If given value is not a string, then it returns false.
*/
export function isBIC(value: unknown): boolean {
return typeof value === "string" && validator.isBIC(value);
}

/**
* Check if a string is a BIC (Bank Identification Code) or SWIFT code.
* If given value is not a string, then it returns false.
*/
export function IsBIC(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_BIC,
validator: {
validate: (value, args) => isBIC(value),
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be a BIC or SWIFT code",
validationOptions
)
}
},
validationOptions
);
}
33 changes: 33 additions & 0 deletions src/decorator/string/IsBase32.ts
@@ -0,0 +1,33 @@
import { ValidationOptions } from "../ValidationOptions";
import { buildMessage, ValidateBy } from "../common/ValidateBy";
import validator from "validator";

export const IS_BASE32 = "isBase32";

/**
* Checks if a string is base32 encoded.
* If given value is not a string, then it returns false.
*/
export function isBase32(value: unknown): boolean {
return typeof value === "string" && validator.isBase32(value);
}

/**
* Check if a string is base32 encoded.
* If given value is not a string, then it returns false.
*/
export function IsBase32(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_BASE32,
validator: {
validate: (value, args) => isBase32(value),
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be base32 encoded",
validationOptions
)
}
},
validationOptions
);
}
33 changes: 33 additions & 0 deletions src/decorator/string/IsBtcAddress.ts
@@ -0,0 +1,33 @@
import { ValidationOptions } from "../ValidationOptions";
import { buildMessage, ValidateBy } from "../common/ValidateBy";
import validator from "validator";

export const IS_BTC_ADDRESS = "isBtcAddress";

/**
* Check if the string is a valid BTC address.
* If given value is not a string, then it returns false.
*/
export function isBtcAddress(value: unknown): boolean {
return typeof value === "string" && validator.isBtcAddress(value);
}

/**
* Check if the string is a valid BTC address.
* If given value is not a string, then it returns false.
*/
export function IsBtcAddress(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_BTC_ADDRESS,
validator: {
validate: (value, args) => isBtcAddress(value),
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be a BTC address",
validationOptions
)
}
},
validationOptions
);
}
33 changes: 33 additions & 0 deletions src/decorator/string/IsDataURI.ts
@@ -0,0 +1,33 @@
import { ValidationOptions } from "../ValidationOptions";
import { buildMessage, ValidateBy } from "../common/ValidateBy";
import validator from "validator";

export const IS_DATA_URI = "isDataURI";

/**
* Check if the string is a data uri format.
* If given value is not a string, then it returns false.
*/
export function isDataURI(value: unknown): boolean {
return typeof value === "string" && validator.isDataURI(value);
}

/**
* Check if the string is a data uri format.
* If given value is not a string, then it returns false.
*/
export function IsDataURI(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_DATA_URI,
validator: {
validate: (value, args) => isDataURI(value),
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be a data uri format",
validationOptions
)
}
},
validationOptions
);
}
33 changes: 33 additions & 0 deletions src/decorator/string/IsEAN.ts
@@ -0,0 +1,33 @@
import { ValidationOptions } from "../ValidationOptions";
import { buildMessage, ValidateBy } from "../common/ValidateBy";
import validator from "validator";

export const IS_EAN = "isEAN";

/**
* Check if the string is an EAN (European Article Number).
* If given value is not a string, then it returns false.
*/
export function isEAN(value: unknown): boolean {
return typeof value === "string" && validator.isEAN(value);
}

/**
* Check if the string is an EAN (European Article Number).
* If given value is not a string, then it returns false.
*/
export function IsEAN(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_EAN,
validator: {
validate: (value, args) => isEAN(value),
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be an EAN (European Article Number)",
validationOptions
)
}
},
validationOptions
);
}

0 comments on commit 09120b7

Please sign in to comment.