0.0.22 • Published 9 years ago

input-filter v0.0.22

Weekly downloads
133
License
MIT
Repository
github
Last release
9 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

9 years ago

0.0.21

9 years ago

0.0.20

9 years ago

0.0.19

9 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

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago