DekGenius.com
JAVASCRIPT
convert camelcase to sentence case javascript
var text = 'helloThereMister';
var result = text.replace( /([A-Z])/g, " $1" );
var finalResult = result.charAt(0).toUpperCase() + result.slice(1);
console.log(finalResult);
Convert string to camel case
//codewars:Convert string to camel case
function toCamelCase(str){
//console.log(str, 'testing')
if(str === ''){
return ''
} else {
let containmentArea = []
let splitString = str.replace(/[^A-Z0-9]/ig, "_").split("_")
//[ 'the', 'stealth', 'warrior' ]
let firstElement = containmentArea.push( splitString.splice(0,1) )
for(let word in splitString){
let splitWords = splitString[word].split('')
let capitalLetter = splitWords[0].toUpperCase()
splitWords.splice(0,1, capitalLetter)
let joinedWord = splitWords.join('')
containmentArea.push(joinedWord)
let newSentence = containmentArea.join('')
}
return containmentArea.join('')
}
}
Convert string to camel case
def to_camel_case(text):
if text == '':
return text
for i in text:
if i == '-' or i == '_':
text = text.replace(text[text.index(i):text.index(i)+2], text[text.index(i)+1].upper(), 1)
return text
convert a string in snake case to camel case js, snake case to camel case js
const snakeToCamelCase = (s) =>
s.toLowerCase().replace(/(_w)/g, (w) => w.toUpperCase().substr(1));
const str1 = 'learn_javascript';
console.log(snakeToCamelCase(str1)); // learnJavaScript
how to convert string to camel case in javascript
const camelCase = (string) => {
function camelize(str) {
return str
.replace(/(?:^w|[A-Z]|w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
})
.replace(/s+/g, "");
}
const newText = camelize(string);
return newText
};
javascript to camelcase
String.prototype.toCamelCase = function () {
let STR = this.toLowerCase()
.trim()
.split(/[ -_]/g)
.map(word => word.replace(word[0], word[0].toString().toUpperCase()))
.join('');
return STR.replace(STR[0], STR[0].toLowerCase());
};
Convert string to camel case
function toCamelCase(str){
let strArray;
if(str === ''){
return ''
}
if(str.indexOf('-') !== -1){
strArray = str.split('-')
}else{
strArray = str.split('_')
}
let capitalString = strArray[0]
for(let i=1; i<strArray.length;i++){
capitalString+= capitalize(strArray[i])
}
return capitalString
}
let capitalize = (str) =>{
return str[0].toUpperCase()+str.slice(1)
}
© 2022 Copyright:
DekGenius.com