Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80765 views
1
'use strict';
2
module.exports = function (str) {
3
str = str.trim();
4
5
if (str.length === 1 || !(/[_.\- ]+/).test(str) ) {
6
if (str[0] === str[0].toLowerCase() && str.slice(1) !== str.slice(1).toLowerCase()) {
7
return str;
8
}
9
10
return str.toLowerCase();
11
}
12
13
return str
14
.replace(/^[_.\- ]+/, '')
15
.toLowerCase()
16
.replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
17
return p1.toUpperCase();
18
});
19
};
20
21