Validators.ts (vaadin-flow-4.0.5) | : | Validators.ts (vaadin-flow-4.0.6) | ||
---|---|---|---|---|
/* tslint:disable:max-classes-per-file */ | /* tslint:disable:max-classes-per-file */ | |||
import * as isAfter from 'validator/lib/isAfter'; | import isAfter from 'validator/es/lib/isAfter'; | |||
import * as isBefore from 'validator/lib/isBefore'; | import isBefore from 'validator/es/lib/isBefore'; | |||
import * as isBoolean from 'validator/lib/isBoolean'; | import isBoolean from 'validator/es/lib/isBoolean'; | |||
import * as isDecimal from 'validator/lib/isDecimal'; | import isDecimal from 'validator/es/lib/isDecimal'; | |||
import * as isEmail from 'validator/lib/isEmail'; | import isEmail from 'validator/es/lib/isEmail'; | |||
// @ts-ignore (vlukashov: have not investigated why, but for the `isFloat` modul | import isFloat from 'validator/es/lib/isFloat'; | |||
e the d.ts file is not accurate) | import isLength from 'validator/es/lib/isLength'; | |||
import {default as isFloat} from 'validator/lib/isFloat'; | import isNumeric from 'validator/es/lib/isNumeric'; | |||
import * as isLength from 'validator/lib/isLength'; | import matches from 'validator/es/lib/matches'; | |||
import * as isNumeric from 'validator/lib/isNumeric'; | import toFloat from 'validator/es/lib/toFloat'; | |||
import * as matches from 'validator/lib/matches'; | ||||
import * as toFloat from 'validator/lib/toFloat'; | ||||
import { Validator } from './Validation'; | import { Validator } from './Validation'; | |||
interface ValidatorAttributes { | interface ValidatorAttributes { | |||
message?: string; | message?: string; | |||
} | } | |||
interface ValueNumberAttributes extends ValidatorAttributes { | interface ValueNumberAttributes extends ValidatorAttributes { | |||
value: number | string; | value: number | string; | |||
} | } | |||
interface DigitAttributes extends ValidatorAttributes { | interface DigitAttributes extends ValidatorAttributes { | |||
integer: number; | integer: number; | |||
skipping to change at line 60 | skipping to change at line 59 | |||
validate(value: T){ | validate(value: T){ | |||
if (typeof value === 'string' || Array.isArray(value)) { | if (typeof value === 'string' || Array.isArray(value)) { | |||
return value.length > 0; | return value.length > 0; | |||
} else if (typeof value === 'number') { | } else if (typeof value === 'number') { | |||
return Number.isFinite(value); | return Number.isFinite(value); | |||
} | } | |||
return value !== undefined; | return value !== undefined; | |||
} | } | |||
} | } | |||
function _asValidatorAttributes(attrs: ValueNumberAttributes | number | string | PatternAttributes | string | RegExp) { | function _asValidatorAttributes(attrs: ValueNumberAttributes | number | string | PatternAttributes | RegExp) { | |||
return typeof attrs === 'object' ? attrs : {}; | return typeof attrs === 'object' ? attrs : {}; | |||
} | } | |||
function _value(attrs: ValueNumberAttributes | number | string) { | function _value(attrs: ValueNumberAttributes | number | string) { | |||
return typeof attrs === 'object' ? attrs.value : attrs; | return typeof attrs === 'object' ? attrs.value : attrs; | |||
} | } | |||
abstract class ValueNumberValidator<T> extends AbstractValidator<T> { | abstract class ValueNumberValidator<T> extends AbstractValidator<T> { | |||
value: number; | value: number; | |||
constructor(attrs: ValueNumberAttributes | number | string) { | constructor(attrs: ValueNumberAttributes | number | string) { | |||
skipping to change at line 222 | skipping to change at line 221 | |||
this.min = _min(attrs); | this.min = _min(attrs); | |||
this.max = _max(attrs); | this.max = _max(attrs); | |||
if (this.min > 0) { | if (this.min > 0) { | |||
this.impliesRequired = true; | this.impliesRequired = true; | |||
} | } | |||
} | } | |||
validate = (value: string) => { | validate = (value: string) => { | |||
if (this.min && this.min > 0 && !new Required().validate(value)) { | if (this.min && this.min > 0 && !new Required().validate(value)) { | |||
return false; | return false; | |||
} | } | |||
return isLength(value, this.min, this.max); | return isLength(value, { min: this.min, max: this.max }); | |||
} | } | |||
} | } | |||
export class Digits extends AbstractValidator<string> { | export class Digits extends AbstractValidator<string> { | |||
integer: number; | integer: number; | |||
fraction: number; | fraction: number; | |||
constructor(attrs: DigitAttributes) { | constructor(attrs: DigitAttributes) { | |||
super({ | super({ | |||
message: `numeric value out of bounds (<${attrs.integer} digits>.<${attrs. fraction} digits> expected)`, | message: `numeric value out of bounds (<${attrs.integer} digits>.<${attrs. fraction} digits> expected)`, | |||
...attrs | ...attrs | |||
End of changes. 3 change blocks. | ||||
14 lines changed or deleted | 12 lines changed or added |