blob: 7e8159ce4eaf1a9e02fa798954fe1952f6489bb3 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
2 * pascalcase <https://github.com/jonschlinkert/pascalcase>
3 *
4 * Copyright (c) 2015, Jon Schlinkert.
5 * Licensed under the MIT License.
6 */
7
8function 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
21module.exports = pascalcase;