> ⚠️ resubmission targeting `main` instead of `v2` ### Purpose Updates `uncamel()` function in [uncamelFilter.js](https://github.com/syncthing/syncthing/blob/v2/gui/default/syncthing/core/uncamelFilter.js) to fix camelCase conversion edge cases, see #10128 This adds an array called `reservedStrings` which will be printed as-is, e.g. `IDs`, `LAN` etc. I pre-populated this with what I believe makes sense, but of course this is easily updated. ### Testing I compiled all the config variables I could find in `syncthing/lib/config/*configuration.go` and tested this new function against them. Everything seemed to pass. ### Screenshot 
This commit is contained in:
@@ -1,27 +1,39 @@
|
|||||||
angular.module('syncthing.core')
|
angular.module('syncthing.core')
|
||||||
.filter('uncamel', function () {
|
.filter('uncamel', function () {
|
||||||
|
const reservedStrings = [
|
||||||
|
'IDs', 'ID', // substrings must come AFTER longer keywords containing them
|
||||||
|
'URL', 'UR',
|
||||||
|
'API', 'QUIC', 'TCP', 'UDP', 'NAT', 'LAN', 'WAN',
|
||||||
|
'KiB', 'MiB', 'GiB', 'TiB'
|
||||||
|
];
|
||||||
return function (input) {
|
return function (input) {
|
||||||
input = input.replace(/(.)([A-Z][a-z]+)/g, '$1 $2').replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
if (!input || typeof input !== 'string') return '';
|
||||||
var parts = input.split(' ');
|
const placeholders = {};
|
||||||
var lastPart = parts.splice(-1)[0];
|
let counter = 0;
|
||||||
|
reservedStrings.forEach(word => {
|
||||||
|
const placeholder = `__RSV${counter}__`;
|
||||||
|
const re = new RegExp(word, 'g');
|
||||||
|
input = input.replace(re, placeholder);
|
||||||
|
placeholders[placeholder] = word;
|
||||||
|
counter++;
|
||||||
|
});
|
||||||
|
input = input.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
||||||
|
Object.entries(placeholders).forEach(([ph, word]) => {
|
||||||
|
input = input.replace(new RegExp(ph, 'g'), ` ${word} `);
|
||||||
|
});
|
||||||
|
let parts = input.split(' ');
|
||||||
|
const lastPart = parts.pop();
|
||||||
switch (lastPart) {
|
switch (lastPart) {
|
||||||
case "S":
|
case 'S': parts.push('(seconds)'); break;
|
||||||
parts.push('(seconds)');
|
case 'M': parts.push('(minutes)'); break;
|
||||||
break;
|
case 'H': parts.push('(hours)'); break;
|
||||||
case "M":
|
case 'Ms': parts.push('(milliseconds)'); break;
|
||||||
parts.push('(minutes)');
|
default: parts.push(lastPart); break;
|
||||||
break;
|
|
||||||
case "H":
|
|
||||||
parts.push('(hours)');
|
|
||||||
break;
|
|
||||||
case "Ms":
|
|
||||||
parts.push('(milliseconds)');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
parts.push(lastPart);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
input = parts.join(' ');
|
parts = parts.map(part => {
|
||||||
return input.charAt(0).toUpperCase() + input.slice(1);
|
const match = reservedStrings.find(w => w.toUpperCase() === part.toUpperCase());
|
||||||
|
return match || part.charAt(0).toUpperCase() + part.slice(1);
|
||||||
|
});
|
||||||
|
return parts.join(' ').replace(/\s+/g, ' ').trim();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user