https://github.com/druids/struct.validators
Additional validators for Struct library
https://github.com/druids/struct.validators
Last synced: 11 months ago
JSON representation
Additional validators for Struct library
- Host: GitHub
- URL: https://github.com/druids/struct.validators
- Owner: druids
- License: mit
- Created: 2018-05-25T08:11:30.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-19T07:21:03.000Z (over 7 years ago)
- Last Synced: 2025-06-30T23:36:34.269Z (about 1 year ago)
- Language: Clojure
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
struct.validators
=================
Additional validators for [Struct library](https://github.com/funcool/struct). It *DOES NOT* include Struct itself.
[](https://circleci.com/gh/druids/struct.validators)
[](https://jarkeeper.com/druids/struct.validators)
[](https://opensource.org/licenses/MIT)
Leiningen/Boot
--------------
```clojure
[struct.validators "0.9.0"]
```
Documentation
-------------
This library adds following validators:
- `non-blank`: forces a non-nil value not to be blank (spaces aren't allowed)
- `non-blank-like`: coerces a non-nil value to `nil` if the value is an empty string or contains only white spaces
coerces the value to `nil`, otherwise makes no changes
- `keyword-like`: coerces a non-blank value to a `keyword`
- `truth`: validates if a given value is `true`
- `enum-factory`: creates a validator that validates if a value is in a given coll (it should be a set for perf.)
- `every-factory`: creates a validator that validates if all items in a sequence satisfy a given scheme, allow
to pass an option map for `validate` function (`{:strip true}` is used as default)
- `bigdec-str`: coerces a non-blank value to a `bigdec` (Clojure only)
- `uuid-str-like`: works like the original `uuid-str`, but accepts also future version of UUID
- `cz-phone`: validates a given value if it's a valid phone number, if so it formats the value into `E164`
(+420777666555), if the value is without prefix, `+420` will be used as default (Clojure only)
Validators for other countries can be defined via `phone-factory` function e.g.:
```clojure
(require '[structs.api :as st])
(def de-phone (st/phone-factory "DE"))
```
Consider using namespace `struct.api` that combines all public functions and validators from `struct.core`
and `struct.validators` at one place. Example:
```clojure
(require '[struct.api :as st])
(st/validate {:name "foo"} {:name [st/required st/non-blank]})
[nil {:name "foo"}]
```