layflags/elm-bic/1.0.0

NOTE: the latest version is 2.0.0

BIC

This library is for parsing Business Identifier Codes (BIC) used e.g. in banking. The implementation is based on ISO 9362 Fourth edition 2014-12-01.

Definition

type BIC

Represents a Business Identifier Code (BIC) as an opaque type.

type alias PartyPrefix =
String

Business party prefix (4 alpha-numeric).

type alias CountryCode =
CountryCode

CountryCode (ISO 3166). Just an alias to Iso3166.CountryCode from rl-king/elm-iso3166-country-codes

type alias PartySuffix =
String

Business party suffix (2 alpha-numeric).

type alias BranchId =
String

Branch identifier (3 alpha-numeric).

The branch code is optional ("XXX" for primary office). Where an eight digit BIC code is given, it may be assumed that it refers to the primary office.

Parsing

fromString : String -> Result Error BIC

Try to parse a String into a BIC. Spaces in that String will be removed and all letters will be upcased.

fromString "FDDO DE MM" -- Ok (BIC "FDDO" Iso3166.DE "MM" Nothing)


fromString "FDDO DE MM XXX" -- Ok (BIC "FDDO" Iso3166.DE "MM" Nothing)


fromString "axisinbb002" -- Ok (BIC "AXIS" Iso3166.IN "BB" (Just "002"))
type Error
= LengthError
| NotAlphaNumeric
| UnknownCountryCode

Parser errors potentially returned by fromString.

fromString "FDDO" -- Err LengthError


fromString "FDDODEMMXXX Q" -- Err LengthError


fromString "FD @! DEMMXXX" -- Err NotAlphaNumeric


fromString "FDDO QQ MMXXX" -- Err UnknownCountryCode

Common helpers

toString : BIC -> String

Convert BIC to an either 8 or 11 character String, depending on the availability of the branch code.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toString bic -- "FDDODEMM"


-- bic == BIC "AXIS" Iso3166.IN "BB" (Just "002")
toString bic -- "AXISINBB002"
toString11 : BIC -> String

Convert BIC to an 11 character String, where the branch code will be set to "XXX" if it doesn't exist.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toString11 bic -- "FDDODEMMXXX"


-- bic == BIC "AXIS" Iso3166.IN "BB" (Just "002")
toString11 bic -- "AXISINBB002"
toPartyPrefix : BIC -> PartyPrefix

Extract business party prefix from BIC.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toPartyPrefix bic -- "FDDO"
toCountyCode : BIC -> CountryCode

Extract country code from BIC.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toCountyCode bic -- Iso3166.DE
toPartySuffix : BIC -> PartySuffix

Extract business party suffix code from BIC.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toPartySuffix bic -- "MM"
toBranchId : BIC -> BranchId

Extract branch code from BIC, using "XXX" if not available.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toBranchId bic -- "XXX"


-- bic == BIC "AXIS" Iso3166.IN "BB" (Just "002")
toBranchId bic -- "002"
toOptionalBranchId : BIC -> Maybe BranchId

Extract branch code from BIC if available.

-- bic == BIC "FDDO" Iso3166.DE "MM" Nothing
toOptionalBranchId bic -- Nothing


-- bic == BIC "AXIS" Iso3166.IN "BB" (Just "002")
toOptionalBranchId bic -- Just "002"