0.0.22 • Published 8 years ago

input-filter v0.0.22

Weekly downloads
133
License
MIT
Repository
github
Last release
8 years ago

input-filter

Build Status InputFilter js implementation for Filtering/Validation data

Example

with ES6 classes

import {InputFilter, Input, StringLength} from 'input-filter'

class LoginFilter extends InputFilter {

    init() {
        let login = new Input('login')
        login.getValidation().add(new StringLength({min: 3}))
        let password = new Input('password')
        password.getValidation().add(new StringLength({min: 3}))

        this.add(login).add(password)
    }
}

var validator = new LoginFilter
//Invalid data
validator.setData({login: 'aa', password: 'dd'})
validator.isValid().then(
    function() {
        console.log('valid')
    },
    function(messages) {
        console.log(messages)
    }
)
//Valid data
validator.setData({login: 'asa', password: 'asd'})
validator.isValid().then(
    function() {
        console.log('valid')
    },
    function(messages) {
        console.log(messages)
    }
)

with InputFilter.factory

import {InputFilter, StringLength, Callback} from 'input-filter'

let fooBarFilter = InputFilter.factory({
    foo: {
        required: false,
        validators: ['Date']
    },
    bar: {
        validators: [
            new StringLength({min:3}),
            new Callback((value) => {
                if (value === '***') {
                    return Promise.reject('value cannot be ***')
                }
            })
        ]
    }
})

fooBarFilter.setData({foo: "", bar: "***"}).isValid().catch((errors) => {
    console.log(errors) //{bar: ['value cannot be ***']}
})

Install

With npm do:

npm install input-filter
0.0.22

8 years ago

0.0.21

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago