Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

class-validator

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-validator - npm Package Compare versions

Comparing version 0.4.0-alpha.1 to 0.4.0-alpha.2

16

decorator/decorators.d.ts

@@ -18,2 +18,6 @@ import { IsEmailOptions, IsFQDNOptions, IsURLOptions, IsCurrencyOptions } from "../validation/ValidationTypeOptions";

/**
* Checks if given value is defined (!== undefined, !== null).
*/
export declare function IsDefined(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if the value match ("===") the comparison.

@@ -29,19 +33,15 @@ */

*/
export declare function Empty(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
export declare function IsEmpty(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if given value is not empty (!== '', !== null, !== undefined).
*/
export declare function NotEmpty(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
export declare function IsNotEmpty(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if given value is defined (!== undefined).
*/
export declare function IsDefined(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if value is in a array of allowed values.
*/
export declare function In(values: any[], validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
export declare function IsIn(values: any[], validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if value is not in a array of disallowed values.
*/
export declare function NotIn(values: any[], validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
export declare function IsNotIn(values: any[], validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**

@@ -48,0 +48,0 @@ * Checks if a value is a boolean.

@@ -57,2 +57,17 @@ "use strict";

/**
* Checks if given value is defined (!== undefined, !== null).
*/
function IsDefined(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_DEFINED,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
index_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsDefined = IsDefined;
/**
* Checks if the value match ("===") the comparison.

@@ -92,6 +107,6 @@ */

*/
function Empty(validationOptions) {
function IsEmpty(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.EMPTY,
type: ValidationTypes_1.ValidationTypes.IS_EMPTY,
target: object.constructor,

@@ -104,10 +119,10 @@ propertyName: propertyName,

}
exports.Empty = Empty;
exports.IsEmpty = IsEmpty;
/**
* Checks if given value is not empty (!== '', !== null, !== undefined).
*/
function NotEmpty(validationOptions) {
function IsNotEmpty(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.NOT_EMPTY,
type: ValidationTypes_1.ValidationTypes.IS_NOT_EMPTY,
target: object.constructor,

@@ -120,25 +135,10 @@ propertyName: propertyName,

}
exports.NotEmpty = NotEmpty;
exports.IsNotEmpty = IsNotEmpty;
/**
* Checks if given value is defined (!== undefined).
*/
function IsDefined(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_DEFINED,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
index_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsDefined = IsDefined;
/**
* Checks if value is in a array of allowed values.
*/
function In(values, validationOptions) {
function IsIn(values, validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IN,
type: ValidationTypes_1.ValidationTypes.IS_IN,
target: object.constructor,

@@ -152,10 +152,10 @@ propertyName: propertyName,

}
exports.In = In;
exports.IsIn = IsIn;
/**
* Checks if value is not in a array of disallowed values.
*/
function NotIn(values, validationOptions) {
function IsNotIn(values, validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.NOT_IN,
type: ValidationTypes_1.ValidationTypes.IS_NOT_IN,
target: object.constructor,

@@ -169,3 +169,3 @@ propertyName: propertyName,

}
exports.NotIn = NotIn;
exports.IsNotIn = IsNotIn;
// -------------------------------------------------------------------------

@@ -172,0 +172,0 @@ // Type checkers

{
"name": "class-validator",
"private": false,
"version": "0.4.0-alpha.1",
"version": "0.4.0-alpha.2",
"description": "Class-based validation in Typescript using decorators",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -442,4 +442,4 @@ # class-validator

validator.notEquals(value, comparison); // Checks if value does not match ("!==") the comparison.
validator.empty(value); // Checks if given value is empty (=== '', === null, === undefined).
validator.notEmpty(value); // Checks if given value is not empty (!== '', !== null, !== undefined).
validator.isEmpty(value); // Checks if given value is empty (=== '', === null, === undefined).
validator.isNotEmpty(value); // Checks if given value is not empty (!== '', !== null, !== undefined).
validator.isIn(value, possibleValues); // Checks if given value is in a array of allowed values.

@@ -521,9 +521,9 @@ validator.isNotIn(value, possibleValues); // Checks if given value not in a array of allowed values.

| **Common validation decorators** |
| `@IsDefined(value: any)` | Checks if value is defined ("!==undefined"). This is the only decorator that ignores skipMissingProperties validation option. |
| `@IsDefined(value: any)` | Checks if value is defined (!== undefined, !== null). This is the only decorator that ignores skipMissingProperties option. |
| `@Equals(comparison: any)` | Checks if value equals ("===") comparison. |
| `@NotEquals(comparison: any)` | Checks if value not equal ("!==") comparison. |
| `@Empty()` | Checks if given value is empty (=== '', === null, === undefined). |
| `@NotEmpty()` | Checks if given value is not empty (!== '', !== null, !== undefined). |
| `@In(values: any[])` | Checks if value is in a array of allowed values. |
| `@NotIn(values: any[])` | Checks if value is not in a array of disallowed values. |
| `@IsEmpty()` | Checks if given value is empty (=== '', === null, === undefined). |
| `@IsNotEmpty()` | Checks if given value is not empty (!== '', !== null, !== undefined). |
| `@IsIn(values: any[])` | Checks if value is in a array of allowed values. |
| `@IsNotIn(values: any[])` | Checks if value is not in a array of disallowed values. |
| **Type validation decorators** |

@@ -530,0 +530,0 @@ | `@IsBoolean()` | Checks if a value is a boolean. |

@@ -35,6 +35,6 @@ "use strict";

var value = object[propertyName];
var metadatas = groupedMetadatas[propertyName];
var isDefinedMetadatas = groupedMetadatas[propertyName].filter(function (metadata) { return metadata.type === ValidationTypes_1.ValidationTypes.IS_DEFINED; });
var metadatas = groupedMetadatas[propertyName].filter(function (metadata) { return metadata.type !== ValidationTypes_1.ValidationTypes.IS_DEFINED; });
var customValidationMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes_1.ValidationTypes.CUSTOM_VALIDATION; });
var nestedValidationMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes_1.ValidationTypes.NESTED_VALIDATION; });
var isDefinedMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes_1.ValidationTypes.IS_DEFINED; });
// handle IS_DEFINED validation type the special way - it should work no matter skipMissingProperties is set or not

@@ -41,0 +41,0 @@ _this.defaultValidations(object, value, isDefinedMetadatas);

@@ -11,6 +11,6 @@ import { ValidationArguments } from "./ValidationArguments";

static NOT_EQUALS: string;
static EMPTY: string;
static NOT_EMPTY: string;
static IN: string;
static NOT_IN: string;
static IS_EMPTY: string;
static IS_NOT_EMPTY: string;
static IS_IN: string;
static IS_NOT_IN: string;
static IS_BOOLEAN: string;

@@ -17,0 +17,0 @@ static IS_DATE: string;

@@ -29,9 +29,9 @@ "use strict";

return "$property should not be equal to $constraint1";
case this.EMPTY:
case this.IS_EMPTY:
return "$property must be empty";
case this.NOT_EMPTY:
case this.IS_NOT_EMPTY:
return "$property should not be empty";
case this.IN:
case this.IS_IN:
return "$property must be one of the following values: $constraint1";
case this.NOT_IN:
case this.IS_NOT_IN:
return "$property should not be one of the following values: $constraint1";

@@ -173,6 +173,6 @@ /* type checkers */

ValidationTypes.NOT_EQUALS = "not_equal";
ValidationTypes.EMPTY = "empty";
ValidationTypes.NOT_EMPTY = "not_empty";
ValidationTypes.IN = "in";
ValidationTypes.NOT_IN = "not_in";
ValidationTypes.IS_EMPTY = "is_empty";
ValidationTypes.IS_NOT_EMPTY = "is_not_empty";
ValidationTypes.IS_IN = "is_in";
ValidationTypes.IS_NOT_IN = "is_not_in";
/* type checkers */

@@ -179,0 +179,0 @@ ValidationTypes.IS_BOOLEAN = "is_boolean";

@@ -23,3 +23,3 @@ import { ValidationMetadata } from "../metadata/ValidationMetadata";

/**
* Checks if value is defined (!==undefined).
* Checks if value is defined (!== undefined, !== null).
*/

@@ -38,7 +38,7 @@ isDefined(value: any): boolean;

*/
empty(value: any): boolean;
isEmpty(value: any): boolean;
/**
* Checks if given value is not empty (!== '', !== null, !== undefined).
*/
notEmpty(value: any): boolean;
isNotEmpty(value: any): boolean;
/**

@@ -183,7 +183,7 @@ * Checks if given value is in a array of allowed values.

*/
isIP(str: string, version?: number): boolean;
isIP(str: string, version?: "4" | "6"): boolean;
/**
* Checks if the string is an ISBN (version 10 or 13).
*/
isISBN(str: string, version?: number): boolean;
isISBN(str: string, version?: "10" | "13"): boolean;
/**

@@ -229,3 +229,3 @@ * Checks if the string is an ISIN (stock/security identifier).

*/
isUUID(str: string, version?: number): boolean;
isUUID(str: string, version?: "3" | "4" | "5"): boolean;
/**

@@ -232,0 +232,0 @@ * Checks if the string is uppercase.

@@ -37,9 +37,9 @@ "use strict";

return this.notEquals(value, metadata.constraints[0]);
case ValidationTypes_1.ValidationTypes.EMPTY:
return this.empty(value);
case ValidationTypes_1.ValidationTypes.NOT_EMPTY:
return this.notEmpty(value);
case ValidationTypes_1.ValidationTypes.IN:
case ValidationTypes_1.ValidationTypes.IS_EMPTY:
return this.isEmpty(value);
case ValidationTypes_1.ValidationTypes.IS_NOT_EMPTY:
return this.isNotEmpty(value);
case ValidationTypes_1.ValidationTypes.IS_IN:
return this.isIn(value, metadata.constraints[0]);
case ValidationTypes_1.ValidationTypes.NOT_IN:
case ValidationTypes_1.ValidationTypes.IS_NOT_IN:
return this.isNotIn(value, metadata.constraints[0]);

@@ -169,6 +169,6 @@ /* type checkers */

/**
* Checks if value is defined (!==undefined).
* Checks if value is defined (!== undefined, !== null).
*/
Validator.prototype.isDefined = function (value) {
return value !== undefined;
return value !== undefined && value !== null;
};

@@ -190,3 +190,3 @@ /**

*/
Validator.prototype.empty = function (value) {
Validator.prototype.isEmpty = function (value) {
return value === "" || value === null || value === undefined;

@@ -197,3 +197,3 @@ };

*/
Validator.prototype.notEmpty = function (value) {
Validator.prototype.isNotEmpty = function (value) {
return value !== "" && value !== null && value !== undefined;

@@ -261,4 +261,5 @@ };

Validator.prototype.divisibleBy = function (value, num) {
var numberString = String(value); // fix it
return this.validatorJs.isDivisibleBy(numberString, num);
return typeof value === "number" &&
typeof num === "number" &&
this.validatorJs.isDivisibleBy(String(value), num);
};

@@ -269,3 +270,3 @@ /**

Validator.prototype.isPositive = function (value) {
return value > 0;
return typeof value === "number" && value > 0;
};

@@ -276,3 +277,3 @@ /**

Validator.prototype.isNegative = function (value) {
return value < 0;
return typeof value === "number" && value < 0;
};

@@ -283,3 +284,3 @@ /**

Validator.prototype.greaterThen = function (first, second) {
return first > second;
return typeof first === "number" && typeof second === "number" && first > second;
};

@@ -290,3 +291,3 @@ /**

Validator.prototype.lessThen = function (first, second) {
return first > second;
return typeof first === "number" && typeof second === "number" && first < second;
};

@@ -293,0 +294,0 @@ // -------------------------------------------------------------------------

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc