Skip to content

Commit

Permalink
Merge pull request #13 from fkammer/add-iban-filter
Browse files Browse the repository at this point in the history
Add angular filter to display IBANs in a human-friendly format
  • Loading branch information
mmjmanders authored Jun 10, 2016
2 parents d8e4196 + d31b924 commit f12444d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ Add `mm.iban` as a dependency of your AngularJS module.
----

To use this directive the `ngModel` directive must also be used because this directive depends on it.

=== filter
[source,html]
----
IBAN: {{ string | iban:separator }}
----

The filter converts a given IBAN to it's human-friendly represantation. The separator defaults to a single space.
15 changes: 15 additions & 0 deletions src/ng-iban.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ angular
else modelValue

return

.filter 'iban', ->
(string, separator) ->
parseIban = (value) ->
if value? then value.toUpperCase().replace /\s/g, '' else undefined

isValidIban = (value) ->
iban = parseIban(value)
IBAN.isValid iban

valid = isValidIban string
if valid
IBAN.printFormat string, separator
else
string
File renamed without changes.
22 changes: 22 additions & 0 deletions test/spec/ng-iban-filter.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

describe 'Filter: iban', ->

# load the filter's module
beforeEach module 'mm.iban'

filter = undefined

beforeEach inject ($filter) ->
filter = $filter 'iban'

it 'electronic IBAN should become print IBAN', ->
expect(filter('NL91ABNA0417164300')).toEqual 'NL91 ABNA 0417 1643 00'

it 'invalid IBAN should stay untouched', ->
expect(filter('INVALIDIBAN')).toEqual 'INVALIDIBAN'
expect(filter('NL90ABNA0417164300')).toEqual 'NL90ABNA0417164300'

it 'mind custom separator', ->
expect(filter('NL91ABNA0417164300', '-')).toEqual 'NL91-ABNA-0417-1643-00'
expect(filter('NL91ABNA0417164300', '')).toEqual 'NL91ABNA0417164300'

0 comments on commit f12444d

Please sign in to comment.