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

class-validator

Package Overview
Dependencies
Maintainers
3
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.10.1 to 0.10.2

20

decorator/decorators.d.ts

@@ -70,2 +70,14 @@ /// <reference types="validator" />

/**
* Checks if a value is a latitude,longitude.
*/
export declare function IsLatLong(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if a value is a latitude,longitude.
*/
export declare function IsLatitude(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if a value is a latitude,longitude.
*/
export declare function IsLongitude(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if a value is a date.

@@ -224,2 +236,10 @@ */

/**
* Checks if the value is a valid object.
*/
export declare function IsObject(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if the value is a valid object & not empty.
*/
export declare function IsNotEmptyObject(validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
/**
* Checks if the string is lowercase.

@@ -226,0 +246,0 @@ */

@@ -252,2 +252,47 @@ "use strict";

/**
* Checks if a value is a latitude,longitude.
*/
function IsLatLong(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_LATLONG,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
container_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsLatLong = IsLatLong;
/**
* Checks if a value is a latitude,longitude.
*/
function IsLatitude(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_LONGITUDE,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
container_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsLatitude = IsLatitude;
/**
* Checks if a value is a latitude,longitude.
*/
function IsLongitude(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_LATITUDE,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
container_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsLongitude = IsLongitude;
/**
* Checks if a value is a date.

@@ -867,2 +912,32 @@ */

/**
* Checks if the value is a valid object.
*/
function IsObject(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_OBJECT,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
container_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsObject = IsObject;
/**
* Checks if the value is a valid object & not empty.
*/
function IsNotEmptyObject(validationOptions) {
return function (object, propertyName) {
var args = {
type: ValidationTypes_1.ValidationTypes.IS_NOT_EMPTY_OBJECT,
target: object.constructor,
propertyName: propertyName,
validationOptions: validationOptions
};
container_1.getFromContainer(MetadataStorage_1.MetadataStorage).addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
};
}
exports.IsNotEmptyObject = IsNotEmptyObject;
/**
* Checks if the string is lowercase.

@@ -869,0 +944,0 @@ */

2

package.json
{
"name": "class-validator",
"private": false,
"version": "0.10.1",
"version": "0.10.2",
"description": "Class-based validation with Typescript / ES6 / ES5 using decorators or validation schemas. Supports both node.js and browser",

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

@@ -473,3 +473,3 @@ # class-validator

@MinLength(32, {
message: "EIC code must be at least 32 charatcers",
message: "EIC code must be at least 32 characters",
context: {

@@ -840,3 +840,8 @@ errorCode: 1003,

validator.isJSON(str); // Checks if the string is valid JSON (note: uses JSON.parse).
validator.isObject(object); // Checks if the object is valid Object (null, functions, arrays will return false)
validator.isNotEmptyObject(object); // Checks if the object is not empty
validator.isLowercase(str); // Checks if the string is lowercase.
validator.isLatLong(str); // Checks if the string is lowercase.
validator.isLatitude(str); // Checks if the string is lowercase.
validator.isLongtitude(str); // Checks if the string is lowercase.
validator.isMobilePhone(str, locale); // Checks if the string is a mobile phone number.

@@ -927,6 +932,11 @@ validator.isISO31661Alpha2(str); // Check if the string is a valid ISO 3166-1 alpha-2

| `@IsJSON()` | Checks if the string is valid JSON. |
| `@IsObject()` | Checks if the object is valid Object (null, functions, arrays will return false). |
| `@IsNotEmptyObject()` | Checks if the object is not empty. |
| `@IsLowercase()` | Checks if the string is lowercase. |
| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. |
| `@IsISO31661Alpha2()` | Check 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()` | Check 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. |
| `@IsLatLong()` | Checks if the string is a valid latitude-longitude coordinate in the format lat,long |
| `@IsLatitude()` | Checks if the string or number is a valid latitude coordinate |
| `@IsLongitude()` | Checks if the string or number is a valid longitude coordinate |
| `@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. |
| `@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) |

@@ -1052,2 +1062,2 @@ | `@IsMongoId()` | Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. |

[2]: https://github.com/pleerock/typedi
[3]: CHANGELOG.md
[3]: CHANGELOG.md
export declare function isPromise<T = any>(p: any): p is Promise<T>;
/**
* Convert Map, Set to Array
*/
export declare function convertToArray<T>(val: Array<T> | Set<T> | Map<any, T>): Array<T>;

@@ -8,3 +8,13 @@ "use strict";

exports.isPromise = isPromise;
/**
* Convert Map, Set to Array
*/
function convertToArray(val) {
if (val instanceof Map) {
return Array.from(val.values());
}
return Array.isArray(val) ? val : Array.from(val);
}
exports.convertToArray = convertToArray;
//# sourceMappingURL=utils.js.map

@@ -174,4 +174,5 @@ "use strict";

if (metadata.each) {
if (value instanceof Array) {
return !value.every(function (subValue) { return _this.validator.validateValueByMetadata(subValue, metadata); });
if (value instanceof Array || value instanceof Set || value instanceof Map) {
var arrayValue = utils_1.convertToArray(value);
return !arrayValue.every(function (subValue) { return _this.validator.validateValueByMetadata(subValue, metadata); });
}

@@ -203,17 +204,46 @@ }

};
var validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
if (utils_1.isPromise(validatedValue)) {
var promise = validatedValue.then(function (isValid) {
if (!isValid) {
if (!metadata.each || !(value instanceof Array || value instanceof Set || value instanceof Map)) {
var validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
if (utils_1.isPromise(validatedValue)) {
var promise = validatedValue.then(function (isValid) {
if (!isValid) {
var _a = _this.createValidationError(object, value, metadata, customConstraintMetadata), type = _a[0], message = _a[1];
errorMap[type] = message;
}
});
_this.awaitingPromises.push(promise);
}
else {
if (!validatedValue) {
var _a = _this.createValidationError(object, value, metadata, customConstraintMetadata), type = _a[0], message = _a[1];
errorMap[type] = message;
}
}
return;
}
// convert set and map into array
var arrayValue = utils_1.convertToArray(value);
// Validation needs to be applied to each array item
var validatedSubValues = arrayValue.map(function (subValue) { return customConstraintMetadata.instance.validate(subValue, validationArguments); });
var validationIsAsync = validatedSubValues
.some(function (validatedSubValue) { return utils_1.isPromise(validatedSubValue); });
if (validationIsAsync) {
// Wrap plain values (if any) in promises, so that all are async
var asyncValidatedSubValues = validatedSubValues
.map(function (validatedSubValue) { return utils_1.isPromise(validatedSubValue) ? validatedSubValue : Promise.resolve(validatedSubValue); });
var asyncValidationIsFinishedPromise = Promise.all(asyncValidatedSubValues)
.then(function (flatValidatedValues) {
var validationResult = flatValidatedValues.every(function (isValid) { return isValid; });
if (!validationResult) {
var _a = _this.createValidationError(object, value, metadata, customConstraintMetadata), type = _a[0], message = _a[1];
errorMap[type] = message;
}
});
_this.awaitingPromises.push(promise);
_this.awaitingPromises.push(asyncValidationIsFinishedPromise);
return;
}
else {
if (!validatedValue) {
var _a = _this.createValidationError(object, value, metadata, customConstraintMetadata), type = _a[0], message = _a[1];
errorMap[type] = message;
}
var validationResult = validatedSubValues.every(function (isValid) { return isValid; });
if (!validationResult) {
var _b = _this.createValidationError(object, value, metadata, customConstraintMetadata), type = _b[0], message = _b[1];
errorMap[type] = message;
}

@@ -242,4 +272,6 @@ });

var targetSchema = typeof metadata.target === "string" ? metadata.target : undefined;
if (value instanceof Array) {
value.forEach(function (subValue, index) {
if (value instanceof Array || value instanceof Set || value instanceof Map) {
// Treats Set as an array - as index of Set value is value itself and it is common case to have Object as value
var arrayLikeValue = value instanceof Set ? Array.from(value) : value;
arrayLikeValue.forEach(function (subValue, index) {
var validationError = _this.generateValidationError(value, subValue, index.toString());

@@ -250,18 +282,2 @@ errors.push(validationError);

}
else if (value instanceof Set) {
var index_1 = 0;
value.forEach(function (subValue) {
var validationError = _this.generateValidationError(value, subValue, index_1.toString());
errors.push(validationError);
_this.execute(subValue, targetSchema, validationError.children);
++index_1;
});
}
else if (value instanceof Map) {
value.forEach(function (subValue, key) {
var validationError = _this.generateValidationError(value, subValue, key.toString());
errors.push(validationError);
_this.execute(subValue, targetSchema, validationError.children);
});
}
else if (value instanceof Object) {

@@ -268,0 +284,0 @@ _this.execute(value, targetSchema, errors);

@@ -21,2 +21,5 @@ import { ValidationArguments } from "./ValidationArguments";

static IS_NUMBER: string;
static IS_LATLONG: string;
static IS_LATITUDE: string;
static IS_LONGITUDE: string;
static IS_STRING: string;

@@ -59,2 +62,4 @@ static IS_DATE_STRING: string;

static IS_JSON: string;
static IS_OBJECT: string;
static IS_NOT_EMPTY_OBJECT: string;
static IS_LOWERCASE: string;

@@ -61,0 +66,0 @@ static IS_MOBILE_PHONE: string;

@@ -128,2 +128,6 @@ "use strict";

return eachPrefix + "$property must be a json string";
case this.IS_OBJECT:
return eachPrefix + "$property must be an object";
case this.IS_NOT_EMPTY_OBJECT:
return eachPrefix + "$property must be a non-empty object";
case this.IS_LOWERCASE:

@@ -139,2 +143,8 @@ return eachPrefix + "$property must be a lowercase string";

return eachPrefix + "$property must be a valid ISO31661 Alpha3 code";
case this.IS_LATLONG:
return eachPrefix + "$property must be a latitude,longitude string";
case this.IS_LATITUDE:
return eachPrefix + "$property must be a latitude string or number";
case this.IS_LONGITUDE:
return eachPrefix + "$property must be a longitude string or number";
case this.IS_MONGO_ID:

@@ -215,2 +225,5 @@ return eachPrefix + "$property must be a mongodb id";

ValidationTypes.IS_NUMBER = "isNumber";
ValidationTypes.IS_LATLONG = "isLatLong";
ValidationTypes.IS_LATITUDE = "isLatitude";
ValidationTypes.IS_LONGITUDE = "isLongitude";
ValidationTypes.IS_STRING = "isString";

@@ -257,2 +270,4 @@ ValidationTypes.IS_DATE_STRING = "isDateString";

ValidationTypes.IS_JSON = "isJson";
ValidationTypes.IS_OBJECT = "isObject";
ValidationTypes.IS_NOT_EMPTY_OBJECT = "isNotEmptyObject";
ValidationTypes.IS_LOWERCASE = "isLowercase";

@@ -259,0 +274,0 @@ ValidationTypes.IS_MOBILE_PHONE = "isMobilePhone";

@@ -12,2 +12,3 @@ /// <reference types="validator" />

private libPhoneNumber;
private _isEmptyObject;
/**

@@ -50,87 +51,99 @@ * Performs validation of the given object based on decorators or validation schema.

*/
isDefined(value: any): boolean;
isDefined(value: unknown): boolean;
/**
* Checks if value matches ("===") the comparison.
*/
equals(value: any, comparison: any): boolean;
equals(value: unknown, comparison: unknown): boolean;
/**
* Checks if value does not match ("!==") the comparison.
*/
notEquals(value: any, comparison: any): boolean;
notEquals(value: unknown, comparison: unknown): boolean;
/**
* Checks if given value is empty (=== '', === null, === undefined).
*/
isEmpty(value: any): boolean;
isEmpty(value: unknown): boolean;
/**
* Checks if given value is not empty (!== '', !== null, !== undefined).
*/
isNotEmpty(value: any): boolean;
isNotEmpty(value: unknown): boolean;
/**
* Checks if given value is in a array of allowed values.
*/
isIn(value: any, possibleValues: any[]): boolean;
isIn(value: unknown, possibleValues: unknown[]): boolean;
/**
* Checks if given value not in a array of allowed values.
*/
isNotIn(value: any, possibleValues: any[]): boolean;
isNotIn(value: unknown, possibleValues: unknown[]): boolean;
/**
* Checks if a given value is a real boolean.
*/
isBoolean(value: any): boolean;
isBoolean(value: unknown): boolean;
/**
* Checks if a given value is a latitude.
*/
isLatLong(value: unknown): boolean;
/**
* Checks if a given value is a latitude.
*/
isLatitude(value: unknown): boolean;
/**
* Checks if a given value is a longitude.
*/
isLongitude(value: unknown): boolean;
/**
* Checks if a given value is a real date.
*/
isDate(value: any): boolean;
isDate(value: unknown): boolean;
/**
* Checks if a given value is a real string.
*/
isString(value: any): boolean;
isString(value: unknown): value is string;
/**
* Checks if a given value is a ISOString date.
*/
isDateString(value: any): boolean;
isDateString(value: unknown): boolean;
/**
* Checks if a given value is an array
*/
isArray(value: any): boolean;
isArray(value: unknown): boolean;
/**
* Checks if a given value is an enum
*/
isEnum(value: any, entity: any): boolean;
isEnum(value: unknown, entity: any): boolean;
/**
* Checks if a given value is a number.
*/
isNumber(value: any, options?: IsNumberOptions): boolean;
isNumber(value: unknown, options?: IsNumberOptions): boolean;
/**
* Checks if value is an integer.
*/
isInt(val: number): boolean;
isInt(val: unknown): boolean;
/**
* Checks if value is a number that's divisible by another.
*/
isDivisibleBy(value: number, num: number): boolean;
isDivisibleBy(value: unknown, num: number): boolean;
/**
* Checks if the value is a positive number.
*/
isPositive(value: number): boolean;
isPositive(value: unknown): boolean;
/**
* Checks if the value is a negative number.
*/
isNegative(value: number): boolean;
isNegative(value: unknown): boolean;
/**
* Checks if the first number is greater than or equal to the second.
*/
min(num: number, min: number): boolean;
min(num: unknown, min: number): boolean;
/**
* Checks if the first number is less than or equal to the second.
*/
max(num: number, max: number): boolean;
max(num: unknown, max: number): boolean;
/**
* Checks if the value is a date that's after the specified date.
*/
minDate(date: Date, minDate: Date): boolean;
minDate(date: unknown, minDate: Date): boolean;
/**
* Checks if the value is a date that's before the specified date.
*/
maxDate(date: Date, maxDate: Date): boolean;
maxDate(date: unknown, maxDate: Date): boolean;
/**

@@ -140,3 +153,3 @@ * Checks if a string is a boolean.

*/
isBooleanString(value: string): boolean;
isBooleanString(value: unknown): boolean;
/**

@@ -146,3 +159,3 @@ * Checks if the string is numeric.

*/
isNumberString(value: string, options?: ValidatorJS.IsNumericOptions): boolean;
isNumberString(value: unknown, options?: ValidatorJS.IsNumericOptions): boolean;
/**

@@ -152,3 +165,3 @@ * Checks if the string contains the seed.

*/
contains(value: string, seed: string): boolean;
contains(value: unknown, seed: string): boolean;
/**

@@ -158,3 +171,3 @@ * Checks if the string does not contain the seed.

*/
notContains(value: string, seed: string): boolean;
notContains(value: unknown, seed: string): boolean;
/**

@@ -164,3 +177,3 @@ * Checks if the string contains only letters (a-zA-Z).

*/
isAlpha(value: string, locale?: ValidatorJS.AlphaLocale): boolean;
isAlpha(value: unknown, locale?: ValidatorJS.AlphaLocale): boolean;
/**

@@ -170,3 +183,3 @@ * Checks if the string contains only letters and numbers.

*/
isAlphanumeric(value: string, locale?: ValidatorJS.AlphanumericLocale): boolean;
isAlphanumeric(value: unknown, locale?: ValidatorJS.AlphanumericLocale): boolean;
/**

@@ -176,3 +189,3 @@ * Checks if the string is a valid decimal.

*/
isDecimal(value: string, options?: ValidatorJS.IsDecimalOptions): boolean;
isDecimal(value: unknown, options?: ValidatorJS.IsDecimalOptions): boolean;
/**

@@ -182,3 +195,3 @@ * Checks if the string contains ASCII chars only.

*/
isAscii(value: string): boolean;
isAscii(value: unknown): boolean;
/**

@@ -188,3 +201,3 @@ * Checks if a string is base64 encoded.

*/
isBase64(value: string): boolean;
isBase64(value: unknown): boolean;
/**

@@ -194,3 +207,3 @@ * Checks if the string's length (in bytes) falls in a range.

*/
isByteLength(value: string, min: number, max?: number): boolean;
isByteLength(value: unknown, min: number, max?: number): boolean;
/**

@@ -200,3 +213,3 @@ * Checks if the string is a credit card.

*/
isCreditCard(value: string): boolean;
isCreditCard(value: unknown): boolean;
/**

@@ -206,3 +219,3 @@ * Checks if the string is a valid currency amount.

*/
isCurrency(value: string, options?: ValidatorJS.IsCurrencyOptions): boolean;
isCurrency(value: unknown, options?: ValidatorJS.IsCurrencyOptions): boolean;
/**

@@ -212,3 +225,3 @@ * Checks if the string is an email.

*/
isEmail(value: string, options?: ValidatorJS.IsEmailOptions): boolean;
isEmail(value: unknown, options?: ValidatorJS.IsEmailOptions): boolean;
/**

@@ -218,3 +231,3 @@ * Checks if the string is a fully qualified domain name (e.g. domain.com).

*/
isFQDN(value: string, options?: ValidatorJS.IsFQDNOptions): boolean;
isFQDN(value: unknown, options?: ValidatorJS.IsFQDNOptions): boolean;
/**

@@ -224,3 +237,3 @@ * Checks if the string contains any full-width chars.

*/
isFullWidth(value: string): boolean;
isFullWidth(value: unknown): boolean;
/**

@@ -230,3 +243,3 @@ * Checks if the string contains any half-width chars.

*/
isHalfWidth(value: string): boolean;
isHalfWidth(value: unknown): boolean;
/**

@@ -236,3 +249,3 @@ * Checks if the string contains variable-width chars.

*/
isVariableWidth(value: string): boolean;
isVariableWidth(value: unknown): boolean;
/**

@@ -242,3 +255,3 @@ * Checks if the string is a hexadecimal color.

*/
isHexColor(value: string): boolean;
isHexColor(value: unknown): boolean;
/**

@@ -248,3 +261,3 @@ * Checks if the string is a hexadecimal number.

*/
isHexadecimal(value: string): boolean;
isHexadecimal(value: unknown): boolean;
/**

@@ -254,7 +267,7 @@ * Checks if the string is an IP (version 4 or 6).

*/
isIP(value: string, version?: number): boolean;
isIP(value: unknown, version?: number): boolean;
/**
* Check if the string is a valid port number.
*/
isPort(value: string): boolean;
isPort(value: unknown): boolean;
/**

@@ -264,3 +277,3 @@ * Checks if the string is an ISBN (version 10 or 13).

*/
isISBN(value: string, version?: number): boolean;
isISBN(value: unknown, version?: number): boolean;
/**

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

*/
isISIN(value: string): boolean;
isISIN(value: unknown): boolean;
/**

@@ -276,3 +289,3 @@ * Checks if the string is a valid ISO 8601 date.

*/
isISO8601(value: string): boolean;
isISO8601(value: unknown): boolean;
/**

@@ -282,8 +295,18 @@ * Checks if the string is valid JSON (note: uses JSON.parse).

*/
isJSON(value: string): boolean;
isJSON(value: unknown): boolean;
/**
* Checks if the value is valid Object.
* Returns false if the value is not an object.
*/
isObject(value: unknown): value is object;
/**
* Checks if the value is valid Object & not empty.
* Returns false if the value is not an object or an empty valid object.
*/
isNotEmptyObject(value: unknown): boolean;
/**
* Checks if the string is lowercase.
* If given value is not a string, then it returns false.
*/
isLowercase(value: string): boolean;
isLowercase(value: unknown): boolean;
/**

@@ -294,3 +317,3 @@ * Checks if the string is a mobile phone number (locale is one of ['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK',

*/
isMobilePhone(value: string, locale: ValidatorJS.MobilePhoneLocale): boolean;
isMobilePhone(value: unknown, locale: ValidatorJS.MobilePhoneLocale): boolean;
/**

@@ -303,11 +326,11 @@ * Checks if the string is a valid phone number.

*/
isPhoneNumber(value: string, region: string): boolean;
isPhoneNumber(value: unknown, region: string): boolean;
/**
* Check 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.
*/
isISO31661Alpha2(value: string): boolean;
isISO31661Alpha2(value: unknown): boolean;
/**
* Check 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.
*/
isISO31661Alpha3(value: string): boolean;
isISO31661Alpha3(value: unknown): boolean;
/**

@@ -317,3 +340,3 @@ * Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId.

*/
isMongoId(value: string): boolean;
isMongoId(value: unknown): boolean;
/**

@@ -323,3 +346,3 @@ * Checks if the string contains one or more multibyte chars.

*/
isMultibyte(value: string): boolean;
isMultibyte(value: unknown): boolean;
/**

@@ -329,3 +352,3 @@ * Checks if the string contains any surrogate pairs chars.

*/
isSurrogatePair(value: string): boolean;
isSurrogatePair(value: unknown): boolean;
/**

@@ -335,3 +358,3 @@ * Checks if the string is an url.

*/
isURL(value: string, options?: ValidatorJS.IsURLOptions): boolean;
isURL(value: unknown, options?: ValidatorJS.IsURLOptions): boolean;
/**

@@ -341,3 +364,3 @@ * Checks if the string is a UUID (version 3, 4 or 5).

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

@@ -347,3 +370,3 @@ * Checks if the string is uppercase.

*/
isUppercase(value: string): boolean;
isUppercase(value: unknown): boolean;
/**

@@ -353,3 +376,3 @@ * Checks if the string's length falls in a range. Note: this function takes into account surrogate pairs.

*/
length(value: string, min: number, max?: number): boolean;
length(value: unknown, min: number, max?: number): boolean;
/**

@@ -359,3 +382,3 @@ * Checks if the string's length is not less than given number. Note: this function takes into account surrogate pairs.

*/
minLength(value: string, min: number): boolean;
minLength(value: unknown, min: number): boolean;
/**

@@ -365,3 +388,3 @@ * Checks if the string's length is not more than given number. Note: this function takes into account surrogate pairs.

*/
maxLength(value: string, max: number): boolean;
maxLength(value: unknown, max: number): boolean;
/**

@@ -371,3 +394,3 @@ * Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i').

*/
matches(value: string, pattern: RegExp, modifiers?: string): boolean;
matches(value: unknown, pattern: RegExp, modifiers?: string): boolean;
/**

@@ -377,3 +400,3 @@ * Checks if the string represents a time without a given timezone in the format HH:MM (military)

*/
isMilitaryTime(value: string): boolean;
isMilitaryTime(value: unknown): boolean;
/**

@@ -383,3 +406,3 @@ * Checks if array contains all values from the given array of values.

*/
arrayContains(array: any[], values: any[]): boolean;
arrayContains(array: unknown, values: any[]): boolean;
/**

@@ -389,3 +412,3 @@ * Checks if array does not contain any of the given values.

*/
arrayNotContains(array: any[], values: any[]): boolean;
arrayNotContains(array: unknown, values: any[]): boolean;
/**

@@ -395,3 +418,3 @@ * Checks if given array is not empty.

*/
arrayNotEmpty(array: any[]): boolean;
arrayNotEmpty(array: unknown): boolean;
/**

@@ -401,3 +424,3 @@ * Checks if array's length is as minimal this number.

*/
arrayMinSize(array: any[], min: number): boolean;
arrayMinSize(array: unknown, min: number): boolean;
/**

@@ -407,3 +430,3 @@ * Checks if array's length is as maximal this number.

*/
arrayMaxSize(array: any[], max: number): boolean;
arrayMaxSize(array: unknown, max: number): boolean;
/**

@@ -413,7 +436,7 @@ * Checks if all array's values are unique. Comparison for objects is reference-based.

*/
arrayUnique(array: any[]): boolean;
arrayUnique(array: unknown): boolean;
/**
* Checks if the value is an instance of the specified object.
*/
isInstance(object: any, targetTypeConstructor: new (...args: any[]) => any): boolean;
isInstance(object: unknown, targetTypeConstructor: new (...args: any[]) => any): boolean;
}

@@ -53,2 +53,10 @@ "use strict";

};
this._isEmptyObject = function (object) {
for (var key in object) {
if (object.hasOwnProperty(key)) {
return false;
}
}
return true;
};
}

@@ -128,2 +136,8 @@ /**

/* type checkers */
case ValidationTypes_1.ValidationTypes.IS_LATLONG:
return this.isLatLong(value);
case ValidationTypes_1.ValidationTypes.IS_LATITUDE:
return this.isLatitude(value);
case ValidationTypes_1.ValidationTypes.IS_LONGITUDE:
return this.isLongitude(value);
case ValidationTypes_1.ValidationTypes.IS_BOOLEAN:

@@ -213,2 +227,6 @@ return this.isBoolean(value);

return this.isJSON(value);
case ValidationTypes_1.ValidationTypes.IS_OBJECT:
return this.isObject(value);
case ValidationTypes_1.ValidationTypes.IS_NOT_EMPTY_OBJECT:
return this.isNotEmptyObject(value);
case ValidationTypes_1.ValidationTypes.IS_LOWERCASE:

@@ -319,2 +337,20 @@ return this.isLowercase(value);

/**
* Checks if a given value is a latitude.
*/
Validator.prototype.isLatLong = function (value) {
return typeof value === "string" && this.validatorJs.isLatLong(value);
};
/**
* Checks if a given value is a latitude.
*/
Validator.prototype.isLatitude = function (value) {
return (typeof value === "number" || this.isString(value)) && this.isLatLong("0," + value);
};
/**
* Checks if a given value is a longitude.
*/
Validator.prototype.isLongitude = function (value) {
return (typeof value === "number" || this.isString(value)) && this.isLatLong(value + ",0");
};
/**
* Checks if a given value is a real date.

@@ -357,2 +393,5 @@ */

if (options === void 0) { options = {}; }
if (typeof value !== "number") {
return false;
}
if (value === Infinity || value === -Infinity) {

@@ -370,3 +409,3 @@ return options.allowInfinity;

Validator.prototype.isInt = function (val) {
return Number.isInteger(val);
return typeof val === "number" && Number.isInteger(val);
};

@@ -415,3 +454,3 @@ // -------------------------------------------------------------------------

Validator.prototype.minDate = function (date, minDate) {
return date && date.getTime() >= minDate.getTime();
return date instanceof Date && date.getTime() >= minDate.getTime();
};

@@ -422,3 +461,3 @@ /**

Validator.prototype.maxDate = function (date, maxDate) {
return date && date.getTime() <= maxDate.getTime();
return date instanceof Date && date.getTime() <= maxDate.getTime();
};

@@ -575,3 +614,3 @@ // -------------------------------------------------------------------------

Validator.prototype.isPort = function (value) {
return this.validatorJs.isPort(value);
return typeof value === "string" && this.validatorJs.isPort(value);
};

@@ -607,2 +646,16 @@ /**

/**
* Checks if the value is valid Object.
* Returns false if the value is not an object.
*/
Validator.prototype.isObject = function (value) {
return value != null && (typeof value === "object" || typeof value === "function") && !Array.isArray(value);
};
/**
* Checks if the value is valid Object & not empty.
* Returns false if the value is not an object or an empty valid object.
*/
Validator.prototype.isNotEmptyObject = function (value) {
return this.isObject(value) && !this._isEmptyObject(value);
};
/**
* Checks if the string is lowercase.

@@ -738,3 +791,3 @@ * If given value is not a string, then it returns false.

return false;
return !array || values.every(function (value) { return array.indexOf(value) !== -1; });
return values.every(function (value) { return array.indexOf(value) !== -1; });
};

@@ -748,3 +801,3 @@ /**

return false;
return !array || values.every(function (value) { return array.indexOf(value) === -1; });
return values.every(function (value) { return array.indexOf(value) === -1; });
};

@@ -756,4 +809,2 @@ /**

Validator.prototype.arrayNotEmpty = function (array) {
if (!(array instanceof Array))
return false;
return array instanceof Array && array.length > 0;

@@ -766,4 +817,2 @@ };

Validator.prototype.arrayMinSize = function (array, min) {
if (!(array instanceof Array))
return false;
return array instanceof Array && array.length >= min;

@@ -776,4 +825,2 @@ };

Validator.prototype.arrayMaxSize = function (array, max) {
if (!(array instanceof Array))
return false;
return array instanceof Array && array.length <= max;

@@ -780,0 +827,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

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