File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /**
4
+ * Convert a string to camel case.
5
+ *
6
+ * @param {String } string - The string.
7
+ * @return {String }
8
+ */
9
+ function camelCase ( string ) {
10
+ if ( typeof string !== 'string' ) {
11
+ throw new Error ( '`camelCase`: first argument must be a string.' ) ;
12
+ }
13
+
14
+ // hyphen found after first character
15
+ if ( string . indexOf ( '-' ) > 0 ) {
16
+ var strings = string . toLowerCase ( ) . split ( '-' ) ;
17
+
18
+ // capitalize starting from the second string item
19
+ for ( var i = 1 , len = strings . length ; i < len ; i ++ ) {
20
+ strings [ i ] = strings [ i ] . charAt ( 0 ) . toUpperCase ( ) + strings [ i ] . slice ( 1 ) ;
21
+ }
22
+
23
+ return strings . join ( '' ) ;
24
+ }
25
+
26
+ return string ;
27
+ }
28
+
29
+ /**
30
+ * Export utilties.
31
+ */
32
+ module . exports = {
33
+ camelCase : camelCase
34
+ } ;
You can’t perform that action at this time.
0 commit comments