-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
30 lines (22 loc) · 797 Bytes
/
index.js
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
import camelcase from 'camelcase';
const PUNCTUATION = /[^\p{L}\p{N}]+/ug;
const toString = input => {
if (input == null) return '';
if (Array.isArray(input)) {
return input.map(s => s.toString().trim()).filter(s => s.length > 0).join(' ');
}
if (typeof input === 'function') {
return input.name ? input.name : '';
}
if (typeof input.toString !== 'function') {
return '';
}
return input.toString().trim();
};
export const pascalcase = (value, options = {}) => {
const input = toString(value);
const regex = options.punctuationRegex ?? PUNCTUATION;
const output = input ? camelcase(regex ? input.replace(regex, ' ') : input, options) : '';
return output ? output[0].toLocaleUpperCase(options.locale) + output.slice(1) : '';
};
export default pascalcase;