Javascript String toCamelCase()

Description

Javascript String toCamelCase()


String.prototype.toCamelCase = function(){
    return this/*from   w  w w  . j  a v a 2 s .c o  m*/
        .toLowerCase()
        .replace( /\W+/g, ' ' )
        .replace( / (.)/g, function($1) { return $1.toUpperCase(); })
        .replace( / /g, '' );
}

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
  return this.valueOf().replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
}

Javascript String toCamelCase()

//Add method to strings
String.prototype.toCamelCase = function () {
  const regex = new RegExp(/(?:_|-)(.)/g)
  if (regex.test(this)) {
    return this.toLowerCase().replace(regex, (match, group1) => {
      return group1.toUpperCase()
    })//from  w  w  w  .  j a va 2s .co  m
  }
  return this + ''
}

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
    return this/* w w w  .  j ava2s. c om*/
        .replace(/\s(.)/g, function ($1) { return $1.toUpperCase(); })
        .replace(/\s/g, '')
        .replace(/^(.)/, function ($1) { return $1.toLowerCase(); });
}

function enumString(e,value) 
{
    for (var k in e) if (e[k] == value) return k;
    return null;
}

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
  return this.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
};

Javascript String toCamelCase()

/**//w  w w . j  av  a 2 s.c o  m
 * Converts a hyphenated string to camel case
 *  ex: 'my-module' returns 'myModule'
 */
String.prototype.toCamelCase = function () {
  return this.toString().toLowerCase().replace(/(-[a-z])/g, function ($1) {
    return $1.toUpperCase().replace('-', '');
  });
};

Javascript String toCamelCase()

/**//from   w ww .  j  a v  a 2 s . c  om
 * toCamelCase: converts string to camel case
 */

String.prototype.toCamelCase = function () {
  return this.replace(/^\s+|\s+$/g, '')
    .toLowerCase()
    .replace(/([\s\-\_][a-z0-9])/g, function ($1) {
      return $1.replace(/\s/, '').toUpperCase();
    })
    .replace(/\W/g, '');
};

export default String.prototype.toCamelCase;

Javascript String toCamelCase()

String.prototype.toCamelCase = function() {
 words = this.split(' ')
 var upperCased = '';
 for (var i = 0; i < words.length; i++) {
  for (var y = 0; y < words[i].length; y++) {
   if (y == 0) {//from   w  w w  .  j  a v  a2s.c  o m
    upperCased += words[i][y].toUpperCase();
   }
   else {
    upperCased += words[i][y];
   }
  }
  upperCased += ' '; 
 } 
 return upperCased;
}


var s = "i'm a test"




console.log(s.toCamelCase())

Javascript String toCamelCase()

String.prototype.toCamelCase = function(){
  return this.replace(/[-_]([a-z])/g, function (g) { return g[1].toUpperCase(); });
};

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
    return this.split(/\W+/g).map(function (w) {
        return w.substr(0, 1).toUpperCase() + w.substr(1); 
    }).join(' ');
};

Javascript String toCamelCase()

'use strict';/*ww w . j av a2 s .  com*/

/**
 * toCamelCase: converts string to camel case
 */

String.prototype.toCamelCase = function () {
  return this.replace(/^\s+|\s+$/g, '').toLowerCase().replace(/([\s\-\_][a-z0-9])/g, function ($1) {
    return $1.replace(/\s/, '').toUpperCase();
  }).replace(/\W/g, '');
};

exports.default = String.prototype.toCamelCase;

Javascript String toCamelCase()

/*@/* www.  ja va 2 s .  c o  m*/
  @file: src/tocamelcase.js
  @version: 1.0.0
  @website: http://webman.io/missing.js/tocamelcase.js
  @author: Mark Topper
  @author-website: http://webman.io
  @function: toCamelCase
  @var:  String  the string to turn into camel case
  @description: convert a string into camel case, like from "hello_world" to "helloWorld"
@*/
String.prototype.toCamelCase = function(){
    return this.replace(/(\_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
};

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
    return this.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
        if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
        return index == 0 ? match.toLowerCase() : match.toUpperCase();
    });/*w  ww.  ja  va2s.c  o  m*/
};

String.prototype.format = function () {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function (match, number) {
        return typeof args[number] != 'undefined'
          ? args[number]
          : match
        ;
    });
};

Javascript String toCamelCase()


String.prototype.toCamelCase = function() {
 return this.toLowerCase()
  // Replaces any - or _ characters with a space
  .replace(/[-_]+/g, ' ')
  // Removes any non alphanumeric characters
  .replace(/[^\w\s]/g, '')
  // Uppercases the first character in each group immediately following a space
  // (delimited by spaces)
  .replace(/ (.)/g, function($1) {
   return $1.toUpperCase();
  })//from w w  w  .j ava  2  s.c o m
  // Removes spaces
  .replace(/ /g, '');
};

Javascript String toCamelCase()

String.prototype.toCamelCase = function(){
    return this.toLowerCase().replace(/(_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
};
String.prototype.toUnderscore = function(){
    return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};
String.prototype.trim = function(){
    return this.replace(/^\s+|\s+$/g, "");
};
String.prototype.capitalize = function(){
    return this.charAt(0).toUpperCase()+this.substring(1);
};

Javascript String toCamelCase()

String.prototype.toCamelCase = function() {
 /*//from   ww  w  . j a  v  a 2  s.  c  om
 Uses regex to take a string and capitalize all first letters of every word.
 Current implementation of regex finds spaces as well, so it's not a perfect
 regex. Still, it's much cleaner than looping. Note: not a true camel case
 as words come out First Word instead of firstWord.
 */
 return this.replace(/(^|\s)[a-z]/g, function (x) { return x.toUpperCase() });
}


function assert(test,result){
 return test == result;
}

function test(){
 var numTestsPassed = 0;
 firstString = "This is a test";
 secondString = "hi I'm a Test string"

 var numTestsPassed = 0
 if (assert(firstString.toCamelCase(), "This Is A Test")){
  numTestsPassed +=1;
}
 if (assert(secondString.toCamelCase(), "Hi I'm A Test String")){
  numTestsPassed +=1;
 console.log("Num Tests passed: ", numTestsPassed);
 }
}

test()

Javascript String toCamelCase()

/*----------------------------------------------------------------------------*\
    # Copyright 2017, BuzzingPixel, LLC//from   ww w  . jav  a2 s  .com

    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the Apache License 2.0.
    # http://www.apache.org/licenses/LICENSE-2.0
\*----------------------------------------------------------------------------*/

String.prototype.toCamelCase = function() {
    return this.toLowerCase()
        // Replaces any - or _ characters with a space
        .replace(/[-_]+/g, ' ')
        // Removes any non alphanumeric characters
        .replace(/[^\w\s]/g, '')
        // Uppercases the first character in each group immediately following a space
        // (delimited by spaces)
        .replace(/ (.)/g, function($1) {
            return $1.toUpperCase();
        })
        // Removes spaces
        .replace(/ /g, '');
};

Javascript String toCamelCase()

String.prototype.toCamelCase = function () {
    var result = this.charAt(0).toLowerCase() + this.substring(1);
    result = result.replaceAll("-", "");
    return result;
};



PreviousNext

Related