Giter VIP home page Giter VIP logo

valua's Introduction

Valua - Validation for Lua

Build Status Coverage Status

A module for making chained validations. Create your objects, append your tests, use and reuse it!

Originally bundled with Sailor MVC Web Framework, now released as a separated module. https://github.com/Etiene/sailor

This module provides tools for validating values, very useful in forms, but also usable elsewhere. It works in appended chains. Create a new validation object and start chaining your test functions. If your value fails a test, it breaks the chain and does not evaluate the rest of it. It returns a boolean and an error string (nil when tests succeeded).

Valua is also available through luarocks

luarocks install valua

Usage

Example 1 - Just create, chain and use:

valua:new().type("string").len(3,5)("test string!") -- false, "should have 3-5 characters"

Example 2 - Create, chain and later use it multiple times:

local reusable_validation = valua:new().type("string").len(3,5)
reusable_validation("test string!") -- false, "should have 3-5 characters"
reusable_validation("test!") -- true

Current validation functions

  • alnum() - Checks if string is alphanumeric.
  • boolean() - Checks if value is a boolean.
  • compare(another_value) - Checks if value is equal to another value.
  • contains(substr) - Checks if a string contains a substring.
  • date() or date(format) - Checks if a string is a valid date. Default format is UK (dd/mm/yyyy). Also checks for US and ISO formats.
  • email() - Checks if a string is a valid email address.
  • empty() - Checks if a value is empty.
  • integer() - Checks if a number is an integer;
  • in_list(list) - Checks if a value is inside an array.
  • len(min,max) - Checks if a string's length is between min and max.
  • match(pattern) - Checks if a string matches a given pattern.
  • max(n) - Checks if a number is equal or less than n.
  • min(n) - Checks if a number is equal or greater than n.
  • not_empty() - Checks if a value is not empty.
  • no_white() - Checks if a string contains no white spaces.
  • number() - Checks if a value is a number.
  • string() - Checks if a value is a string.
  • type(t) - Checks if a value is of type t.
  • optional(t) - If value is nil it would be accepted. If it's not nil it would be processed with other chained validation functions as usually done.

Copyright (c) 2014 Etiene Dalcol

http://etiene.net

http://twitter.com/etiene_d

License: MIT

Inspired by Respect Validation for PHP

https://github.com/Respect/Validation

valua's People

Contributors

d9k avatar etiene avatar felipedaragon avatar fperrad avatar ignacio avatar soapdog avatar tieske avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

valua's Issues

Add optional validator

Would be cool to have ability to mark value as optional.

I see 3 options

Have a second parameter for validation e.g:

value = nil -- or value = ""
valua:new().type("string").len(3,5)(value) -- returns false
valua:new().type("string").len(3,5)(value, true) -- returns true

Have a parameter on creation e.g:

value = nil -- or value = ""
valua:new().type("string").len(3,5)(value) -- returns false
valua:new(true).type("string").len(3,5)(value) -- returns true

Have stackable function e.g:

value = nil -- or value = ""
valua:new().type("string").len(3,5)(value) -- returns false
valua:new().optional().type("string").len(3,5)(value) -- returns true

rockspecs

There is a valua 0.2.2 on LuaRocks but the rockspec is not in the GitHub repository and it does not support 5.3. There is a valua-0.2.1-2 rockspec that supports 5.3 in the repository but it is invalid (the version in the file is wrong) and it is not in LuaRocks.

luarocks or opm

Hello!

Valua is a very cool package but its actual version is not installable by luarocks or opm.
It`s unfair!
Would you update it?

Thank you!

version 0.2.2-2 failing to install

sudo luarocks install valua 0.2.2-2
Installing http://luarocks.org/repositories/rocks/valua-0.2.2-2.rockspec...
Using http://luarocks.org/repositories/rocks/valua-0.2.2-2.rockspec... switching to 'build' mode
Cloning into 'valua'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 7 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (7/7), 5.53 KiB | 0 bytes/s, done.
Checking connectivity... done.
Note: checking out '5c541c55c1a16469ef7ed1c34de2511f6916c6a3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

cp: cannot stat ‘valua.lua’: No such file or directory

Error: Failed copying valua.lua
ubuntu@ip-10-77-56-125:~$ sudo luarocks install valua 0.2.2-1
Installing http://luarocks.org/repositories/rocks/valua-0.2.2-1.src.rock...
Using http://luarocks.org/repositories/rocks/valua-0.2.2-1.src.rock... switching to 'build' mode
Archive: /tmp/luarocks_luarocks-rock-valua-0.2.2-1-6206/valua-0.2.2-1.src.rock
inflating: valua-0.2.2-1.rockspec
extracting: valua-0.2.2.tar.gz
Updating manifest for /usr/local/lib/luarocks/rocks

valua 0.2.2-1 is now built and installed in /usr/local/ (license: MIT)

Update version on luarocks

The version available on luarocks won't even install, the only way to install sailor is to clone valua manually and installing it with "luarocks make"

Unable to install Valua under Centos7 using LuaRocks

Attempt to install valua using Cento7 32-bit OS with the following command:
sudo luarocks install valua

Results in the following error message:

[tonyd@morspirit ~]$ sudo luarocks install valua
[sudo] password for tonyd:
Installing http://www.luarocks.org/repositories/rocks/valua-0.3-1.src.rock...
Using http://www.luarocks.org/repositories/rocks/valua-0.3-1.src.rock... switching to 'build' mode

Error: Failed copying valua.lua

Installed lua RPM Packages:
lua-5.1.4-14.el7.i686
lua-devel-5.1.4-14.el7.i686
luarocks-2.1.2-1.el6.noarch

All other sailor pre-requisite rocks installed successfully; I have successfully installed and used other luarocks modules ('sha1' and 'odbc')

@TDycks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.