New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

input-filter

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

input-filter

InputFilter js implementation

  • 0.0.22
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
143
increased by68.24%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 18 Nov 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc