@finnair/v-validation
Advanced tools
Comparing version 7.0.0-alpha.1 to 7.0.0-alpha.2
@@ -6,2 +6,8 @@ # Change Log | ||
# [7.0.0-alpha.2](https://github.com/finnair/v-validation/compare/v7.0.0-alpha.1...v7.0.0-alpha.2) (2024-11-08) | ||
### Features | ||
- string size and number between validator chaining ([507f171](https://github.com/finnair/v-validation/commit/507f17124b28e295ecc7f1eef0359729b523076a)) | ||
# [7.0.0-alpha.1](https://github.com/finnair/v-validation/compare/v7.0.0-alpha.0...v7.0.0-alpha.1) (2024-11-08) | ||
@@ -8,0 +14,0 @@ |
@@ -273,2 +273,3 @@ import { Path } from '@finnair/path'; | ||
pattern(pattern: string | RegExp, flags?: string): NextStringValidator; | ||
size(min: number, max: number): NextStringValidator; | ||
} | ||
@@ -327,2 +328,3 @@ export declare class NextStringValidator extends StringValidatorBase<string> { | ||
max(max: number, inclusive?: boolean): NextNumberValidator<In>; | ||
between(min: number, max: number, minInclusive?: boolean, maxInclusive?: boolean): NextNumberValidator<In>; | ||
protected validateNumberFormat(value: number, format: undefined | NumberFormat, path: Path, ctx: ValidationContext): Promise<number>; | ||
@@ -329,0 +331,0 @@ } |
@@ -764,2 +764,5 @@ "use strict"; | ||
} | ||
size(min, max) { | ||
return new NextStringValidator(this, new SizeValidator(min, max)); | ||
} | ||
} | ||
@@ -947,2 +950,13 @@ exports.StringValidatorBase = StringValidatorBase; | ||
} | ||
between(min, max, minInclusive = true, maxInclusive = true) { | ||
if (minInclusive && maxInclusive) { | ||
if (!(min <= max)) { | ||
throw new Error('Between: min shuold be <= max when both are inclusive (i.e. min <= max)'); | ||
} | ||
} | ||
else if (!(min < max)) { | ||
throw new Error('Between: min should be < max when either min or max is exclusive'); | ||
} | ||
return new NextNumberValidator(this, new CompositionValidator([new MinValidator(min, minInclusive), new MaxValidator(max, maxInclusive)])); | ||
} | ||
validateNumberFormat(value, format, path, ctx) { | ||
@@ -949,0 +963,0 @@ switch (format) { |
@@ -273,2 +273,3 @@ import { Path } from '@finnair/path'; | ||
pattern(pattern: string | RegExp, flags?: string): NextStringValidator; | ||
size(min: number, max: number): NextStringValidator; | ||
} | ||
@@ -327,2 +328,3 @@ export declare class NextStringValidator extends StringValidatorBase<string> { | ||
max(max: number, inclusive?: boolean): NextNumberValidator<In>; | ||
between(min: number, max: number, minInclusive?: boolean, maxInclusive?: boolean): NextNumberValidator<In>; | ||
protected validateNumberFormat(value: number, format: undefined | NumberFormat, path: Path, ctx: ValidationContext): Promise<number>; | ||
@@ -329,0 +331,0 @@ } |
@@ -716,2 +716,5 @@ import deepEqual from 'deep-equal'; | ||
} | ||
size(min, max) { | ||
return new NextStringValidator(this, new SizeValidator(min, max)); | ||
} | ||
} | ||
@@ -888,2 +891,13 @@ export class NextStringValidator extends StringValidatorBase { | ||
} | ||
between(min, max, minInclusive = true, maxInclusive = true) { | ||
if (minInclusive && maxInclusive) { | ||
if (!(min <= max)) { | ||
throw new Error('Between: min shuold be <= max when both are inclusive (i.e. min <= max)'); | ||
} | ||
} | ||
else if (!(min < max)) { | ||
throw new Error('Between: min should be < max when either min or max is exclusive'); | ||
} | ||
return new NextNumberValidator(this, new CompositionValidator([new MinValidator(min, minInclusive), new MaxValidator(max, maxInclusive)])); | ||
} | ||
validateNumberFormat(value, format, path, ctx) { | ||
@@ -890,0 +904,0 @@ switch (format) { |
{ | ||
"name": "@finnair/v-validation", | ||
"version": "7.0.0-alpha.1", | ||
"version": "7.0.0-alpha.2", | ||
"private": false, | ||
@@ -51,5 +51,5 @@ "description": "V-validation core package", | ||
"devDependencies": { | ||
"@finnair/path": "^7.0.0-alpha.1" | ||
"@finnair/path": "^7.0.0-alpha.2" | ||
}, | ||
"gitHead": "67d3242f3dac67335aa7275975f1889c50a04c62" | ||
"gitHead": "e5f44227e5c78c322a7874f665b122c5e5446acc" | ||
} |
@@ -32,4 +32,4 @@ ![CI](https://github.com/finnair/v-validation/workflows/CI/badge.svg?branch=master) | ||
* Direct, chainable support for most used "next" validation rules, e.g. `V.number().min(1).max(2)`: | ||
* `V.string()` supports `notEmpty`, `notBlank` and `pattern`. | ||
* `V.number()` supports `min` and `max`. | ||
* `V.string()` supports `notEmpty`, `notBlank`, `pattern` and `size`. | ||
* `V.number()` supports `min`, `max` and `between`. | ||
* Use `Validator#validateValue` to get valid a valid value or an exception directly | ||
@@ -228,3 +228,19 @@ | ||
``` | ||
### Validator Chaining in Version >= 7 | ||
Version 7 offers shortcuts for most common validator chaining cases: | ||
```typescript | ||
V.integer() | ||
.min(1) | ||
.max(1000) | ||
.between(1, 1000); | ||
V.string() | ||
.notEmpty() | ||
.notBlank() | ||
.pattern(/.+/) | ||
.size(1, 10) | ||
``` | ||
## Combining Validators | ||
@@ -231,0 +247,0 @@ |
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
302295
5392
678