Skip to content

Adapcon/validate-args-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Validate-args-js

Validate arguments.

Build Status

Coverage Status

Installation

npm install --save validate-args-js

Usage

Import

const check = require('validate-args-js')

Simple

check.arg({ 
    arg: undefined, 
    err: 'err name' 
})

//Return -> throw new Error('err name')
check.arg({ 
    arg: undefined, 
    err: undefined 
})

//Return -> throw new Error('one argument has not been defined!')

Accept

check.arg({ 
    arg: undefined, 
    err: 'err name',
    accept: {
        options: [1,2,3],
        err: 'err accept name'
    }
})

//Return -> throw new Error('err name')
check.arg({ 
    arg: 4, 
    err: 'err name',
    accept: {
        options: [1,2,3],
        err: 'err accept name'
    }
})

//Return -> throw new Error('err accept name')
check.arg({ 
    arg: 4, 
    err: 'err name',
    accept: {
        options: [1,2,3],
        err: undefined
    }
})

//Return -> throw new Error('one argument has not been accepted!')

List

check.args([
    { 
        arg: 1, 
        err: 'err value',
        accept: {
            options: [1,2,3],
            err: 'err accept value'
        }
    },
    { 
        arg: 4, 
        err: 'err value 2',
        accept: {
            options: [1,2,3],
            err: 'err accept value 2'
        }
    }
])

//Return -> throw new Error('err accept value 2')
check.args([{ 
    arg: undefined, 
    err: 'err name',
    accept: {
        options: [1,2,3],
        err: 'err accept name'
    }
}])

//Return -> throw new Error('err name')

About

Validate arguments to Javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published