Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
feature(helpers): added snake case and constant case for manipulating…
Browse files Browse the repository at this point in the history
… strings
  • Loading branch information
danbucholtz committed Jul 24, 2017
1 parent 653d9f2 commit 9e19890
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/util/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,19 @@ describe('helpers', () => {
});
});

describe('snakeCase', () => {
it('should convert the phrase to use underscores', () => {
expect(helpers.snakeCase('taco bell')).toEqual('taco_bell');
});
});

describe('constantCase', () => {
it('should capitalize and separate words by underscore', () => {
expect(helpers.constantCase('taco bell')).toEqual('TACO_BELL');
});

it('should convert camel case to correct case', () => {
expect(helpers.constantCase('TacoBell')).toEqual('TACO_BELL');
});
});
});
8 changes: 8 additions & 0 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ export function sentenceCase(input: string) {
return upperCaseFirst(noCase);
}

export function snakeCase(input: string) {
return removeCaseFromString(input, '_');
}

export function constantCase(input: string) {
return snakeCase(input).toUpperCase();
}

export function camelCase(input: string) {
input = removeCaseFromString(input);
input = input.replace(/ (?=\d)/g, '_');
Expand Down

0 comments on commit 9e19890

Please sign in to comment.