green-coder / minimallist

A minimalist data driven data model library, inspired by Clojure Spec and Malli.
Eclipse Public License 2.0
66 stars 1 forks source link
clojure clojurescript data-parsing data-validation

Minimallist CircleCI

A minimalist data driven data model library, inspired by Clojure Spec and Malli.

Clojars Project cljdoc badge project chat cljdoc badge

Usage

(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"]]]}]]}]

Features

Non-goals (for now)

Documentation

See the latest documentation on cljdoc for:

Status

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.

License

The Minimallist library is developed by Vincent Cantin. It is distributed under the terms of the Eclipse Public License version 2.0.