Skip to content

Camel Case is actually Pascal Case #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/caseconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* more information and online tools for this implementation on: <a href=
* "https://en.toolpage.org/cat/case-converter">https://en.toolpage.org/cat/case-converter</a>
*
* @author Yves Sorge
* @author Yves Sorge, Daniel Kendall (camelCase)
*/
function CaseConverterClass() {

Expand Down Expand Up @@ -77,19 +77,44 @@ function CaseConverterClass() {
}

/**
* Converts a text into camel case.
* Example: "camel case" into "CamelCase".
* Converts a text into pascal case.
* Example: "Pascal case" into "PascalCase".
*
* @param {String} value
* @return {String} converted string
*/
this.convertToCamelCase = function(value) {
this.convertToPascalCase = function(value) {
var replace = "/";
value = value.replace(/[\(\)\[\]\{\}\=\?\!\.\:,\-_\+\\\"#~\/]/g, " ");
value = this.convertToStartCase(value);
return value.replace(/\s+/g, "");
}

/**
* Converts a text into camel case.
* Example: "camel case" into "camelCase".
*
* @param {String} value
* @return {String} converted string
*/
this.convertToCamelCase = function(value) {
// Remove special characters and convert to start case
value = value.replace(/[\(\)\[\]\{\}\=\?\!\.\:,\-\_\+\\\"\#~\/]/g, " ");
value = this.convertToStartCase(value);

// Convert to camelCase
const words = value.split(" ");
const camelCaseWords = words.map((word, index) => {
if (index === 0) {
return word.toLowerCase();
} else {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
}
});

return camelCaseWords.join("");
}

/**
* Converts a text into snake case.
* Example: "snake case" into "Snake_Case".
Expand Down