Last active
October 31, 2022 02:01
-
-
Save codeBelt/0dbdc2e0e53c1ca35e161c946795c37e to your computer and use it in GitHub Desktop.
Revisions
-
codeBelt revised this gist
Jun 3, 2019 . No changes.There are no files selected for viewing
-
codeBelt revised this gist
Mar 5, 2019 . 1 changed file with 106 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,106 @@ import StringUtility from './StringUtility'; describe('StringUtility', () => { const testStrings = ['lives-Down_by-the.River', 'Lives`Down,by~the RIVER', 'LivesDownBY the RIVER']; describe('toCamelCase', () => { it('returns camelCase string', () => { const expectedResult = 'livesDownByTheRiver'; testStrings.forEach((str) => { expect(StringUtility.toCamelCase(str)).toEqual(expectedResult); }); }); }); describe('toTitleCase', () => { it('returns Title Case string', () => { const expectedResult = 'Lives Down By The River'; testStrings.forEach((str) => { expect(StringUtility.toTitleCase(str)).toEqual(expectedResult); }); }); }); describe('toPascalCase', () => { it('returns PascalCase string', () => { const expectedResult = 'LivesDownByTheRiver'; testStrings.forEach((str) => { expect(StringUtility.toPascalCase(str)).toEqual(expectedResult); }); }); }); describe('toConstantCase', () => { it('returns CONSTANT_CASE string', () => { const expectedResult = 'LIVES_DOWN_BY_THE_RIVER'; testStrings.forEach((str) => { expect(StringUtility.toConstantCase(str)).toEqual(expectedResult); }); }); }); describe('toDotCase', () => { it('returns dot.case string', () => { const expectedResult = 'lives.down.by.the.river'; testStrings.forEach((str) => { expect(StringUtility.toDotCase(str)).toEqual(expectedResult); }); }); }); describe('toKebabCase', () => { it('returns kebab-case string', () => { const expectedResult = 'lives-down-by-the-river'; testStrings.forEach((str) => { expect(StringUtility.toKebabCase(str)).toEqual(expectedResult); }); }); }); describe('toLowerCase', () => { it('returns lowercase string', () => { const expectedResult = 'livesdownbytheriver'; testStrings.forEach((str) => { expect(StringUtility.toLowerCase(str)).toEqual(expectedResult); }); }); }); describe('toPathCase', () => { it('returns path/case string', () => { const expectedResult = 'lives/down/by/the/river'; testStrings.forEach((str) => { expect(StringUtility.toPathCase(str)).toEqual(expectedResult); }); }); }); describe('toSnakeCase', () => { it('returns snake_case string', () => { const expectedResult = 'lives_down_by_the_river'; testStrings.forEach((str) => { expect(StringUtility.toSnakeCase(str)).toEqual(expectedResult); }); }); }); describe('toSentenceCase', () => { it('returns Sentence case string', () => { const expectedResult = 'Lives down by the river'; testStrings.forEach((str) => { expect(StringUtility.toSentenceCase(str)).toEqual(expectedResult); }); }); }); }); -
codeBelt revised this gist
Mar 5, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ import {camelCase, kebabCase, lowerCase, snakeCase, startCase, upperCase, upperFirst} from 'lodash'; export default class StringUtility { static toCamelCase(str) { return camelCase(str); } @@ -40,4 +41,5 @@ export default class StringUtility { static toSentenceCase(str) { return upperFirst(lowerCase(str)); } } -
codeBelt created this gist
Mar 5, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import {camelCase, upperCase, startCase, lowerCase, kebabCase, upperFirst, snakeCase} from 'lodash'; export default class StringUtility { static toCamelCase(str) { return camelCase(str); } static toTitleCase(str) { return startCase(camelCase(str)); } static toPascalCase(str) { return startCase(camelCase(str)).replace(/ /g, ''); } static toConstantCase(str) { return upperCase(str).replace(/ /g, '_'); } static toDotCase(str) { return lowerCase(str).replace(/ /g, '.'); } static toKebabCase(str) { return kebabCase(str); } static toLowerCase(str) { return lowerCase(str).replace(/ /g, ''); } static toPathCase(str) { return lowerCase(str).replace(/ /g, '/'); } static toSnakeCase(str) { return snakeCase(str); } static toSentenceCase(str) { return upperFirst(lowerCase(str)); } }