Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
feature(listFilter): Added list filter
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianlee44 committed Sep 11, 2013
1 parent 8e33695 commit de7e220
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/filters/list.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###
@chalk overview
@name List
@description
List filter. Use for converting arrays into a string
@param {Array} list Array of items
@param {String} separator String to separate each element of the array (default ,)
@returns {String} Formatted string
###

angular.module("Mac").filter "list", [ ->
(list, separator = ", ") ->
list.join separator
]
24 changes: 24 additions & 0 deletions test/unit/filters.list.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe "List filter", ->
$rootScope = null
$compile = null
listFilter = null

beforeEach module("Mac")
beforeEach inject (_$rootScope_, _$compile_, _listFilter_) ->
$rootScope = _$rootScope_
$compile = _$compile_
listFilter = _listFilter_

it "should format an array into a string", ->
array = [1, 2, 3, 4]
expect(listFilter array).toBe "1, 2, 3, 4"

it "should format an array into a string with a custom separator", ->
array = [1, 2, 3, 4]
expect(listFilter array, " | ").toBe "1 | 2 | 3 | 4"

it "should interpolate correctly", ->
$rootScope.array = [1, 2, 3, 4]
element = $compile("<span>{{ array | list }}</span>") $rootScope
$rootScope.$digest()
expect(element.text()).toBe "1, 2, 3, 4"

0 comments on commit de7e220

Please sign in to comment.