-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* IE support related changes * logger.debug removed * code cleanup * set-value package replaced with simple logic * polyfill url added in constant * test case for camelcase logic Co-authored-by: Moumita Mandal <[email protected]> Co-authored-by: Moumita Mandal <[email protected]>
- Loading branch information
Showing
7 changed files
with
131 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import camelcase from "../utils/camelcase"; | ||
|
||
test("convert string with space to camelcase format", () => { | ||
expect(camelcase("camel case")).toBe("camelCase"); | ||
}); | ||
|
||
test("convert string with underscore to camelcase format", () => { | ||
expect(camelcase("camel_case")).toBe("camelCase"); | ||
}); | ||
|
||
test("convert string with first letter capital to camelcase format", () => { | ||
expect(camelcase("Camelcase")).toBe("camelcase"); | ||
}); | ||
|
||
test("convert uppercase string to camelcase format", () => { | ||
expect(camelcase("CAMELCASE")).toBe("camelcase"); | ||
}); | ||
|
||
test("convert string with first letter capital for each word to camelcase format", () => { | ||
expect(camelcase("Camel Case")).toBe("camelCase"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// util function to convert the input to string type | ||
function convertToString(input) { | ||
if (input) { | ||
if (typeof input === "string") { | ||
return input; | ||
} | ||
|
||
return String(input); | ||
} | ||
return ""; | ||
} | ||
|
||
// convert string to words | ||
function toWords(input) { | ||
input = convertToString(input); | ||
|
||
var regex = | ||
/[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g; | ||
|
||
return input.match(regex); | ||
} | ||
|
||
// convert the input array to camel case | ||
function toCamelCase(inputArray) { | ||
let result = ""; | ||
|
||
for (let i = 0, len = inputArray.length; i < len; i++) { | ||
const currentStr = inputArray[i]; | ||
|
||
let tempStr = currentStr.toLowerCase(); | ||
|
||
if (i !== 0) { | ||
// convert first letter to upper case (the word is in lowercase) | ||
tempStr = tempStr.substr(0, 1).toUpperCase() + tempStr.substr(1); | ||
} | ||
|
||
result += tempStr; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// this function call all other functions | ||
|
||
function camelcase(input) { | ||
const words = toWords(input); | ||
|
||
return toCamelCase(words); | ||
} | ||
|
||
export default camelcase; |
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