@vitrical/utils
Advanced tools
Comparing version 1.3.7 to 1.3.8
@@ -112,4 +112,28 @@ "use strict"; | ||
}); | ||
it('Optional + array, too short', () => { | ||
const result = (0, validation_1.validateObject)({ | ||
str: ['string[]?', 3, 100], | ||
}, { | ||
str: ['sfe', 'adad'], | ||
}); | ||
expect(result.length).toEqual(1); | ||
}); | ||
it('Optional + array, too long', () => { | ||
const result = (0, validation_1.validateObject)({ | ||
str: ['string[]?', 2, 3], | ||
}, { | ||
str: ['sfe', 'adad', 'sfsfs', 'sfsfs'], | ||
}); | ||
expect(result.length).toEqual(1); | ||
}); | ||
it('Optional + array', () => { | ||
const result = (0, validation_1.validateObject)({ | ||
str: ['string[]?', 2, 4], | ||
}, { | ||
str: ['sfe', 'adad', 'sfsfs', 'sfsfs'], | ||
}); | ||
expect(result.length).toEqual(0); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=validation.test.js.map |
@@ -180,3 +180,42 @@ import { validateObject } from '../validation' | ||
}) | ||
it('Optional + array, too short', () => { | ||
const result = validateObject( | ||
{ | ||
str: ['string[]?', 3, 100], | ||
}, | ||
{ | ||
str: ['sfe', 'adad'], | ||
} | ||
) | ||
expect(result.length).toEqual(1) | ||
}) | ||
it('Optional + array, too long', () => { | ||
const result = validateObject( | ||
{ | ||
str: ['string[]?', 2, 3], | ||
}, | ||
{ | ||
str: ['sfe', 'adad', 'sfsfs', 'sfsfs'], | ||
} | ||
) | ||
expect(result.length).toEqual(1) | ||
}) | ||
it('Optional + array', () => { | ||
const result = validateObject( | ||
{ | ||
str: ['string[]?', 2, 4], | ||
}, | ||
{ | ||
str: ['sfe', 'adad', 'sfsfs', 'sfsfs'], | ||
} | ||
) | ||
expect(result.length).toEqual(0) | ||
}) | ||
}) | ||
}) |
{ | ||
"name": "@vitrical/utils", | ||
"version": "1.3.7", | ||
"version": "1.3.8", | ||
"description": "Collection of useful functions and typings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,7 +14,8 @@ export declare const objectHasProperty: (obj: unknown, property: string | number) => obj is { | ||
type ValidationLength = 'number' | 'string' | 'array' | 'number?' | 'string?' | 'array?'; | ||
type ValidationRegular = 'bigint' | 'boolean' | 'object' | 'undefined' | 'bigint?' | 'boolean?' | 'object?'; | ||
type ValidationRegular = 'bigint' | 'boolean' | 'object' | 'undefined' | 'bigint?' | 'boolean?' | 'object?' | 'any'; | ||
type ValidationArray = 'number[]' | 'string[]' | 'boolean[]' | 'object[]' | 'bigint[]' | 'undefined[]' | 'array[]'; | ||
type ValidationArrayOptional = 'number[]?' | 'string[]?' | 'boolean[]?' | 'object[]?' | 'bigint[]?' | 'undefined[]?'; | ||
type MaxLength = number; | ||
type MinLength = number; | ||
type SchemaInput = [ValidationLength, MinLength, MaxLength] | ValidationRegular | ValidationLength | ValidationArray | [ValidationArray, MinLength, MaxLength] | 'any'; | ||
type SchemaInput = [ValidationLength, MinLength, MaxLength] | ValidationRegular | ValidationLength | ValidationArray | [ValidationArray, MinLength, MaxLength] | ValidationArrayOptional | [ValidationArrayOptional, MinLength, MaxLength]; | ||
export type ValidateObjectOptions<T extends { | ||
@@ -25,3 +26,3 @@ [key: string]: unknown; | ||
}; | ||
export declare const isValidationType: (validationType: ValidationLength | ValidationArray | ValidationRegular, value: unknown) => boolean; | ||
export declare const isValidationType: (validationType: ValidationLength | ValidationArray | ValidationRegular | ValidationArrayOptional, value: unknown) => boolean; | ||
export declare const validateObject: <T extends { | ||
@@ -28,0 +29,0 @@ [key: string]: unknown; |
@@ -108,2 +108,44 @@ "use strict"; | ||
break; | ||
case 'undefined[]': | ||
if (!Array.isArray(value) || value.some((v) => typeof v !== 'undefined')) | ||
return false; | ||
break; | ||
case 'any': | ||
break; | ||
case 'number[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'number')) | ||
return false; | ||
break; | ||
case 'string[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'string')) | ||
return false; | ||
break; | ||
case 'boolean[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'boolean')) | ||
return false; | ||
break; | ||
case 'object[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'object')) | ||
return false; | ||
break; | ||
case 'bigint[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'bigint')) | ||
return false; | ||
break; | ||
case 'undefined[]?': | ||
if (typeof value !== 'undefined' && !Array.isArray(value)) | ||
return false; | ||
if (Array.isArray(value) && value.some((v) => typeof v !== 'undefined')) | ||
return false; | ||
break; | ||
default: | ||
@@ -110,0 +152,0 @@ if (typeof value !== validationType) |
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
59744
1031