forked from jakesgordon/javascript-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamelize.js
More file actions
33 lines (22 loc) · 974 Bytes
/
camelize.js
File metadata and controls
33 lines (22 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'
//-------------------------------------------------------------------------------------------------
function camelize(label) {
if (label.length === 0)
return label;
var n, result, word, words = label.split(/[_-]/);
// single word with first character already lowercase, return untouched
if ((words.length === 1) && (words[0][0].toLowerCase() === words[0][0]))
return label;
result = words[0].toLowerCase();
for(n = 1 ; n < words.length ; n++) {
result = result + words[n].charAt(0).toUpperCase() + words[n].substring(1).toLowerCase();
}
return result;
}
//-------------------------------------------------------------------------------------------------
camelize.prepended = function(prepend, label) {
label = camelize(label);
return prepend + label[0].toUpperCase() + label.substring(1);
}
//-------------------------------------------------------------------------------------------------
module.exports = camelize;