class-validator
Advanced tools
Comparing version 0.6.8 to 0.7.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -3,0 +4,0 @@ * Container to be used by this library for inversion control. If container was not implicitly set then by default |
@@ -77,2 +77,6 @@ import { IsEmailOptions, IsFQDNOptions, IsURLOptions, IsCurrencyOptions } from "../validation/ValidationTypeOptions"; | ||
/** | ||
* Checks if a value is a number enum. | ||
*/ | ||
export declare function IsEnum(entity: Object, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void; | ||
/** | ||
* Checks if the value is a number that's divisible by another. | ||
@@ -110,6 +114,2 @@ */ | ||
/** | ||
* Checks if the string is a date. | ||
*/ | ||
export declare function IsDateString(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void; | ||
/** | ||
* Checks if the string is a number. | ||
@@ -116,0 +116,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationTypes_1 = require("../validation/ValidationTypes"); | ||
@@ -277,2 +278,18 @@ var ValidationMetadata_1 = require("../metadata/ValidationMetadata"); | ||
exports.IsArray = IsArray; | ||
/** | ||
* Checks if a value is a number enum. | ||
*/ | ||
function IsEnum(entity, validationOptions) { | ||
return function (object, propertyName) { | ||
var args = { | ||
type: ValidationTypes_1.ValidationTypes.IS_ENUM, | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
constraints: [entity], | ||
validationOptions: validationOptions | ||
}; | ||
index_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args)); | ||
}; | ||
} | ||
exports.IsEnum = IsEnum; | ||
// ------------------------------------------------------------------------- | ||
@@ -413,17 +430,2 @@ // Number checkers | ||
/** | ||
* Checks if the string is a date. | ||
*/ | ||
function IsDateString(validationOptions) { | ||
return function (object, propertyName) { | ||
var args = { | ||
type: ValidationTypes_1.ValidationTypes.IS_DATE_STRING, | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
validationOptions: validationOptions | ||
}; | ||
index_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args)); | ||
}; | ||
} | ||
exports.IsDateString = IsDateString; | ||
/** | ||
* Checks if the string is a number. | ||
@@ -430,0 +432,0 @@ */ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidationOptions.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MetadataStorage_1 = require("./metadata/MetadataStorage"); | ||
@@ -7,0 +8,0 @@ var Validator_1 = require("./validation/Validator"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_1 = require("../index"); | ||
@@ -3,0 +4,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationSchemaToMetadataTransformer_1 = require("../validation-schema/ValidationSchemaToMetadataTransformer"); | ||
@@ -3,0 +4,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -3,0 +4,0 @@ * This metadata contains validation rules. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidationMetadataArgs.js.map |
{ | ||
"name": "class-validator", | ||
"private": false, | ||
"version": "0.6.8", | ||
"version": "0.7.0", | ||
"description": "Class-based validation with Typescript / ES6 / ES5 using decorators or validation schemas. Supports both node.js and browser", | ||
@@ -26,17 +26,16 @@ "license": "MIT", | ||
"dependencies": { | ||
"validator": ">=5.0.0" | ||
"validator": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^3.4.34", | ||
"@types/chai-as-promised": "0.0.29", | ||
"@types/es6-shim": "^0.31.32", | ||
"@types/gulp": "^3.8.32", | ||
"@types/mocha": "^2.2.32", | ||
"@types/node": "^6.0.45", | ||
"@types/sinon": "^1.16.31", | ||
"@types/chai": "^3.4.35", | ||
"@types/chai-as-promised": "0.0.30", | ||
"@types/gulp": "^4.0.2", | ||
"@types/mocha": "^2.2.40", | ||
"@types/node": "^7.0.10", | ||
"@types/sinon": "^1.16.36", | ||
"chai": "^3.4.1", | ||
"chai-as-promised": "^6.0.0", | ||
"codecov": "^1.0.1", | ||
"codecov": "^2.1.0", | ||
"del": "^2.2.2", | ||
"es6-shim": "^0.35.1", | ||
"es6-shim": "^0.35.3", | ||
"gulp": "^3.9.1", | ||
@@ -46,14 +45,15 @@ "gulp-istanbul": "^1.1.1", | ||
"gulp-replace": "^0.5.4", | ||
"gulp-shell": "^0.5.0", | ||
"gulp-sourcemaps": "^1.6.0", | ||
"gulp-tslint": "^6.1.2", | ||
"gulp-typescript": "^3.0.2", | ||
"gulpclass": "0.1.1", | ||
"mocha": "^3.1.2", | ||
"remap-istanbul": "^0.7.0", | ||
"sinon": "^1.17.6", | ||
"sinon-chai": "^2.8.0", | ||
"tslint": "^3.15.1", | ||
"tslint-stylish": "^2.1.0-beta", | ||
"typescript": "^2.0.3" | ||
"gulp-shell": "^0.6.3", | ||
"gulp-sourcemaps": "^2.4.1", | ||
"gulp-tslint": "^7.1.0", | ||
"gulp-typescript": "^3.1.6", | ||
"gulpclass": "0.1.2", | ||
"mocha": "^3.2.0", | ||
"remap-istanbul": "^0.9.1", | ||
"sinon": "^2.1.0", | ||
"sinon-chai": "^2.9.0", | ||
"ts-node": "^3.0.2", | ||
"tslint": "^4.5.1", | ||
"tslint-stylish": "^2.1.0", | ||
"typescript": "^2.2.1" | ||
}, | ||
@@ -60,0 +60,0 @@ "scripts": { |
@@ -475,2 +475,3 @@ # class-validator | ||
propertyName: propertyName, | ||
constraints: [property], | ||
options: validationOptions, | ||
@@ -608,2 +609,3 @@ validator: { | ||
validator.isInt(value); // Checks if value is an integer. | ||
validator.isEnum(value, entity); // Checks if value is valid for a certain enum entity. | ||
@@ -623,3 +625,2 @@ // number validation methods | ||
validator.isBooleanString(str); // Checks if a string is a boolean. | ||
validator.isDateString(str); // Checks if the string is a date. | ||
validator.isNumberString(str); // Checks if the string is numeric. | ||
@@ -691,2 +692,3 @@ | ||
| `@IsArray()` | Checks if the string is an array | | ||
| `@Enum(entity: object)` | Checks if the value is an valid enum | | ||
| **Number validation decorators** | | ||
@@ -824,2 +826,5 @@ | `@IsDivisibleBy(num: number)` | Checks if the value is a number that's divisible by another. | | ||
## Validating plain objects | ||
Due to nature of the decorators, the validated object has to be instantiated using `new Class()` syntax. If you have your class defined using class-validator decorators and you want to validate plain JS object (literal object or returned by JSON.parse), you need to transform it to the class instance (e.g. using [class-transformer](https://github.com/pleerock/class-transformer)) or just use the [class-transformer-validator](https://github.com/19majkel94/class-transformer-validator) extension which can do that for you. | ||
## Samples | ||
@@ -830,2 +835,5 @@ | ||
## Extensions | ||
There are several extensions that simplify class-validator integration with other modules: | ||
- [class-validator integration](https://github.com/19majkel94/class-transformer-validator) with [class-transformer](https://github.com/pleerock/class-transformer) | ||
@@ -832,0 +840,0 @@ ## Release notes |
@@ -23,3 +23,3 @@ import { ValidatorOptions } from "./validation/ValidatorOptions"; | ||
*/ | ||
options: ValidatorOptions; | ||
options?: ValidatorOptions; | ||
/** | ||
@@ -26,0 +26,0 @@ * Array of validation constraints. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MetadataStorage_1 = require("./metadata/MetadataStorage"); | ||
@@ -3,0 +4,0 @@ var ConstraintMetadata_1 = require("./metadata/ConstraintMetadata"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidationSchema.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationMetadata_1 = require("../metadata/ValidationMetadata"); | ||
@@ -3,0 +4,0 @@ var ValidationTypes_1 = require("../validation/ValidationTypes"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidationArguments.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -3,0 +4,0 @@ * Validation error description. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationError_1 = require("./ValidationError"); | ||
@@ -3,0 +4,0 @@ var MetadataStorage_1 = require("../metadata/MetadataStorage"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidationTypeOptions.js.map |
@@ -22,2 +22,3 @@ import { ValidationArguments } from "./ValidationArguments"; | ||
static IS_INT: string; | ||
static IS_ENUM: string; | ||
static IS_DIVISIBLE_BY: string; | ||
@@ -31,3 +32,2 @@ static IS_POSITIVE: string; | ||
static IS_BOOLEAN_STRING: string; | ||
static IS_DATE_STRING: string; | ||
static IS_NUMBER_STRING: string; | ||
@@ -34,0 +34,0 @@ static CONTAINS: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -51,2 +52,4 @@ * Validation types. | ||
return eachPrefix + "$property must be an array"; | ||
case this.IS_ENUM: | ||
return eachPrefix + "$property must be a valid enum value"; | ||
/* number checkers */ | ||
@@ -71,4 +74,2 @@ case this.IS_DIVISIBLE_BY: | ||
return eachPrefix + "$property must be a boolean string"; | ||
case this.IS_DATE_STRING: | ||
return eachPrefix + "$property must be a date string"; | ||
case this.IS_NUMBER_STRING: | ||
@@ -169,80 +170,80 @@ return eachPrefix + "$property must be a number string"; | ||
}; | ||
/* system */ | ||
ValidationTypes.CUSTOM_VALIDATION = "customValidation"; | ||
ValidationTypes.NESTED_VALIDATION = "nestedValidation"; | ||
ValidationTypes.CONDITIONAL_VALIDATION = "conditionalValidation"; | ||
/* common checkers */ | ||
ValidationTypes.IS_DEFINED = "isDefined"; | ||
ValidationTypes.EQUALS = "equals"; | ||
ValidationTypes.NOT_EQUALS = "notEquals"; | ||
ValidationTypes.IS_EMPTY = "isEmpty"; | ||
ValidationTypes.IS_NOT_EMPTY = "isNotEmpty"; | ||
ValidationTypes.IS_IN = "isIn"; | ||
ValidationTypes.IS_NOT_IN = "isNotIn"; | ||
/* type checkers */ | ||
ValidationTypes.IS_BOOLEAN = "isBoolean"; | ||
ValidationTypes.IS_DATE = "isDate"; | ||
ValidationTypes.IS_NUMBER = "isNumber"; | ||
ValidationTypes.IS_STRING = "isString"; | ||
ValidationTypes.IS_ARRAY = "isArray"; | ||
ValidationTypes.IS_INT = "isInt"; | ||
/* number checkers */ | ||
ValidationTypes.IS_DIVISIBLE_BY = "isDivisibleBy"; | ||
ValidationTypes.IS_POSITIVE = "isPositive"; | ||
ValidationTypes.IS_NEGATIVE = "isNegative"; | ||
ValidationTypes.MIN = "min"; | ||
ValidationTypes.MAX = "max"; | ||
/* date checkers */ | ||
ValidationTypes.MIN_DATE = "minDate"; | ||
ValidationTypes.MAX_DATE = "maxDate"; | ||
/* string-as-type checkers */ | ||
ValidationTypes.IS_BOOLEAN_STRING = "isBooleanString"; | ||
ValidationTypes.IS_DATE_STRING = "isDateString"; | ||
ValidationTypes.IS_NUMBER_STRING = "isNumberString"; | ||
/* string checkers */ | ||
ValidationTypes.CONTAINS = "contains"; | ||
ValidationTypes.NOT_CONTAINS = "notContains"; | ||
ValidationTypes.IS_ALPHA = "isAlpha"; | ||
ValidationTypes.IS_ALPHANUMERIC = "isAlphanumeric"; | ||
ValidationTypes.IS_ASCII = "isAscii"; | ||
ValidationTypes.IS_BASE64 = "isBase64"; | ||
ValidationTypes.IS_BYTE_LENGTH = "isByteLength"; | ||
ValidationTypes.IS_CREDIT_CARD = "isCreditCard"; | ||
ValidationTypes.IS_CURRENCY = "isCurrency"; | ||
ValidationTypes.IS_EMAIL = "isEmail"; | ||
ValidationTypes.IS_FQDN = "isFqdn"; | ||
ValidationTypes.IS_FULL_WIDTH = "isFullWidth"; | ||
ValidationTypes.IS_HALF_WIDTH = "isHalfWidth"; | ||
ValidationTypes.IS_VARIABLE_WIDTH = "isVariableWidth"; | ||
ValidationTypes.IS_HEX_COLOR = "isHexColor"; | ||
ValidationTypes.IS_HEXADECIMAL = "isHexadecimal"; | ||
ValidationTypes.IS_IP = "isIp"; | ||
ValidationTypes.IS_ISBN = "isIsbn"; | ||
ValidationTypes.IS_ISIN = "isIsin"; | ||
ValidationTypes.IS_ISO8601 = "isIso8601"; | ||
ValidationTypes.IS_JSON = "isJson"; | ||
ValidationTypes.IS_LOWERCASE = "isLowercase"; | ||
ValidationTypes.IS_MOBILE_PHONE = "isMobilePhone"; | ||
ValidationTypes.IS_MONGO_ID = "isMongoId"; | ||
ValidationTypes.IS_MULTIBYTE = "isMultibyte"; | ||
ValidationTypes.IS_SURROGATE_PAIR = "isSurrogatePair"; | ||
ValidationTypes.IS_URL = "isUrl"; | ||
ValidationTypes.IS_UUID = "isUuid"; | ||
ValidationTypes.LENGTH = "length"; | ||
ValidationTypes.IS_UPPERCASE = "isUppercase"; | ||
ValidationTypes.MIN_LENGTH = "minLength"; | ||
ValidationTypes.MAX_LENGTH = "maxLength"; | ||
ValidationTypes.MATCHES = "matches"; | ||
ValidationTypes.IS_MILITARY_TIME = "isMilitaryTime"; | ||
/* array checkers */ | ||
ValidationTypes.ARRAY_CONTAINS = "arrayContains"; | ||
ValidationTypes.ARRAY_NOT_CONTAINS = "arrayNotContains"; | ||
ValidationTypes.ARRAY_NOT_EMPTY = "arrayNotEmpty"; | ||
ValidationTypes.ARRAY_MIN_SIZE = "arrayMinSize"; | ||
ValidationTypes.ARRAY_MAX_SIZE = "arrayMaxSize"; | ||
ValidationTypes.ARRAY_UNIQUE = "arrayUnique"; | ||
return ValidationTypes; | ||
}()); | ||
/* system */ | ||
ValidationTypes.CUSTOM_VALIDATION = "customValidation"; | ||
ValidationTypes.NESTED_VALIDATION = "nestedValidation"; | ||
ValidationTypes.CONDITIONAL_VALIDATION = "conditionalValidation"; | ||
/* common checkers */ | ||
ValidationTypes.IS_DEFINED = "isDefined"; | ||
ValidationTypes.EQUALS = "equals"; | ||
ValidationTypes.NOT_EQUALS = "notEquals"; | ||
ValidationTypes.IS_EMPTY = "isEmpty"; | ||
ValidationTypes.IS_NOT_EMPTY = "isNotEmpty"; | ||
ValidationTypes.IS_IN = "isIn"; | ||
ValidationTypes.IS_NOT_IN = "isNotIn"; | ||
/* type checkers */ | ||
ValidationTypes.IS_BOOLEAN = "isBoolean"; | ||
ValidationTypes.IS_DATE = "isDate"; | ||
ValidationTypes.IS_NUMBER = "isNumber"; | ||
ValidationTypes.IS_STRING = "isString"; | ||
ValidationTypes.IS_ARRAY = "isArray"; | ||
ValidationTypes.IS_INT = "isInt"; | ||
ValidationTypes.IS_ENUM = "isEnum"; | ||
/* number checkers */ | ||
ValidationTypes.IS_DIVISIBLE_BY = "isDivisibleBy"; | ||
ValidationTypes.IS_POSITIVE = "isPositive"; | ||
ValidationTypes.IS_NEGATIVE = "isNegative"; | ||
ValidationTypes.MIN = "min"; | ||
ValidationTypes.MAX = "max"; | ||
/* date checkers */ | ||
ValidationTypes.MIN_DATE = "minDate"; | ||
ValidationTypes.MAX_DATE = "maxDate"; | ||
/* string-as-type checkers */ | ||
ValidationTypes.IS_BOOLEAN_STRING = "isBooleanString"; | ||
ValidationTypes.IS_NUMBER_STRING = "isNumberString"; | ||
/* string checkers */ | ||
ValidationTypes.CONTAINS = "contains"; | ||
ValidationTypes.NOT_CONTAINS = "notContains"; | ||
ValidationTypes.IS_ALPHA = "isAlpha"; | ||
ValidationTypes.IS_ALPHANUMERIC = "isAlphanumeric"; | ||
ValidationTypes.IS_ASCII = "isAscii"; | ||
ValidationTypes.IS_BASE64 = "isBase64"; | ||
ValidationTypes.IS_BYTE_LENGTH = "isByteLength"; | ||
ValidationTypes.IS_CREDIT_CARD = "isCreditCard"; | ||
ValidationTypes.IS_CURRENCY = "isCurrency"; | ||
ValidationTypes.IS_EMAIL = "isEmail"; | ||
ValidationTypes.IS_FQDN = "isFqdn"; | ||
ValidationTypes.IS_FULL_WIDTH = "isFullWidth"; | ||
ValidationTypes.IS_HALF_WIDTH = "isHalfWidth"; | ||
ValidationTypes.IS_VARIABLE_WIDTH = "isVariableWidth"; | ||
ValidationTypes.IS_HEX_COLOR = "isHexColor"; | ||
ValidationTypes.IS_HEXADECIMAL = "isHexadecimal"; | ||
ValidationTypes.IS_IP = "isIp"; | ||
ValidationTypes.IS_ISBN = "isIsbn"; | ||
ValidationTypes.IS_ISIN = "isIsin"; | ||
ValidationTypes.IS_ISO8601 = "isIso8601"; | ||
ValidationTypes.IS_JSON = "isJson"; | ||
ValidationTypes.IS_LOWERCASE = "isLowercase"; | ||
ValidationTypes.IS_MOBILE_PHONE = "isMobilePhone"; | ||
ValidationTypes.IS_MONGO_ID = "isMongoId"; | ||
ValidationTypes.IS_MULTIBYTE = "isMultibyte"; | ||
ValidationTypes.IS_SURROGATE_PAIR = "isSurrogatePair"; | ||
ValidationTypes.IS_URL = "isUrl"; | ||
ValidationTypes.IS_UUID = "isUuid"; | ||
ValidationTypes.LENGTH = "length"; | ||
ValidationTypes.IS_UPPERCASE = "isUppercase"; | ||
ValidationTypes.MIN_LENGTH = "minLength"; | ||
ValidationTypes.MAX_LENGTH = "maxLength"; | ||
ValidationTypes.MATCHES = "matches"; | ||
ValidationTypes.IS_MILITARY_TIME = "isMilitaryTime"; | ||
/* array checkers */ | ||
ValidationTypes.ARRAY_CONTAINS = "arrayContains"; | ||
ValidationTypes.ARRAY_NOT_CONTAINS = "arrayNotContains"; | ||
ValidationTypes.ARRAY_NOT_EMPTY = "arrayNotEmpty"; | ||
ValidationTypes.ARRAY_MIN_SIZE = "arrayMinSize"; | ||
ValidationTypes.ARRAY_MAX_SIZE = "arrayMaxSize"; | ||
ValidationTypes.ARRAY_UNIQUE = "arrayUnique"; | ||
exports.ValidationTypes = ValidationTypes; | ||
//# sourceMappingURL=ValidationTypes.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationUtils = (function () { | ||
@@ -3,0 +4,0 @@ function ValidationUtils() { |
@@ -89,2 +89,6 @@ import { ValidationMetadata } from "../metadata/ValidationMetadata"; | ||
/** | ||
* Checks if a given value is an enum | ||
*/ | ||
isEnum(value: any, entity: any): boolean; | ||
/** | ||
* Checks if a given value is a real number. | ||
@@ -131,7 +135,2 @@ */ | ||
/** | ||
* Checks if the string is a date. | ||
* If given value is not a string, then it returns false. | ||
*/ | ||
isDateString(value: string): boolean; | ||
/** | ||
* Checks if the string is numeric. | ||
@@ -138,0 +137,0 @@ * If given value is not a string, then it returns false. |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; | ||
return { next: verb(0), "throw": verb(1), "return": verb(2) }; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ValidationTypes_1 = require("./ValidationTypes"); | ||
@@ -39,4 +75,15 @@ var ValidationExecutor_1 = require("./ValidationExecutor"); | ||
Validator.prototype.validateOrReject = function (objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) { | ||
return this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) | ||
.then(function (validationErorrs) { return (validationErorrs.length > 0) ? Promise.reject(validationErorrs) : Promise.resolve(); }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var errors; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions)]; | ||
case 1: | ||
errors = _a.sent(); | ||
if (errors.length) | ||
return [2 /*return*/, Promise.reject(errors)]; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -89,2 +136,4 @@ /** | ||
return this.isInt(value); | ||
case ValidationTypes_1.ValidationTypes.IS_ENUM: | ||
return this.isEnum(value, metadata.constraints[0]); | ||
/* number checkers */ | ||
@@ -109,4 +158,2 @@ case ValidationTypes_1.ValidationTypes.IS_DIVISIBLE_BY: | ||
return this.isBooleanString(value); | ||
case ValidationTypes_1.ValidationTypes.IS_DATE_STRING: | ||
return this.isDateString(value); | ||
case ValidationTypes_1.ValidationTypes.IS_NUMBER_STRING: | ||
@@ -272,2 +319,11 @@ return this.isNumberString(value); | ||
/** | ||
* Checks if a given value is an enum | ||
*/ | ||
Validator.prototype.isEnum = function (value, entity) { | ||
var enumValues = Object.keys(entity) | ||
.map(function (k) { return entity[k]; }) | ||
.filter(function (v) { return typeof v === "number"; }); | ||
return enumValues.indexOf(value) >= 0; | ||
}; | ||
/** | ||
* Checks if a given value is a real number. | ||
@@ -348,9 +404,2 @@ */ | ||
/** | ||
* Checks if the string is a date. | ||
* If given value is not a string, then it returns false. | ||
*/ | ||
Validator.prototype.isDateString = function (value) { | ||
return typeof value === "string" && this.validatorJs.isDate(value); | ||
}; | ||
/** | ||
* Checks if the string is numeric. | ||
@@ -357,0 +406,0 @@ * If given value is not a string, then it returns false. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidatorConstraintInterface.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ValidatorOptions.js.map |
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
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
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
393190
3860
840
+ Addedvalidator@7.2.0(transitive)
- Removedvalidator@13.12.0(transitive)
Updatedvalidator@^7.0.0