Skip to main content

cljs.spec.alpha

&

  • &

    takes a regex op re, and predicates. Returns a regex-op that consumes input as per re but subjects the resulting value t...

*

+

  • +

    Returns a regex op that matches one or more values matching pred. Produces a vector of matches

?

  • ?

    Returns a regex op that matches zero or one value matching pred. Produces a single value (not a collection) if matched.

A

  • alt

    Takes key+pred pairs, e.g. (s/alt :even even? :small #(< % 42)) Returns a regex op that returns a map entry containing...

  • and

    Takes predicate/spec-forms, e.g. (s/and even? #(< % 42)) Returns a spec that returns the conformed value. Successive c...

  • assert

    spec-checking assert expression. Returns x if x is valid? according to spec, else throws an error with explain-data plus...

  • assert*

    Do not call this directly, use 'assert'.

C

  • cat

    Takes key+pred pairs, e.g. (s/cat :e even? :o odd?) Returns a regex op that matches (all) values in sequence, returnin...

  • check-asserts

    Enable or disable spec asserts that have been compiled with '*compile-asserts*' true. See 'assert'. Initially set to bo...

  • check-asserts?

    Returns the value set by check-asserts.

  • coll-of

    Returns a spec for a collection of items satisfying pred. Unlike generator will fill an empty init-coll. Same options a...

  • conform

    Given a spec and a value, returns :cljs.spec.alpha/invalid if value does not match spec, else the (possibly destructured...

  • conformer

    takes a predicate function with the semantics of conform i.e. it should return either a (possibly converted) value or :c...

D

  • def

    Given a namespace-qualified keyword or resolveable symbol k, and a spec, spec-name, predicate or regex-op makes an entry...

  • describe

    returns an abbreviated description of the spec as data

  • double-in

    Specs a 64-bit floating point number. Options: :infinite? - whether +/- infinity allowed (default true) :NaN? - ...

E

  • every

    takes a pred and validates collection elements against that pred. Note that 'every' does not do exhaustive checking, ra...

  • every-kv

    like 'every' but takes separate key and val preds and works on associative collections. Same options as 'every', :into ...

  • exercise

    generates a number (default 10) of values compatible with spec and maps conform over them, returning a sequence of [val ...

  • exercise-fn

    exercises the fn named by sym (a symbol) by applying it to n (default 10) generated samples of its args spec. When fspec...

  • explain

    Given a spec and a value that fails to conform, prints an explanation to *out*.

  • explain-data

    Given a spec and a value x which ought to conform, returns nil if x conforms, else a map with at least the key ::problem...

  • explain-out

    Prints explanation data (per 'explain-data') to *out* using the printer in *explain-out*, by default explain-printer.

  • explain-printer

    Default printer for explain-data. nil indicates a successful validation.

  • explain-str

    Given a spec and a value that fails to conform, returns an explanation as a string.

F

  • fdef

    Takes a symbol naming a function, and one or more of the following: :args A regex spec for the function arguments as th...

  • form

    returns the spec as data

  • fspec

    takes :args :ret and (optional) :fn kwargs whose values are preds and returns a spec whose conform/explain take a fn and...

G

  • gen

    Given a spec, returns the generator for it, or throws if none can be constructed. Optionally an overrides map can be pro...

  • get-spec

    Returns spec registered for keyword/symbol/var k, or nil.

I

  • inst-in

    Returns a spec that validates insts in the range from start (inclusive) to end (exclusive).

  • inst-in-range?

    Return true if inst at or after start and before end

  • int-in

    Returns a spec that validates fixed precision integers in the range from start (inclusive) to end (exclusive).

  • int-in-range?

    Return true if start <= val, val < end and val is a fixed precision integer.

  • invalid?

    tests the validity of a conform return value

K

  • keys

    Creates and returns a map validating spec. :req and :opt are both vectors of namespaced-qualified keywords. The validato...

  • keys*

    takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values, converts them into a ...

M

  • map-of

    Returns a spec for a map whose keys satisfy kpred and vals satisfy vpred. Unlike 'every-kv', map-of will exhaustively co...

  • merge

    Takes map-validating specs (e.g. 'keys' specs) and returns a spec that returns a conformed map satisfying all of the spe...

  • multi-spec

    Takes the name of a spec/predicate-returning multimethod and a tag-restoring keyword or fn (retag). Returns a spec that...

N

  • nilable

    returns a spec that accepts nil and values satisfiying pred

  • nonconforming

    takes a spec and returns a spec that has the same properties except 'conform' returns the original (not the conformed) v...

O

  • or

    Takes key+pred pairs, e.g. (s/or :even even? :small #(< % 42)) Returns a destructuring spec that returns a map entry c...

R

  • regex?

    returns x if x is a (cljs.spec.alpha) regex op, else logical false

  • registry

    returns the registry map, prefer 'get-spec' to lookup a spec by name

S

  • spec

    Takes a single predicate form, e.g. can be the name of a predicate, like even?, or a fn literal like #(< % 42). Note tha...

  • spec?

    returns x if x is a spec object, else logical false

T

  • tuple

    takes one or more preds and returns a spec for a tuple, a vector where each element conforms to the corresponding pred. ...

U

  • unform

    Given a spec and a value created by or compliant with a call to 'conform' with the same spec, returns a value with all c...

V

  • valid?

    Helper function that returns true when x is valid for spec.

W

  • with-gen

    Takes a spec and a no-arg, generator-returning fn and returns a version of that spec that uses that generator