Merge branch 'pr/6413'
This commit is contained in:
commit
7522c5c6be
|
@ -17,4 +17,14 @@ describe('String Format', function () {
|
|||
expect(string.convert('Zm9vYmFy')).to.be('foobar');
|
||||
});
|
||||
|
||||
it('convert a string to title case', function () {
|
||||
var StringFormat = fieldFormats.getType('string');
|
||||
var string = new StringFormat({
|
||||
transform: 'title'
|
||||
});
|
||||
expect(string.convert('PLEASE DO NOT SHOUT')).to.be('Please Do Not Shout');
|
||||
expect(string.convert('Mean, variance and standard_deviation.')).to.be('Mean, Variance And Standard_deviation.');
|
||||
expect(string.convert('Stay CALM!')).to.be('Stay Calm!');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -36,12 +36,14 @@ export default function StringFormatProvider(Private) {
|
|||
{ id: false, name: '- none -' },
|
||||
{ id: 'lower', name: 'Lower Case' },
|
||||
{ id: 'upper', name: 'Upper Case' },
|
||||
{ id: 'title', name: 'Title Case' },
|
||||
{ id: 'short', name: 'Short Dots' },
|
||||
{ id: 'base64', name: 'Base64 Decode'}
|
||||
];
|
||||
|
||||
_String.sampleInputs = [
|
||||
'A Quick Brown Fox.',
|
||||
'STAY CALM!',
|
||||
'com.organizations.project.ClassName',
|
||||
'hostname.net',
|
||||
'SGVsbG8gd29ybGQ='
|
||||
|
@ -55,10 +57,15 @@ export default function StringFormatProvider(Private) {
|
|||
}
|
||||
};
|
||||
|
||||
_String.prototype._toTitleCase = function (val) {
|
||||
return val.replace(/\w\S*/g, txt => { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
|
||||
};
|
||||
|
||||
_String.prototype._convert = function (val) {
|
||||
switch (this.param('transform')) {
|
||||
case 'lower': return String(val).toLowerCase();
|
||||
case 'upper': return String(val).toUpperCase();
|
||||
case 'title': return this._toTitleCase(val);
|
||||
case 'short': return _.shortenDottedString(val);
|
||||
case 'base64': return this._base64Decode(val);
|
||||
default: return _.asPrettyString(val);
|
||||
|
|
Loading…
Reference in a new issue