/*! case - v1.6.3 - 2020-03-24
* Copyright (c) 2020 Nathan Bubna; Licensed (MIT OR GPL-3.0-or-later) */
(function() {
"use strict";
var unicodes = function(s, prefix) {
prefix = prefix || '';
return s.replace(/(^|-)/g, '$1\\u'+prefix).replace(/,/g, '\\u'+prefix);
},
basicSymbols = unicodes('20-26,28-2F,3A-40,5B-60,7B-7E,A0-BF,D7,F7', '00'),
baseLowerCase = 'a-z'+unicodes('DF-F6,F8-FF', '00'),
baseUpperCase = 'A-Z'+unicodes('C0-D6,D8-DE', '00'),
improperInTitle = 'A|An|And|As|At|But|By|En|For|If|In|Of|On|Or|The|To|Vs?\\.?|Via',
regexps = function(symbols, lowers, uppers, impropers) {
symbols = symbols || basicSymbols;
lowers = lowers || baseLowerCase;
uppers = uppers || baseUpperCase;
impropers = impropers || improperInTitle;
return {
capitalize: new RegExp('(^|['+symbols+'])(['+lowers+'])', 'g'),
pascal: new RegExp('(^|['+symbols+'])+(['+lowers+uppers+'])', 'g'),
fill: new RegExp('['+symbols+']+(.|$)','g'),
sentence: new RegExp('(^\\s*|[\\?\\!\\.]+"?\\s+"?|,\\s+")(['+lowers+'])', 'g'),
improper: new RegExp('\\b('+impropers+')\\b', 'g'),
relax: new RegExp('([^'+uppers+'])(['+uppers+']*)(['+uppers+'])(?=[^'+uppers+']|$)', 'g'),
upper: new RegExp('^[^'+lowers+']+$'),
hole: /[^\s]\s[^\s]/,
apostrophe: /'/g,
room: new RegExp('['+symbols+']')
};
},
re = regexps(),
_ = {
re: re,
unicodes: unicodes,
regexps: regexps,
types: [],
up: String.prototype.toUpperCase,
low: String.prototype.toLowerCase,
cap: function(s) {
return _.up.call(s.charAt(0))+s.slice(1);
},
decap: function(s) {
return _.low.call(s.charAt(0))+s.slice(1);
},
deapostrophe: function(s) {
return s.replace(re.apostrophe, '');
},
fill: function(s, fill, deapostrophe) {
if (fill != null) {
s = s.replace(re.fill, function(m, next) {
return next ? fill + next : '';
});
}
if (deapostrophe) {
s = _.deapostrophe(s);
}
return s;
},
prep: function(s, fill, pascal, upper) {
s = s == null ? '' : s + '';// force to string
if (!upper && re.upper.test(s)) {
s = _.low.call(s);
}
if (!fill && !re.hole.test(s)) {
var holey = _.fill(s, ' ');
if (re.hole.test(holey)) {
s = holey;
}
}
if (!pascal && !re.room.test(s)) {
s = s.replace(re.relax, _.relax);
}
return s;
},
relax: function(m, before, acronym, caps) {
return before + ' ' + (acronym ? acronym+' ' : '') + caps;
}
},
Case = {
_: _,
of: function(s) {
for (var i=0,m=_.types.length; i