GS1.Validator.Constraint (gs1_barcode v0.1.2)
View SourceA DSL for building reusable GS1 AI validation constraint predicates, that are intended to be lightweight and composable.
Examples
import GS1.Validator.Constraint
constraint = all([is_num(), len(14)])
constraint.("12345678901234") # => true
constraint.("ABC") # => false
Summary
Types
Validation predicate function that tests a string value against a constraint.
Functions
Returns true only if all predicates in the list return true.
Acts as a logical AND.
Returns true if at least one predicate in the list returns true.
Acts as a logical OR.
Checks if value is an integer string within the range [min, max] (inclusive).
Generates a validator for a specific pre-defined GS1 data format.
Checks if the value consists entirely of digits.
Checks if the string value has an exact length of n.
Checks if the value matches the given Regex.
Checks if string value has a length less than or equal to n.
Checks if string value has a length greater than or equal to n.
Inverts the result of a predicate.
Types
Functions
Returns true only if all predicates in the list return true.
Acts as a logical AND.
Usage
all([is_num(), len(5)])
Returns true if at least one predicate in the list returns true.
Acts as a logical OR.
Usage
any([len(5), len(8)])
@spec between(pos_integer(), pos_integer()) :: Macro.t()
Checks if value is an integer string within the range [min, max] (inclusive).
Generates a validator for a specific pre-defined GS1 data format.
Supported Formats
:date_yymmdd- validatesYYMMDDdate format and represents a valid calendar date.:date_yymmd0- validatesYYMMD0format.
Usage
format(:date_yymmdd)
@spec is_num() :: Macro.t()
Checks if the value consists entirely of digits.
@spec len(pos_integer()) :: Macro.t()
Checks if the string value has an exact length of n.
Checks if the value matches the given Regex.
@spec max_len(pos_integer()) :: Macro.t()
Checks if string value has a length less than or equal to n.
@spec min_len(pos_integer()) :: Macro.t()
Checks if string value has a length greater than or equal to n.
Inverts the result of a predicate.