{"id":25453535,"url":"https://github.com/xcessentials/xcevalidatablevalue","last_synced_at":"2026-05-29T12:01:43.050Z","repository":{"id":62457271,"uuid":"75524333","full_name":"XCEssentials/XCEValidatableValue","owner":"XCEssentials","description":"Generic value wrapper with built-in validation.","archived":false,"fork":false,"pushed_at":"2025-01-19T02:50:25.000Z","size":633,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-27T20:47:37.806Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/XCEssentials.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-04T07:47:27.000Z","updated_at":"2025-01-19T02:50:28.000Z","dependencies_parsed_at":"2025-01-19T03:26:02.270Z","dependency_job_id":"b2312f02-f1d9-49b0-a7d6-9058fef74c2d","html_url":"https://github.com/XCEssentials/XCEValidatableValue","commit_stats":{"total_commits":371,"total_committers":1,"mean_commits":371.0,"dds":0.0,"last_synced_commit":"453fab67ad4541d85fe9cf70a787b19e4003c3d3"},"previous_names":["xcessentials/xcevalidatablevalue","xcessentials/validatablevalue"],"tags_count":59,"template":false,"template_full_name":null,"purl":"pkg:github/XCEssentials/XCEValidatableValue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XCEssentials%2FXCEValidatableValue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XCEssentials%2FXCEValidatableValue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XCEssentials%2FXCEValidatableValue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XCEssentials%2FXCEValidatableValue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/XCEssentials","download_url":"https://codeload.github.com/XCEssentials/XCEValidatableValue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/XCEssentials%2FXCEValidatableValue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33650712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-17T23:55:56.685Z","updated_at":"2026-05-29T12:01:43.032Z","avatar_url":"https://github.com/XCEssentials.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub License](https://img.shields.io/github/license/XCEssentials/ValidatableValue.svg?longCache=true)](LICENSE)\n[![GitHub Tag](https://img.shields.io/github/tag/XCEssentials/ValidatableValue.svg?longCache=true)](https://github.com/XCEssentials/ValidatableValue/tags)\n[![Swift Package Manager Compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg?longCache=true)](Package.swift)\n[![Written in Swift](https://img.shields.io/badge/Swift-5.3-orange.svg?longCache=true)](https://swift.org)\n[![Supported platforms](https://img.shields.io/badge/platforms-macOS%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-blue.svg?longCache=true)](Package.swift)\n[![Build Status](https://travis-ci.com/XCEssentials/ValidatableValue.svg?branch=master)](https://travis-ci.com/XCEssentials/ValidatableValue)\n\n# ValidatableValue\n\nGeneric value wrapper with built-in declarative validation.\n\n## Problem\n\nEvery app has [data model](https://en.wikipedia.org/wiki/Data_model). A data model is usually implemented as a custom structured [data type](https://en.wikipedia.org/wiki/Data_type) that stores one or more [properties](https://en.wikipedia.org/wiki/Property_(programming)). Ideally, the type of each property (no matter if it's of primitive or structured type) defines desired set of all possible values for this property. Plus, there are might be special rules that may define whatever any given value is acceptable for the property or not.\n\nSwift has no built-in mechanism of how to narrow-down set of allowed values within one of the standard data types and/or evaluate any special rules against each given value to check if it's acceptable for the property or not.\n\nFor example, to limit a vlaue to just integer numbers in the range from 1 to 100 and avoid all odd numbers within this range we usually use just Integer, and then somehow later implement the needed checks before actually put a value in this property. That leads to distribution of single portion of business logic (requirements for this particualr property) across at least two (sometimes more) places in the codebase.\n\n## Wishlist\n\n1. concise declarative definition of value validation logic;\n2. safe value validation before actually writing it into property;\n3. ability to combine several requirements together to describe complex validation rules;\n4. eliminate any side effects by making validation logic to be written as pure function on type level.\n\n## How to install\n\nThe recommended way is to install using [SwiftPM](https://swift.org/package-manager/), but [Carthage](https://github.com/Carthage/Carthage) is also supported out of the box..\n\n## Quick example\n\nTo describe custom validation rules for user account password let's define so called `ValueSpecification`. Such specification defines value base type (any pre-defined data type) plus set of requirements that need to be fulfilled in order to pass validation.\n\n```swift\nenum Password: ValueSpecification\n{\n    static\n    let conditions: [Condition\u003cString\u003e] = [\n\n        Check(\"Lenght between 8 and 30 characters\"){ 8...30 ~= $0.count },\n        Check(\"Has at least 1 capital character\"){ 1 \u003c= Pwd.caps.count(in: $0) },\n        Check(\"Has at least 4 lower characters\"){ 4 \u003c= Pwd.lows.count(in: $0) },\n        Check(\"Has at least 1 digit character\"){ 1 \u003c= Pwd.digits.count(in: $0) },\n        Check(\"Has at least 1 special character\"){ 1 \u003c= Pwd.specials.count(in: $0) },\n        Check(\"Allowed chars only\"){ Pwd.allowed.isSuperset(of: CS(charactersIn: $0)) }\n    ]\n}\n```\n\nNote, that `Password` is declared as enum, because we only need it as a scope, it won't be instantiated directly — its name defines name of the specification and also inside we specify `conditions` (a.k.a. requirements) that must be fulfilled in oreder to pass validation.\n\nIn the example above we use simple custom helpers defined like this:\n\n```swift\nenum Pwd\n{\n    static\n    let caps = CS.uppercaseLetters\n\n    static\n    let lows = CS.lowercaseLetters\n\n    static\n    let digits = CS.decimalDigits\n\n    static\n    let specials = CS(charactersIn: \" ,.!?@#$%^\u0026*()-_+=\")\n\n    static\n    var allowed = caps.union(lows).union(digits).union(specials)\n}\n```\n\n## How to use\n\nSee [User.swift](User.swift) in [unit tests](https://github.com/XCEssentials/ValidatableValue/tree/master/Tests/AllTests) for comprehensive up-to-date example of usage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcessentials%2Fxcevalidatablevalue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxcessentials%2Fxcevalidatablevalue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcessentials%2Fxcevalidatablevalue/lists"}