File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,8 @@ Type validators can be used to validate the type of the validated value. These v
63
63
* ` userdata `
64
64
* ` function ` or ` func ` (as the function is a reserved keyword in Lua)
65
65
* ` thread `
66
- * ` integer ` (works only with Lua > 5.3, ` math.type(nbr) == 'integer' ` )
67
- * ` float ` (works only with Lua > 5.3, ` math.type(nbr) == 'float' ` )
66
+ * ` integer ` (works only with Lua >= 5.3, ` math.type(nbr) == 'integer' ` )
67
+ * ` float ` (works only with Lua >= 5.3, ` math.type(nbr) == 'float' ` )
68
68
* ` file ` (` io.type(value) == 'file' ` )
69
69
70
70
#### Example
@@ -102,6 +102,7 @@ Validation factory consist of different validators and filters used to validate
102
102
* ` unmatch(pattern[, init]) ` , validates that the value does not match (` string.match ` ) the pattern
103
103
* ` tostring() ` , converts value to string
104
104
* ` tonumber([base]) ` , converts value to number
105
+ * ` tointeger() ` , converts value to integer (works only with Lua >= 5.3, ` math.tointeger' ` )
105
106
* ` lower() ` , converts value to lower case
106
107
* ` upper() ` , converts value to upper case
107
108
* ` trim() ` , trims whitespace from the left and the right
Original file line number Diff line number Diff line change @@ -9,18 +9,21 @@ local upper = string.upper
9
9
local pairs = pairs
10
10
local gsub = string.gsub
11
11
local type = type
12
+ local iotype = io.type
13
+ local mathtype = math.type
14
+ local tointeger = math.tointeger
12
15
local len = string.len
13
16
if utf8 and utf8.len then
14
17
len = utf8.len
15
18
end
16
19
local function istype (t )
17
20
if t == " integer" or t == " float" then
18
21
return function (value )
19
- return math.type (value ) == t
22
+ return mathtype (value ) == t
20
23
end
21
24
elseif t == " file" then
22
25
return function (value )
23
- return io.type (value ) == t
26
+ return iotype (value ) == t
24
27
end
25
28
else
26
29
return function (value )
@@ -140,6 +143,12 @@ function factory.tonumber(base)
140
143
return nbr ~= nil , nbr
141
144
end
142
145
end
146
+ function factory .tointeger ()
147
+ return function (value )
148
+ local nbr = tointeger (value )
149
+ return nbr ~= nil , nbr
150
+ end
151
+ end
143
152
function factory .lower ()
144
153
return function (value )
145
154
if type (value ) == " string" or type (value ) == " number" then
You can’t perform that action at this time.
0 commit comments