This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
130 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const { decamelize } = require('humps'); | ||
const { decamelize } = require('../../../helpers'); | ||
|
||
/** | ||
* | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
14 changes: 14 additions & 0 deletions
14
constants/regexes/dashHyphenWhitespaceAnyCharacters.test.js
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS } = require('./'); | ||
|
||
describe('regexes', () => { | ||
describe('DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS', () => { | ||
it('should replace dash, hyphen, whitespace and any characters', () => { | ||
expect( | ||
'Hello_World'.replace( | ||
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS, | ||
(match, chr) => (chr ? chr.toUpperCase() : ''), | ||
), | ||
).toBe('HelloWorld'); | ||
}); | ||
}); | ||
}); |
This file contains 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 characters
11 changes: 11 additions & 0 deletions
11
constants/regexes/separateStringIntoWordsWithCapitalLetter.test.js
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER } = require('./'); | ||
|
||
describe('helpers', () => { | ||
describe('SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER', () => { | ||
it('should separate string', () => { | ||
expect( | ||
'HelloWorld'.split(SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER), | ||
).toEqual(['Hello', 'World']); | ||
}); | ||
}); | ||
}); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const camelize = require('./'); | ||
|
||
describe('helpers', () => { | ||
describe('camelize', () => { | ||
it('should camelize string', () => { | ||
expect(camelize('hello-world', { separator: '-' })).toBe('helloWorld'); | ||
}); | ||
}); | ||
}); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { | ||
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS, | ||
} = require('../../constants/regexes'); | ||
const isNumeric = require('../isNumeric/'); | ||
|
||
/** | ||
* @example camelize('Hello_World') => 'HelloWorld' | ||
* @param {string} value Decamelize string. | ||
* @return {string} Camelize string. | ||
*/ | ||
module.exports = value => { | ||
let string = value; | ||
if (isNumeric(string)) { | ||
return string; | ||
} | ||
string = string.replace( | ||
DASH_HYPHEN_WHITESPACE_ANY_CHARACTERS, | ||
(match, chr) => (chr ? chr.toUpperCase() : ''), | ||
); | ||
// Ensure 1st char is always lowercase | ||
return string.substr(0, 1).toLowerCase() + string.substr(1); | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const decamelize = require('./'); | ||
|
||
describe('helpers', () => { | ||
describe('decamelize', () => { | ||
it('should decamelize string with hyphen separator', () => { | ||
expect(decamelize('helloWorld', { separator: '-' })).toBe('hello-world'); | ||
}); | ||
|
||
it('should decamelize string with underscore separator', () => { | ||
expect(decamelize('helloWorld', { separator: '_' })).toBe('hello_world'); | ||
}); | ||
}); | ||
}); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const separateWords = require('../separateWords'); | ||
|
||
/** | ||
* @example decamelize('helloWorld', {separator: '-'}) => 'hello_world' | ||
* @param {string} string | ||
* @param {Object} [options] User options. | ||
* @param {string} [options.separator] separating line. | ||
* @param {regex|string} [options.split] line break. | ||
* @return {string} Decamelize string. | ||
*/ | ||
module.exports = (string, options) => | ||
separateWords(string, options).toLowerCase(); |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { | ||
SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER, | ||
} = require('../../constants/regexes'); | ||
|
||
/** | ||
* @example HelloWorld => Hello_world | ||
* @param {string} string String. | ||
* @param {Object} [options] User options. | ||
* @param {string} [options.separator] separating line. | ||
* @param {regex|string} [options.split] line break. | ||
* @return {string} | ||
* | ||
*/ | ||
module.exports = (string, options = {}) => { | ||
const separator = options.separator || '_'; | ||
const split = options.split || SEPARATE_STRING_INTO_WORDS_WITH_CAPITAL_LETTER; | ||
|
||
return string.split(split).join(separator); | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const separateWords = require('./'); | ||
|
||
describe('helpers', () => | ||
describe('separateWords', () => { | ||
it('should separate word', () => { | ||
expect(separateWords('HelloWorld')).toEqual('Hello_World'); | ||
}); | ||
})); |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters