عکس mamal72
Validate anything as you need using a simple higher order functionTypeScript
موضوع‌ها
۰
فورک‌ها
۰
ستاره‌ها
۵
تاریخ ایجاد
۸ اردیبهشت ۱۳۹۹
آخرین بروزرسانی
حدود ۲ ماه قبل
لایسنس
MIT License

NPM Build Status codecov David npm npm bundle size npm

eyval

Validate anything as you need using a simple higher order function.

Installation

NPM:

npm i eyval

Yarn:

yarn add eyval

Usage

Basic usage example:

import eyval from 'eyval'

const isOldEnough = (age: number) => age >= 18
const isYoungEnough = (age: number) => age < 100

const validateAge = eyval<number>(isOldEnough, isYoungEnough)

const validAge = 20
const tooYoung = 14
const tooOld = 200

validateAge(validAge) // returns true
validateAge(tooYoung) // returns false
validateAge(tooOld) // returns false

Another Example using validator npm package:

import eyval from 'eyval'
import isEmail from 'validator/lib/isEmail'

const validEmailAddress = 'foo@bar.com'
const invalidEmailAddress = 'foo@bar'

const validateEmail = eyval<string>(isEmail)

validateEmail(validEmailAddress) // returns true
validateEmail(invalidEmailAddress) // returns false

Contribution

You can report bugs and issues here.

You can also send a PR if you feel like you can improve or fix something. Don't forget to write/update tests for your changes.