3.0.0 • Published 9 years ago

vali-filter v3.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

vali-filter

Module that filters and validates data.

Features

  • Validate deeply nested data
  • validate lists
  • validate strings
  • return data that is ready to be inserted into the database!
  • Almost all Laravel validators implemented (more to come)

Example:

var body = {
	info: {
		name: 'Rinalds',
		surname: 'Zukulis',
		age: 20
	},
	cards: [1,3,4,5,3,2,14,12,21,2,23],
	group: [
		{
			name: 'janis',
			evil: 'yes'
		},
		{
			name: 'peteris',
			evil: 'yes'
		},
		{
			name: 'juris',
			evil: 'yes'
		},
	],
	agreed: true,
	agreedOn: '2015-01-01T05:06:07',
	password: 'rerere',
	password_confirmation: 'rerere',
	j: '{"name":"Rinalds"}'
}

var validate = require('vali-filter')();

var data = validate(body, {
	info: {
		name: 'required|alpha_num|min:2|max:10',
		surname: 'required|alpha_num|min:2|max:10',
		age: 'integer|digits_between:2,3',
	},
	cards: ['required|min:2|max:15', 'integer|max:200'],
	group: ['required|min:2|max:15', {
		name: 'required|integer'
	}],
	agreed: 'required|accepted',
	agreedOn: 'required|date',
	password: 'required|confirmed|in:rerere,rer,asdasd',
	j: 'required|json'
});

if(data.invalid)
	return console.log(data.errors);

console.log(data);

Note

  • rule "simple_text" not only validates but sanitizes html for XSS attacks. For example "<script> alert("evil things") </script>" will be sanitized to "&lt;script&gt; alert("evil things") &lt;/script&lt;""

Installation

$ npm install vali-filter

Docs & Community

3.0.0

9 years ago

2.0.0

9 years ago

1.5.0

10 years ago

1.4.0

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.5

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago