UNPKG

1.36 kBJavaScriptView Raw
1var CaseTransform = /** @class */ (function () {
2 function CaseTransform() {
3 }
4 CaseTransform.snakeToCamelCase = function (value) {
5 return value ? value.replace(new RegExp(/_/g), ' ').replace(/\b\w/g, function (l) { return l.toUpperCase(); })
6 .replace(/\b\w/, function (l) { return l.toLowerCase(); }).replace(/\s/g, '') : value;
7 };
8 CaseTransform.lowerToTitleCase = function (value) {
9 // Code taken from https://github.com/gouch/to-title-case to support the proper spec.
10 var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i;
11 return value ? value.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function (match, index, title) {
12 if (index > 0 && index + match.length !== title.length &&
13 match.search(smallWords) > -1 && title.charAt(index - 2) !== ':' &&
14 (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&
15 title.charAt(index - 1).search(/[^\s-]/) < 0) {
16 return match.toLowerCase();
17 }
18 if (match.substr(1).search(/[A-Z]|\../) > -1) {
19 return match;
20 }
21 return match.charAt(0).toUpperCase() + match.substr(1);
22 }) : value;
23 };
24 ;
25 return CaseTransform;
26}());
27export { CaseTransform };