Skip to content

Commit af446dd

Browse files
committed
Adds titlecase filter.
1 parent efe6ffe commit af446dd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

demo.html

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ <h3>replace('World','Peeps')</h3>
2727
<h3>truncate(8, true)</h3>
2828
{{'Lorem Catsum Itsum' | truncate(8, true) }}
2929

30+
<h3>titlecase</h3>
31+
{{'this is a sentence that was not using title case.' | titlecase}}
32+
3033
<h3>startsWith(T)</h3>
3134
<template repeat="{{friend in friends | startsWith('T')}}">
3235
{{ friend.name }}

filter-titlecase.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Return a title-cased version of the input
3+
* @param {string} input
4+
* @return {string}
5+
*/
6+
PolymerExpressions.prototype.titlecase = function (input) {
7+
var words = input.split(' ');
8+
for (var i = 0; i < words.length; i++) {
9+
var ret = words[i].toLowerCase();
10+
words[i] = ret.charAt(0).toUpperCase() + ret.slice(1);
11+
}
12+
return words.join(' ');
13+
}

polymer-filters.html

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script src="filter-random.js"></script>
1313
<script src="filter-round.js"></script>
1414
<script src="filter-truncate.js"></script>
15+
<script src="filter-titlecase.js"></script>
1516
<script src="filter-trim.js"></script>
1617

1718
<!--
@@ -69,6 +70,12 @@
6970
7071
> 2010-10-29 04:40:23 Z
7172
73+
####Title case
74+
75+
{{'this is a sentence that was not using title case.' | titlecase}}
76+
77+
> This Is A Sentence That Was Not Using Title Case.
78+
7279
####Order an array by the expression predicate
7380
7481
<template repeat="{{friends | orderBy('age')}}">

0 commit comments

Comments
 (0)