npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@validarium/validations

v0.9.0

Published

Common validation functions.

Downloads

211

Readme

Validations

validations

This package contains common validation functions


validations.hasNoWhiteSpace ⇒ Object

Checks if a string contains no white space.

Returns: Object - {message Object} when predicate fails or null when pass
Category: number
Example

> hasNoWhiteSpace("")
null

> hasNoWhiteSpace("validarium")
null

> hasNoWhiteSpace("vali darium")
{message Object}

validations.isInteger ⇒ Object

Checks if the value is an integer

Returns: Object - {message Object} when predicate fails or null when pass
Category: number
Example

> isInteger(2)
null

> isInteger(2.1)
{message Object}

validations.isNegativeNumber ⇒ Object

Checks if the value is a negative number

Returns: Object - {message Object} when predicate fails or null when pass
Category: number
Example

> isNegativeNumber(-5)
null

> isNegativeNumber(5)
{message Object}

> isNegativeNumber(0)
{message Object}

validations.isPositiveNumber ⇒ Object

Checks if the value is a positive number

Returns: Object - {message Object} when predicate fails or null when pass
Category: number
Example

> isPositiveNumber(5)
null

> isPositiveNumber(-5)
{message Object}

> isPositiveNumber(0)
{message Object}

validations.hasAgeInInterval(minAge, maxAge) ⇒ Object

Checks if the age is in specified interval

Returns: Object - {message Object} when predicate fails or null when pass
Category: number

| Param | Type | Description | | --- | --- | --- | | minAge | number | minimal age | | maxAge | number | maximal age |

Example

> hasAgeInInterval(1, 3)(2)
null

> hasAgeInInterval(1, 3)(3)
null

> hasAgeInInterval(1, 3)(5)
{message Object}

validations.hasValueInInterval(min, max) ⇒ Object

Checks if the value has only digits

Returns: Object - {message Object} when predicate fails or null when pass
Category: number

| Param | Type | Description | | --- | --- | --- | | min | number | lower interval endpoint | | max | number | upper interval endpoint |

Example

> hasValueInInterval(1, 3)(2)
null

> hasValueInInterval(1, 3)(3)
null

> hasValueInInterval(1, 3)(5)
{message Object}

validations.hasValueMax(max) ⇒ Object

Checks if the value is lower or equal to max

Returns: Object - {message Object} when predicate fails or null when pass
Category: number

| Param | Type | Description | | --- | --- | --- | | max | number | maximum value |

Example

> hasValueMax(2)(1)
null

> hasValueMax(2)(2)
null

> hasValueMax(2)(3)
{message Object}

validations.hasValueMin(min) ⇒ Object

Checks if the value is higher or equal to min

Returns: Object - {message Object} when predicate fails or null when pass
Category: number

| Param | Type | Description | | --- | --- | --- | | min | number | minimum value |

Example

> hasValueMin(2)(3)
null

> hasValueMin(2)(2)
null

> hasValueMin(2)(1)
{message Object}

validations.isDivisibleBy(divisor) ⇒ Object

Checks is value is divisible by desired divisor

Returns: Object - {message Object} when predicate fails or null when pass
Category: number

| Param | Type | Description | | --- | --- | --- | | divisor | number | divisor |

Example

> isDivisibleBy(5)(10)
null

> isDivisibleBy(6)(10)
{message Object}

validations.isRequired ⇒ Object

Checks if the value is present

Returns: Object - {message Object} when predicate fails or null when pass
Category: other
Example

> isRequired('abc')
null

> isRequired(null)
{message Object}

validations.isRequiredNumber ⇒ Object

Checks if the value is present

Returns: Object - {message Object} when predicate fails or null when pass
Category: other
Example

> isRequiredNumber(0)
null

> isRequiredNumber(null)
{message Object}

validations.hasNoSpecialSymbols ⇒ Object

Checks if the value doesn't contain any special symbol

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> hasNoSpecialSymbols('abc')
null

> hasNoSpecialSymbols('a%b')
{message Object}

validations.hasOnlyDigits ⇒ Object

Checks if the value has only digits

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> hasOnlyDigits('123')
null

> hasOnlyDigits('12n3')
{message Object}

validations.isEmail ⇒ Object

Checks if the value is valid email

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isEmail('[email protected]')
null

> isEmail('emailpostemail')
{message Object}

validations.isNumber ⇒ Object

Checks if the value is a number

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isNumber('3')
null

> isNumber('abc')
{message Object}

validations.visPhoneNumber ⇒ Object

Checks if the value is a valid phone number

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isPhoneNumber('980123456')
null

> isPhoneNumber('23')
{message Object}

validations.isString ⇒ Object

Checks if value is type of string

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isString('abc')
null

> isString('')
null

> isString(123)
{message Object}

validations.isTrimmed ⇒ Object

Checkes if the string do not starts or ends with whitespaces.

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isTrimmed('valid value')
null

> isTrimmed(' invalid value')
{message Object}

> isTrimmed('invalid value ')
{message Object}

> isTrimmed(' invalid value ')
{message Object}

validations.isTrimmedLeft ⇒ Object

Checkes if the string do not starts with whitespaces.

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isTrimmedLeft('valid value')
null

> isTrimmedLeft(' invalid value')
{message Object}

validations.isTrimmedRight ⇒ Object

Checkes if the string do not ends with whitespaces.

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isTrimmedRight('valid value')
null

> isTrimmedRight('invalid value  ')
{message Object}

validations.isValidIban ⇒ Object

Checks if the value is a valid IBAN

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> isValidIban('CH4217423156868474686')
null

> isValidIban('CZ123')
{message Object}

validations.matches ⇒ Object

Checks if value matches the given predicate

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Type | Description | | --- | --- | | string | predicate |

Example

> matches('/([a-z]a)/g')('banana')
null

> matches('/([a-z]a)/g')('blueberry')
{message Object}

validations.hasDateMax(max) ⇒ Object

Checks if the the date is maximally the specified value

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | max | string | maximum date |

Example

> hasDateMax('2032-07-01')('2020-07-01')
null

> hasDateMax('2032-07-01')('2032-07-01')
null

> hasDateMax('2032-07-01')('2032-07-02')
{message Object}

validations.hasDateMin(min) ⇒ Object

Checks if the the date is minimally the specified value

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | min | string | minimal date |

Example

> hasDateMin('2032-07-01')('2040-07-01')
null

> hasDateMin('2032-07-01')('2032-07-01')
null

> hasDateMin('2032-07-02')('2032-07-01')
{message Object}

validations.hasLength(length) ⇒ Object

Checks if the value has exact length

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | length | number | desired length for value |

Example

> hasLength(6)('abcdef')
null

> hasLength(6)('abc')
{message Object}

validations.hasLengthInInterval(min, max) ⇒ Object

Checks if the value has length in interval

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | min | number | lower interval endpoint | | max | number | upper interval endpoint |

Example

> hasLengthInInterval(2, 6)('abcd')
null

> hasLengthInInterval(2, 6)('abcdef')
null

> hasLengthInInterval(2, 6)('a')
{message Object}

validations.hasLengthMax(max) ⇒ Object

Checks if the values length is lower or equal to max

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | max | number | maximum value |

Example

> hasLengthMax(2)('a')
null

> hasLengthMax(2)('ab')
null

> hasLengthMax(2)('abc')
{message Object}

validations.hasLengthMin(min) ⇒ Object

Checks if the values length is higher or equal to min

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | min | number | minimum value |

Example

> hasLengthMin(2)('abc')
null

> hasLengthMin(2)('ab')
null

> hasLengthMin(2)('a')
{message Object}

validations.isNumber(list) ⇒ Object

Checks if the value doesn't equal any list item

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | list | array | array of values |

Example

> isNotOneOf(['apple', 'pineapple', 'banana'])('banana')
null

> isNotOneOf(['apple', 'pineapple', 'banana'])('blueberry')
{message Object}

validations.isOneOf(list) ⇒ Object

Checks if the value equals any list item

Returns: Object - {message Object} when predicate fails or null when pass
Category: string

| Param | Type | Description | | --- | --- | --- | | list | array | array of values |

Example

> isOneOf(['apple', 'pineapple', 'banana'])('banana')
null

> isOneOf(['apple', 'pineapple', 'banana'])('blueberry')
{message Object}

validations.startsWith() ⇒ Object

Checks if the value starts with specific string

Returns: Object - {message Object} when predicate fails or null when pass
Category: string
Example

> startsWith('dog')('dogo')
null

> startsWith('dog')('cato')
{message Object}

Related projects

  • @redux-tools – Maintaining large Redux applications with ease.
  • react-union – Integrate React apps into various CMSs seamlessly.
  • lundium – Beautiful React component library.

License

All packages are distributed under the MIT license. See the license here.