Skip to content

Commit ea8ea4a

Browse files
committedJun 8, 2014
Add simple filter for trimming strings.
1 parent 48eead9 commit ea8ea4a

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎demo.html

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ <h3>last</h3>
7070
<h3>random</h3>
7171
{{ colors | random }}
7272

73+
<h3>trim</h3>
74+
{{' I was a string with leading and trailing whitespace ' | trim}}
75+
7376
</template>
7477
<script>
7578
var template = document.getElementById('view');

‎filter-trim.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Trim a string, removing leading and trailing whitespace
3+
* @param {string} input
4+
* @return {string} trimmed string
5+
*/
6+
PolymerExpressions.prototype.trim = function(input){
7+
return input.replace(/^\s*|\s*$/g, '');
8+
}

‎polymer-filters.html

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<script src="filter-wordcount.js"></script>
1212
<script src="filter-random.js"></script>
1313
<script src="filter-round.js"></script>
14+
<script src="filter-trim.js"></script>
1415

1516
<!--
1617
A collection of filters for formatting values of [Polymer expressions](www.polymer-project.org/docs/polymer/expressions.html) for display to users.
@@ -41,6 +42,12 @@
4142
4243
> Hello Peeps
4344
45+
####Trim
46+
47+
{{' I was a string with leading and trailing whitespace ' | trim}}
48+
49+
> I was a string with leading and trailing whitespace
50+
4451
####Date
4552
4653
{{1288323623006 | date('yyyy-MM-dd HH:mm:ss Z')}}

0 commit comments

Comments
 (0)
Please sign in to comment.