This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(listFilter): Added list filter
- Loading branch information
1 parent
8e33695
commit de7e220
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |