Liking cljdoc? Tell your friends :D

Specs and checks

Predicates

The phone-number provides many predicate functions that can be used to check for certain properties of phone numbers. These include:

Function NameDescription
core/valid-input?Checks if a value can possibly be used as a phone number
core/valid?Checks if a phone numer is valid
core/invalid?Checks if a phone numer is invalid
core/possible?Checks if a phone numer is a possible number
core/impossible?Checks if a phone numer is an impossible number
core/native?Checks if a phone numer is in a native format (PhoneNumber)
core/has-raw-input?Checks if a phone numer contains the retained raw input
core/geographical?Checks if a phone numer identifies a line with some geographical location
core/short-possible?Checks if a phone numer is in a possible short number
core/short-valid?Checks if a phone numer is in a valid short number
core/short-emergency?Checks if a phone numer is in an emergency number
core/short-to-emergency?Checks if a phone numer can be used to connect to an emergency
core/short-to-emergency?Checks if a phone numer can be used to connect to an emergency

Specs

Clojure Spec is used in the phone-number library to validate data and generate property-based tests. Most of the defined specs have generators attached.

There are 3 groups of specs:

  • Input specs, created for easy data validation.
    (ns-prefix: phone-number.input)

  • Generic specs used to describe the output data.
    (ns-prefix: phone-number)

  • Specs that are used internally to test the library for corner cases and make sure that new features or other changes won't break anything.
    (ns-prefixes: phone-number.arg, phone-number.args, phone-number.props)

This page lists the input and some of the generic specs. To use them just require phone-number.spec, clojure.spec.alpha and optionally clojure.spec.gen.alpha:

(require [phone-number.spec       :as spec]
         [clojure.spec.alpha      :as    s]
         [clojure.spec.gen.alpha  :as  gen])
Spec NameData description
:phone-number.input/regionregion code
:phone-number.input/typephone number type
:phone-number.input/leniencyphone number leniency
:phone-number.input/formatphone number format
:phone-number.input/format-globalphone number format
(with calling code prefix)
:phone-number.input/format-regionalphone number format
(without calling code prefix)
:phone-number.input/tz-formattime zone format
:phone-number.input/net-codeglobal network calling code
:phone-number.input/country-codecountry calling code
:phone-number.input/calling-codecalling code (either global or country)
:phone-number.input/costcost class of short numbers
:phone-number.input/nativephone number in native format
(PhoneNumber object)
:phone-number.input/native-validnative phone number which is valid
:phone-number.input/stringphone number as a string
:phone-number.input/string-globalphone number as a string with a calling code
:phone-number.input/string-regionalphone number as a string without a calling code
:phone-number.input/string-validvalid phone number as a string
:phone-number.input/string-invalidinvalid phone number as a string
:phone-number.input/numericphone number as natural number without calling code
:phone-number/infophone number as a map
:phone-number/info-validvalid phone number as a map
:phone-number/info-invalidinvalid phone number as a map
:phone-number.input/possiblepossible phone number
:phone-number.input/impossibleimpossible phone number
:phone-number.input/unknownphone number of unknown type
:phone-number.input/has-regionphone number with region code information
:phone-number.input/has-calling-codephone number with calling code
:phone-number.input/has-locationphone number having geographical location
:phone-number.input/has-time-zonephone number having time zone information
:phone-number.input/has-known-typephone number of known type
:phone-number.input/mobilemobile phone number
:phone-number.input/fixed-linefixed-line phone number
:phone-number.input/toll-freetoll-free phone number
:phone-number.input/premium-ratepremium-rate phone number
:phone-number.input/shared-costshared-cost phone number
:phone-number.input/voipVoIP phone number
:phone-number.input/personalpersonal phone number
:phone-number.input/pagerpager number
:phone-number.input/uanUAN number
:phone-number.input/voicemailvoicemail number
:phone-number.input/fixed-line-or-mobilefixed-line or mobile number (incl. uncertain)
:phone-number.input/uncertain-fixed-line-or-mobileuncertain number (fixed line or mobile)
:phone-number.input/maybe-mobileuncertain number (fixed line or mobile) or mobile
:phone-number.input/maybe-fixed-lineuncertain number (fixed line or mobile) or fixed-line
:phone-number.input/shortvalid short number
:phone-number.input/maybe-shortpossible short number
:phone-number.input.short/validvalid short number
:phone-number.input.short/invalidinvalid short number
:phone-number.input.short/possiblepossible short number
:phone-number.input.short/carrier-specificcarrier-specific short number
:phone-number.input.short/infoshort number properties as a map
:phone-number.input/numberphone number (with calling code or without)

Phone-number also contains specs for functions, however they are intended for testing and it is NOT RECOMMENDED to enable the instrumentation in production.

Please note that if you intend to use phone-number's specs in a program (not in phone-number's REPL) you should add proper dependencies since production profile of phone-number does not depend on spec nor test library. Example, minimal deps.edn:

{:paths ["src" "resources"]

 :deps {io.randomseed/phone-number {:mvn/version "8.12.16-1"}}

 :aliases {
           :dev {
                 :extra-deps {org.clojure/spec.alpha  {:mvn/version "0.2.194"}
                              org.clojure/test.check  {:mvn/version "1.1.0"}}
                 :extra-paths ["dev/src" "test"]
                 :jvm-opts ["-Dclojure.spec.compile-asserts=true"]}

           :test {
                  :extra-paths ["test"]
                  :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}}

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close