Articles Tagged 'RegExp'

Camelize, CamelCase

As seen in the post Variety of coding and coding approaches that a developer may have to solve a problem are multiple and diverse for the same programming language used. Here's how some of the most popular JavaScript frameworks have solved a simple function of CamelCase :

Prototype.js

Prototype.js , version 1.6.0.3, explicitly proposes a method camelize() to make the camelcase on a string. The author's approach is quite simple and the code is self-explanatory. In this case it was not made any use of Regular Expression!

1
2
3
4
5
6
7
8
9
10
11
12
13
( ) { camelize: function () {
this . split ( '-' ) , len = parts. length ; var parts = this. split ('-'), len = parts. length;
len == 1 ) return parts [ 0 ] ; if (len == 1) return parts [0];

this . charAt ( 0 ) == '-' camelized var = this. charAt (0) == '-'
0 ] . charAt ( 0 ) . toUpperCase ( ) + parts [ 0 ] . substring ( 1 ) ? Parts [0]. CharAt (0). ToUpperCase () + parts [0]. Substring (1)
0 ] ; : Parts [0];

var i = 1 ; i < len ; i ++ ) for (var i = 1, i <len; i + +)
i ] . charAt ( 0 ) . toUpperCase ( ) + parts [ i ] . substring ( 1 ) ; camelized + = parts [i]. charAt (0). toUpperCase () + parts [i]. substring (1);

camelized return;
}

Continued ...


Stop SOPA