3.11.3 • Published 4 months ago

@baloise/web-app-validators v3.11.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

@baloise/web-app-validators

Continuous Release npm npm bundle size npm GitHub GitHub issues

The library serve a collection of validator functions.

Installation

npm install @baloise/web-app-validators

Usage

API

isCustom

isCustom(validatorFn: BalValidatorFn) => BalValidatorFn

Returns true if the value date is before the given date.

BalValidators.isCustom(value => value > 2)(3) // true

isBefore

isBefore(date: any) => BalValidatorFn

Returns true if the value date is before the given date

BalValidators.isBefore('2000-01-02')('2000-01-01') // true
BalValidators.isBefore(new Date(2020, 0, 2))(new Date(2020, 0, 1)) // true

isAfter

isAfter(date: any) => BalValidatorFn

Returns true if the value date is before the given date

BalValidators.isAfter('2000-01-01')('2000-01-02') // true
BalValidators.isAfter(new Date(2020, 0, 1))(new Date(2020, 0, 2)) // true

isDate

isDate() => BalValidatorFn

Returns true if the value is valid date

BalValidators.isDate()('2000-01-02') // true
BalValidators.isDate()(new Date(2000, 0, 1)) // true

isMin

isMin(min: number) => BalValidatorFn

Returns true if the number is bigger or equal than the min number

BalValidators.isMin(10)(10) // true
BalValidators.isMin(10)(11) // true
BalValidators.isMin(10)(9) // false

isMax

isMax(max: number) => BalValidatorFn

Returns true if the number is smaller or equal than the max number

BalValidators.isMax(10)(10) // true
BalValidators.isMax(10)(9) // true
BalValidators.isMax(10)(11) // false

isNumber

isNumber() => BalValidatorFn

Returns true if the number is valid

BalValidators.isNumber()(10) // true
BalValidators.isNumber()('10') // true
BalValidators.isNumber()('a') // false

isMonetaryNumber

isMonetaryNumber() => BalValidatorFn

Returns true if the value is a valid formatted number

BalValidators.isMonetaryNumber()(10) // true
BalValidators.isMonetaryNumber()(`1'000.99`) // true
BalValidators.isMonetaryNumber()(`a`) // false

matchesRegex

matchesRegex(regex: RegExp) => BalValidatorFn

Returns true if the value matches the regex

BalValidators.matchesRegex(new RegExp('^\\d+$'))('1') // true

isEmail

isEmail() => BalValidatorFn

Returns true if the value matches the regex

BalValidators.isEmail()('peter@baloise.ch') // true

isPhone

isPhone() => BalValidatorFn

Returns true if the value matches the regex

BalValidators.isPhone()('123 456 78 90') // true

isRequired

isRequired() => BalValidatorFn

Returns true if the value is a non-empty value

BalValidators.isRequired()('foo') // true
BalValidators.isRequired()('') // false

isRequiredTrue

isRequiredTrue() => BalValidatorFn

Returns true if the value is true. This validator is commonly used for required checkboxes.

BalValidators.isRequiredTrue()(true) // true
BalValidators.isRequiredTrue()('') // false

isMinLength

isMinLength(minLength: number) => BalValidatorFn

Returns true if the string is bigger or equal than the min length

BalValidators.isMinLength(3)('123') // true
BalValidators.isMinLength(3)('12') // false

isMaxLength

isMaxLength(maxLength: number) => BalValidatorFn

Returns true if the string is smaller or equal than the max length

BalValidators.isMaxLength(3)('123') // true
BalValidators.isMaxLength(3)('1234') // false

validateConditionally

validateConditionally(validatorFn: BalValidatorFn, conditionFn: BalValidatorFn) => BalValidatorFn

Returns true if the condition is true and the validations is true too.

BalValidators.validateConditionally(
  value => value > 2,
  () => true,
)(3) // true
BalValidators.validateConditionally(
  value => value > 2,
  () => false,
)(3) // undefined
3.11.3

4 months ago

3.11.2

8 months ago

3.10.1

1 year ago

3.10.0

1 year ago

3.11.0

1 year ago

3.11.1

1 year ago

3.9.0

1 year ago

3.7.1-beta.302

1 year ago

3.7.1-beta.304

1 year ago

3.7.1-beta.303

1 year ago

3.7.1-beta.305

1 year ago

3.7.3

1 year ago

3.7.2

1 year ago

3.8.0

1 year ago

3.6.4

2 years ago

3.6.3

2 years ago

3.7.2-beta.1

1 year ago

3.7.1

1 year ago

3.7.0

1 year ago

3.3.2-beta.4

2 years ago

3.3.2-beta.7

2 years ago

3.3.2-beta.8

2 years ago

3.3.2-beta.5

2 years ago

3.3.2-beta.6

2 years ago

3.3.2-beta.9

2 years ago

3.3.2-beta.20

2 years ago

3.3.2-beta.22

2 years ago

3.3.2-beta.24

2 years ago

3.3.2-beta.23

2 years ago

3.6.2

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.3.2-beta.14

2 years ago

3.3.2-beta.17

2 years ago

3.3.2-beta.16

2 years ago

3.3.2-beta.19

2 years ago

3.3.2-beta.18

2 years ago

3.3.2-beta.13

2 years ago

3.5.0

2 years ago

3.4.0

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.1

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.2-beta.3

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.0.1

2 years ago