Skip to content

Commit

Permalink
trim and empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kemsky committed Feb 15, 2016
1 parent 13cbee7 commit 7e5d7ba
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
19 changes: 19 additions & 0 deletions source/com/kemsky/filters/empty.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright: (c) 2016. Turtsevich Alexander
*
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.html
*/

package com.kemsky.filters
{
import com.kemsky.support.toValue;

public function empty(val:*):Function
{
return function (item:*):Boolean
{
var value:* = toValue(item, val);
return (value as String) == null || (value as String).length == 0;
};
}
}
25 changes: 25 additions & 0 deletions source/com/kemsky/filters/trim.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright: (c) 2016. Turtsevich Alexander
*
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.html
*/

package com.kemsky.filters
{
import com.kemsky.support.toValue;

import mx.utils.StringUtil;

public function trim(val:*):Function
{
return function (item:*):String
{
var value:* = toValue(item, val);
if(value is String)
{
return StringUtil.trim(value);
}
return "";
};
}
}
21 changes: 21 additions & 0 deletions testSrc/com/kemsky/filters/TestFilters.as
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ package com.kemsky.filters
{
}

[Test]
public function testTrim():void
{
var s:Stream = $("", null, " ", "test ");
var e:Stream = s.map(trim(_));
assertEquals(e.length, 4);
assertEquals(e.first, "");
assertEquals(e.second, "");
assertEquals(e.third, "");
assertEquals(e.fourth, "test");
}

[Test]
public function testEmpty():void
{
var s:Stream = $("", null, "", "test");
var e:Stream = s.filter(not(empty(_)));
assertEquals(e.length, 1);
assertEquals(e.first, "test");
}

[Test]
public function testInvoke():void
{
Expand Down

0 comments on commit 7e5d7ba

Please sign in to comment.