Liking cljdoc? Tell your friends :D

stdnum.core

Validate, parse, and format standard identifier numbers.

This API supports credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing (ABA), IMEI, and the raw Luhn check. A type keyword selects the identifier type. The API uses Clojure data. It is a facade over Apache Commons Validator and iban4j. It does not reimplement their algorithms.

(valid?  :iban "GB82 WEST 1234 5698 7654 32")  ;=> true
(parse   :credit-card "4111111111111111")      ;=> {:valid? true :network :visa}
(format  :iban "GB82WEST12345698765432")       ;=> "GB82 WEST 1234 5698 7654 32"
(detect  "4111111111111111")                   ;=> [:credit-card :luhn]

valid?, parse, and format throw only for an unknown identifier type. Bad input data does not throw. valid? returns false, parse returns {:valid? false}, and format returns nil.

Validate, parse, and format standard identifier numbers.

This API supports credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing
(ABA), IMEI, and the raw Luhn check. A type keyword selects the identifier
type. The API uses Clojure data. It is a facade over Apache Commons Validator
and iban4j. It does not reimplement their algorithms.

    (valid?  :iban "GB82 WEST 1234 5698 7654 32")  ;=> true
    (parse   :credit-card "4111111111111111")      ;=> {:valid? true :network :visa}
    (format  :iban "GB82WEST12345698765432")       ;=> "GB82 WEST 1234 5698 7654 32"
    (detect  "4111111111111111")                   ;=> [:credit-card :luhn]

`valid?`, `parse`, and `format` throw only for an unknown identifier type.
Bad input data does not throw. `valid?` returns false, `parse` returns
{:valid? false}, and `format` returns nil.
raw docstring

card-networkclj

(card-network s)

The card network of s (:visa :mastercard :amex :discover :diners), or nil if s is not a recognized card number.

The card network of `s` (`:visa` `:mastercard` `:amex` `:discover` `:diners`),
or nil if `s` is not a recognized card number.
sourceraw docstring

compactclj

(compact s)

Return s without spaces, hyphens, and dots, in upper case. This is the canonical compact form for every identifier type.

Return `s` without spaces, hyphens, and dots, in upper case. This is the
canonical compact form for every identifier type.
sourceraw docstring

describeclj

(describe type)

Metadata for type as a map: {:type :de-vat :category :vat :country :de :example "136695976" :source "..."}

Metadata for `type` as a map:
{:type :de-vat :category :vat :country :de :example "136695976" :source "..."}
sourceraw docstring

detectclj

(detect s)
(detect s {:keys [country category]})

Return a vector of identifier types that consider s valid. A card number, for example, can also be Luhn-valid. Return an empty vector if no type matches. Optional :country and :category filters constrain the candidate types. :country is an ISO prefix. :category is :banking, :securities, :publishing, :commerce, :research, :national, or :vat.

Return a vector of identifier types that consider `s` valid. A card number,
for example, can also be Luhn-valid. Return an empty vector if no type matches.
Optional `:country` and `:category` filters constrain the candidate types.
`:country` is an ISO prefix. `:category` is :banking, :securities,
:publishing, :commerce, :research, :national, or :vat.
sourceraw docstring

exampleclj

(example type)

Return a known-valid identifier of type as a string. This is the first cited vector from the verification corpus. A known type never returns nil.

Return a known-valid identifier of `type` as a string. This is the first
cited vector from the verification corpus. A known type never returns nil.
sourceraw docstring

examplesclj

(examples type)

All known-valid example identifiers of type, as a vector of strings.

All known-valid example identifiers of `type`, as a vector of strings.
sourceraw docstring

formatclj

(format type s)

Return the canonical form of s as type. For example, it groups an IBAN and a card number in fours and hyphenates an ISSN. Return nil if s is not valid. An unknown type throws.

Return the canonical form of `s` as `type`. For example, it groups an IBAN
and a card number in fours and hyphenates an ISSN. Return nil if `s` is not
valid. An unknown `type` throws.
sourceraw docstring

parseclj

(parse type s)

Validate s as type and return a map. A valid value returns at least {:valid? true}. It can also return type-specific fields, such as card :network or IBAN :country, :bban, and :formatted. Bad data returns {:valid? false}. An unknown type throws.

Validate `s` as `type` and return a map. A valid value returns at least
`{:valid? true}`. It can also return type-specific fields, such as card
`:network` or IBAN `:country`, `:bban`, and `:formatted`. Bad data returns
`{:valid? false}`. An unknown `type` throws.
sourceraw docstring

type-categoryclj

(type-category type)

Return the category of type: :banking, :securities, :publishing, :commerce, :research, :vat, or :national. A known type never returns nil.

Return the category of `type`: :banking, :securities, :publishing, :commerce,
:research, :vat, or :national. A known type never returns nil.
sourceraw docstring

type-countryclj

(type-country type)

Return the country of a type as a lower-case ISO 3166-1 alpha-2 keyword. For example, :de is the country of :de-vat. International types, such as :iban and :credit-card, return nil. :eu is the exceptionally reserved EU code.

Return the country of a type as a lower-case ISO 3166-1 alpha-2 keyword.
For example, :de is the country of :de-vat. International types, such as
:iban and :credit-card, return nil. :eu is the exceptionally reserved EU code.
sourceraw docstring

typesclj

The set of identifier-type keywords this library understands.

The set of identifier-type keywords this library understands.
sourceraw docstring

valid?clj

(valid? type s)

True if s is a valid identifier of type. Bad data returns false. An unknown type throws IllegalArgumentException.

True if `s` is a valid identifier of `type`. Bad data returns false. An
unknown `type` throws IllegalArgumentException.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close