Skip to content

Commit

Permalink
feat: added capitalize method, it simplies capitalizes the given text…
Browse files Browse the repository at this point in the history
… argument
  • Loading branch information
teclone committed Jun 11, 2019
1 parent b356228 commit 0aa6b6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ export const applyCase = (text: string, caseStyle: number,
}
};

/**
* capitalizes the given text
* @param text text to capitalize
*/
export const capitalize = (text: string): string => {
return text.length > 0? text.charAt(0).toUpperCase() + text.substring(1).toLowerCase() : '';
}

/**
* expands the string key and turns it into an object property
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,17 @@ describe('Utils', function() {
});
});

describe(`.capitalize(text: string): string`, function() {
it(`should capitalize the given text`, function() {
expect(Utils.capitalize('naMe')).toEqual('Name');
expect(Utils.capitalize('')).toEqual('');
});

it(`should default the delimiter argument to /[_-\\s]/ if not given`, function() {
expect(Utils.snakeCase('my-second_string')).toEqual('my_second_string');
});
});

describe(`.expandProperty(target: object, key: string, value: any, delimiter: string = ".",
caseStyle= CASE_STYLES.CAMEL_CASE)`, function() {

Expand Down

0 comments on commit 0aa6b6f

Please sign in to comment.