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

Commit 9e19890

Browse files
committed
feature(helpers): added snake case and constant case for manipulating strings
1 parent 653d9f2 commit 9e19890

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/util/helpers.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,19 @@ describe('helpers', () => {
359359
});
360360
});
361361

362+
describe('snakeCase', () => {
363+
it('should convert the phrase to use underscores', () => {
364+
expect(helpers.snakeCase('taco bell')).toEqual('taco_bell');
365+
});
366+
});
367+
368+
describe('constantCase', () => {
369+
it('should capitalize and separate words by underscore', () => {
370+
expect(helpers.constantCase('taco bell')).toEqual('TACO_BELL');
371+
});
372+
373+
it('should convert camel case to correct case', () => {
374+
expect(helpers.constantCase('TacoBell')).toEqual('TACO_BELL');
375+
});
376+
});
362377
});

src/util/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,14 @@ export function sentenceCase(input: string) {
410410
return upperCaseFirst(noCase);
411411
}
412412

413+
export function snakeCase(input: string) {
414+
return removeCaseFromString(input, '_');
415+
}
416+
417+
export function constantCase(input: string) {
418+
return snakeCase(input).toUpperCase();
419+
}
420+
413421
export function camelCase(input: string) {
414422
input = removeCaseFromString(input);
415423
input = input.replace(/ (?=\d)/g, '_');

0 commit comments

Comments
 (0)