1 |
3a515b92
|
cagy
|
/*!
|
2 |
|
|
* pascalcase <https://github.com/jonschlinkert/pascalcase>
|
3 |
|
|
*
|
4 |
|
|
* Copyright (c) 2015, Jon Schlinkert.
|
5 |
|
|
* Licensed under the MIT License.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
function pascalcase(str) {
|
9 |
|
|
if (typeof str !== 'string') {
|
10 |
|
|
throw new TypeError('expected a string.');
|
11 |
|
|
}
|
12 |
|
|
str = str.replace(/([A-Z])/g, ' $1');
|
13 |
|
|
if (str.length === 1) { return str.toUpperCase(); }
|
14 |
|
|
str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
|
15 |
|
|
str = str.charAt(0).toUpperCase() + str.slice(1);
|
16 |
|
|
return str.replace(/[\W_]+(\w|$)/g, function (_, ch) {
|
17 |
|
|
return ch.toUpperCase();
|
18 |
|
|
});
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
module.exports = pascalcase;
|