Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-validator

Typed fluent validation rules for Pudu

0.1.1Apache-2.01

InstallClose

Presence.pudu

Pudu29 lines1.2 KB

GitHub ↗
1/** @Validation.Rules.Presence.Module — checks explicit optional values */2module PuduLangValidator.Rules.Presence34import PuduLangValidator.Rule as Rule56/// Require an optional property to contain a value.7export fn notNull[T, V](builder: Rule.RuleBuilder[T, Option[V]]) -> Rule.RuleBuilder[T, Option[V]] {8  Rule.withCode(Rule.withMessage(Rule.must(builder, |value: Option[V]| match value {9          case Some(_) => true10          case None => false11        }), "A value is required."), "NotNull")12}1314/// Require an optional property to be absent.15export fn isNull[T, V](builder: Rule.RuleBuilder[T, Option[V]]) -> Rule.RuleBuilder[T, Option[V]] {16  Rule.withCode(Rule.withMessage(Rule.must(builder, |value: Option[V]| match value {17          case Some(_) => false18          case None => true19        }), "A value must be absent."), "Null")20}2122/// Reject absent, empty, and whitespace-only optional text.23export fn notEmpty[T](builder: Rule.RuleBuilder[T, Option[Str]]) -> Rule.RuleBuilder[T, Option[Str]] {24  Rule.withCode(Rule.withMessage(Rule.must(builder, |value: Option[Str]| match value {25          case Some(text) => !text.trim().isEmpty()26          case None => false27        }), "Text is required."), "NotEmpty")28}29