Skip to content

Commit

Permalink
add lua-livr
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad authored and hishamhm committed Jul 22, 2024
1 parent 537ef87 commit 8c80344
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
38 changes: 38 additions & 0 deletions types/lua-livr/LIVR.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--
-- https://luarocks.org/modules/fperrad/lua-livr
--

local record LIVR
type Data = {string:any}
type Error = string|table
type ValidatorFn = function(value: any, all: Data): any, Error
type Builder = function(builders: {string:Builder}, ...: any): ValidatorFn
type Rule = string|table

record Alias
name: string
rules: Rule
error: string
end

record Validator
prepare: function(self: Validator): Validator
validate: function(self: Validator, data: Data): Data, string|{string:Error}
register_rules: function(self: Validator, rules: {string:Builder}): Validator
register_aliased_rule: function(self: Validator, alias: Alias): Validator
get_rules: function(self: Validator): {string:Builder}
end

new: function(rules: {string:Rule}, is_auto_trim: boolean): Validator
register_default_rules: function(rules: {string:Builder})
register_aliased_default_rule: function(alias: Alias)

default_rules: {string:Builder}
default_auto_trim: boolean
_NAME: string
_VERSION: string
_DESCRIPTION: string
_COPYRIGHT: string
end

return LIVR
9 changes: 9 additions & 0 deletions types/lua-livr/LIVR/helpers.d.tl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

local record helpers
primitive_type: {string:boolean}
string_number_type: {string:boolean}
number_boolean_type: {string:boolean}
expected_type: function(rule: string, n: integer, tname: string, value: any)
end

return helpers

0 comments on commit 8c80344

Please sign in to comment.