JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 145
  • Score
    100M100P100Q71984F
  • License MIT

InputFilter js implementation

Package Exports

  • input-filter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (input-filter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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