A minimalist data driven data model library, inspired by Clojure Spec and Malli.
(ns your-namespace
(:require [minimallist.core :refer [valid? describe]]
[minimallist.helper :as h]))
(def hiccup-model
(h/let ['hiccup (h/alt [:node (h/in-vector (h/cat [:name (h/fn keyword?)]
[:props (h/? (h/map-of (h/vector (h/fn keyword?) (h/fn any?))))]
[:children (h/* (h/not-inlined (h/ref 'hiccup)))]))]
[:primitive (h/alt [:nil (h/fn nil?)]
[:boolean (h/fn boolean?)]
[:number (h/fn number?)]
[:text (h/fn string?)])])]
(h/ref 'hiccup)))
(valid? hiccup-model [:div {:class [:foo :bar]}
[:p "Hello, world of data"]])
;=> true
(describe hiccup-model [:div {:class [:foo :bar]}
[:p "Hello, world of data"]])
;=> [:node {:name :div
; :props [[[:class [:foo :bar]]]]
; :children [[:node {:name :p
; :props []
; :children [[:primitive [:text "Hello, world of data"]]]}]]}]
- validates, parses and generates data,
- fully data driven, models are hash-map based created via helpers,
- support recursive definitions and sequence regex,
- no macro, no static registry, pure functions,
- relatively simple implementation, easy to read and modify,
- cross platform (
.cljc
), valid?
anddescribe
run in Babashka
- does not integrate with anything else,
- does not try hard to be performant
See the latest documentation on cljdoc for:
- A general description of the Minimallist project.
- How to use the helpers to build your models.
- How to validate, parse and generate your data.
This is a work in progress, the API may change in the future.
More functionalities will be added later, once the API design is more stable.
If you find any bug or have comments, please create an issue in GitHub.
The Minimallist library is developed by Vincent Cantin. It is distributed under the terms of the Eclipse Public License version 2.0.