File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -94,19 +94,19 @@ module.exports.template = function (template, data) {
9494/**
9595 * Make first char uppercase.
9696 * @param {string } str
97- * @returns {string }
97+ * @returns {string | undefined }
9898 */
9999module . exports . ucfirst = function ( str ) {
100- return str . charAt ( 0 ) . toUpperCase ( ) + str . substr ( 1 )
100+ if ( str ) return str . charAt ( 0 ) . toUpperCase ( ) + str . substr ( 1 )
101101}
102102
103103/**
104104 * Make first char lowercase.
105105 * @param {string } str
106- * @returns {string }
106+ * @returns {string | undefined }
107107 */
108108module . exports . lcfirst = function ( str ) {
109- return str . charAt ( 0 ) . toLowerCase ( ) + str . substr ( 1 )
109+ if ( str ) return str . charAt ( 0 ) . toLowerCase ( ) + str . substr ( 1 )
110110}
111111
112112module . exports . chunkArray = function ( arr , chunk ) {
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ describe('utils', () => {
3838 it ( 'should capitalize first letter' , ( ) => {
3939 expect ( utils . ucfirst ( 'hello' ) ) . equal ( 'Hello' )
4040 } )
41+
42+ it ( 'should handle the undefined' , ( ) => {
43+ expect ( utils . ucfirst ( ) ) . to . be . undefined
44+ } )
4145 } )
4246
4347 describe ( '#beautify' , ( ) => {
You can’t perform that action at this time.
0 commit comments