Unified validation, parsing, and formatting of standard identifier numbers.
One API over several identifier types - credit cards, IBAN/BIC, ISBN, ISSN, ISIN, US bank routing (ABA), IMEI, and the raw Luhn check - dispatched on a type keyword. Idiomatic Clojure data in and out; an idiomatic facade over the maintained Apache Commons Validator and iban4j engines (it does not reinvent the 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/format throw only on an unknown identifier type (a caller
bug); bad input data never throws - valid? returns false, parse returns
{:valid? false}, format returns nil.
Unified validation, parsing, and formatting of standard identifier numbers.
One API over several identifier types - credit cards, IBAN/BIC, ISBN, ISSN,
ISIN, US bank routing (ABA), IMEI, and the raw Luhn check - dispatched on a
type keyword. Idiomatic Clojure data in and out; an idiomatic facade over the
maintained Apache Commons Validator and iban4j engines (it does not reinvent
the 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`/`format` throw only on an unknown identifier type (a caller
bug); bad input data never throws - `valid?` returns false, `parse` returns
{:valid? false}, `format` returns nil.(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.
(compact s)Return s stripped of spaces, hyphens, and dots and upper-cased - the
canonical compact form shared by every identifier type.
Return `s` stripped of spaces, hyphens, and dots and upper-cased - the canonical compact form shared by every identifier type.
(detect s)Return a vector of the identifier types that consider s valid (possibly
several, e.g. a card number is also Luhn-valid). Empty when nothing matches.
Return a vector of the identifier types that consider `s` valid (possibly several, e.g. a card number is also Luhn-valid). Empty when nothing matches.
(format type s)Canonical human-readable form of s as type (e.g. IBAN grouped in fours,
ISSN hyphenated, card grouped in fours), or nil if s is not valid. Unknown
type throws.
Canonical human-readable form of `s` as `type` (e.g. IBAN grouped in fours, ISSN hyphenated, card grouped in fours), or nil if `s` is not valid. Unknown `type` throws.
(parse type s)Validate s as type and return a map. On success: at least {:valid? true},
plus type-specific fields (e.g. card :network; IBAN :country/:bban/
:formatted). On bad data: {:valid? false}. Unknown type throws.
Validate `s` as `type` and return a map. On success: at least `{:valid? true}`,
plus type-specific fields (e.g. card `:network`; IBAN `:country`/`:bban`/
`:formatted`). On bad data: `{:valid? false}`. Unknown `type` throws.The set of identifier-type keywords this library understands.
The set of identifier-type keywords this library understands.
(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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |