New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

comp-val

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comp-val

composable validation

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

@tww/cval Composable Validation!

comes with typescript definitions

npm install --save @tww/cval

Examples

import cval from '@tww/cval'
  // using validations individually
  const validResultFromEmail = cval.isEmail('myEmailFeild', 'bob@bob.com')

  // '' because bob@bob.com is valid
  console.log('email error', validResultFromEmail)

  const invalidResultFromEmail = cval.isEmail('myEmailFeild', 'bob$bob.com')

  // 'myEmailField must be a valid email' because bob$bob.com is invalid
  console.log('email error', validResultFromEmail)


  const validateEmail = cval.composeValidations(
    cval.isEmail,
    cval.minLength(6),
    cval.maxLength(15)
  )

  // empty array is returned, no errors
  let errors = validateEmail('myEmailField', 'steve@bob.com')
  console.log(errors.length) // 0 
  
  // steve@bobcom is not a valid email
  errors = validateEmail('myEmailField', 'steve@bobcom')
  console.log(errors.length, errors) // 1 error returned
  // ['myEmailField must be a valid email'] 

  // a@bc is not a valid email, and it's too short!
  errors = validateEmail('myEmailField', 'a@bc')
  console.log(errors.length, errors) // 1 error returned
  // ['myEmailField must be a valid email', 'myEmailField must be at least 9 characters'] 

Docs and bundled validation

Checkout our validation docs

FAQs

Package last updated on 26 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts