File tree Expand file tree Collapse file tree 5 files changed +120
-0
lines changed Expand file tree Collapse file tree 5 files changed +120
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var R = require ( 'ramda' ) ;
4
+ var Capitalize = require ( 'capitalize' ) ;
5
+
6
+ /**
7
+ * Capitalize the first letter of a String.
8
+ *
9
+ * @since 0.4.0
10
+ * @param {String|* } str - String to capitalize. Other types will be converted.
11
+ * @return {String }
12
+ * @example :
13
+ *
14
+ * {{capitalize "hello world"}} //=> "Hello world"
15
+ */
16
+
17
+ module . exports = function capitalize ( str ) {
18
+ if ( R . isNil ( str ) ) {
19
+ throw new Error ( 'The "capitalize" helper requires one argument.' )
20
+ }
21
+
22
+ if ( ! R . is ( String , str ) ) {
23
+ str = str . toString ( ) ;
24
+ }
25
+
26
+ return Capitalize ( str ) ;
27
+ } ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var R = require ( 'ramda' ) ;
4
+ var Capitalize = require ( 'capitalize' ) ;
5
+
6
+ /**
7
+ * Capitalize each word in a String. Works with punctuation and international
8
+ * characters.
9
+ *
10
+ * @since 0.4.0
11
+ * @param {String|* } str - String to capitalize. Other types will be converted.
12
+ * @return {String }
13
+ * @example :
14
+ *
15
+ * {{capitalizeWords "hello world"}} //=> "Hello World"
16
+ * {{capitalizeWords "hello-cañapolísas"}} //=> "Hello-Cañapolísas"
17
+ * {{capitalizeWords "it's a nice day"}} //=> "It's A Nice Day"
18
+ */
19
+
20
+ module . exports = function capitalizeWords ( str ) {
21
+ if ( R . isNil ( str ) ) {
22
+ throw new Error ( 'The "capitalizeWords" helper requires one argument.' )
23
+ }
24
+
25
+ if ( ! R . is ( String , str ) ) {
26
+ str = str . toString ( ) ;
27
+ }
28
+
29
+ return Capitalize . words ( str ) ;
30
+ } ;
Original file line number Diff line number Diff line change 27
27
},
28
28
"homepage" : " https://github.com/cloudfour/core-hbs-helpers" ,
29
29
"dependencies" : {
30
+ "capitalize" : " ^1.0.0" ,
30
31
"chance" : " ^1.0.3" ,
31
32
"handlebars" : " ^4.0.3" ,
32
33
"moment" : " ^2.10.6" ,
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var capitalize = require ( '../' ) . capitalize ;
4
+ var tape = require ( 'tape' ) ;
5
+ var Handlebars = require ( 'handlebars' ) ;
6
+
7
+ Handlebars . registerHelper ( capitalize . name , capitalize ) ;
8
+
9
+ tape ( 'capitalize' , function ( test ) {
10
+ var template = Handlebars . compile ( '{{capitalize content}}' ) ;
11
+ var expected ;
12
+ var actual ;
13
+
14
+ test . plan ( 3 ) ;
15
+
16
+ expected = 'Hello world' ;
17
+ actual = template ( { content : 'hello world' } ) ;
18
+ test . equal ( actual , expected , 'Works' ) ;
19
+
20
+ expected = 'True' ;
21
+ actual = template ( { content : true } ) ;
22
+ test . equal ( actual , expected , 'Works with non-String arguments' ) ;
23
+
24
+ test . throws (
25
+ function ( ) {
26
+ template ( ) ;
27
+ } ,
28
+ / r e q u i r e s o n e a r g u m e n t \. $ / ,
29
+ 'Errors when argument is missing'
30
+ ) ;
31
+ } ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ var capitalizeWords = require ( '../' ) . capitalizeWords ;
4
+ var tape = require ( 'tape' ) ;
5
+ var Handlebars = require ( 'handlebars' ) ;
6
+
7
+ Handlebars . registerHelper ( capitalizeWords . name , capitalizeWords ) ;
8
+
9
+ tape ( 'capitalizeWords' , function ( test ) {
10
+ var template = Handlebars . compile ( '{{{capitalizeWords content}}}' ) ;
11
+ var expected ;
12
+ var actual ;
13
+
14
+ test . plan ( 3 ) ;
15
+
16
+ expected = '"How\'s It Going?"' ;
17
+ actual = template ( { content : '"how\'s it going?"' } ) ;
18
+ test . equal ( actual , expected , 'Works' ) ;
19
+
20
+ expected = 'A,B,C' ;
21
+ actual = template ( { content : [ 'a' , 'b' , 'c' ] } ) ;
22
+ test . equal ( actual , expected , 'Works with non-String arguments' ) ;
23
+
24
+ test . throws (
25
+ function ( ) {
26
+ template ( ) ;
27
+ } ,
28
+ / r e q u i r e s o n e a r g u m e n t \. $ / ,
29
+ 'Errors when argument is missing'
30
+ ) ;
31
+ } ) ;
You can’t perform that action at this time.
0 commit comments