Skip to content

Commit d61369e

Browse files
Marcos PlaconaMarcos Placona
Marcos Placona
authored and
Marcos Placona
committed
Add left and right only trimming capabilities
1 parent 6d732da commit d61369e

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

demo.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ <h3>random</h3>
8888

8989
<h3>length</h3>
9090
{{'Hello World' | length}}
91+
92+
<h3>ltrim</h3>
93+
{{' I was a string with leading whitespace' | ltrim}}
94+
95+
<h3>rtrim</h3>
96+
{{'I was a string with trailing whitespace ' | rtrim}}
9197

9298
<h3>trim</h3>
93-
{{' I was a string with leading and trailing whitespace ' | trim}}
99+
{{' I was a string with leading and trailing whitespace ' | trim}}
94100

95101
<h3>list</h3>
96102
{{colors | list}}

filter-ltrim.js

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

filter-rtrim.js

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

polymer-filters.html

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<script src="filter-round.js"></script>
1414
<script src="filter-truncate.js"></script>
1515
<script src="filter-titlecase.js"></script>
16+
<script src="filter-ltrim.js"></script>
17+
<script src="filter-rtrim.js"></script>
1618
<script src="filter-trim.js"></script>
1719
<script src="filter-length.js"></script>
1820
<script src="filter-list.js"></script>
@@ -47,6 +49,18 @@
4749
4850
> Hello Peeps
4951
52+
####LTrim
53+
54+
{{' I was a string with leading whitespace' | ltrim}}
55+
56+
> I was a string with leading whitespace
57+
58+
####RTrim
59+
60+
{{'I was a string with trailing whitespace ' | rtrim}}
61+
62+
> I was a string with trailing whitespace
63+
5064
####Trim
5165
5266
{{' I was a string with leading and trailing whitespace ' | trim}}

0 commit comments

Comments
 (0)