more advanced unit aliasing

This commit is contained in:
Evert Prants 2021-10-19 20:53:55 +03:00
parent 921e9df04e
commit 32c041cb4f
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 21 additions and 2 deletions

View File

@ -43,7 +43,7 @@
}, },
{ {
"name": "utility", "name": "utility",
"version": "3.1.7" "version": "3.1.10"
} }
], ],
"typescript": true "typescript": true

View File

@ -2,7 +2,7 @@
"main": "plugin.js", "main": "plugin.js",
"name": "utility", "name": "utility",
"description": "Utility commands and math operations", "description": "Utility commands and math operations",
"version": "3.1.7", "version": "3.1.10",
"tags": ["commands", "tools"], "tags": ["commands", "tools"],
"dependencies": ["simplecommands"], "dependencies": ["simplecommands"],
"npmDependencies": [ "npmDependencies": [

View File

@ -236,10 +236,12 @@ function createUnitIndex(): void {
abbr, singular.toLowerCase(), plural.toLowerCase() abbr, singular.toLowerCase(), plural.toLowerCase()
]; ];
// liter <-> litres
if (abbr === 'l') { if (abbr === 'l') {
unitIndex[abbr].push('liter', 'liters'); unitIndex[abbr].push('liter', 'liters');
} }
// meter -> metre
if (singular.includes('meter')) { if (singular.includes('meter')) {
unitIndex[abbr].push( unitIndex[abbr].push(
singular.replace('meter', 'metre').toLowerCase(), singular.replace('meter', 'metre').toLowerCase(),
@ -247,6 +249,23 @@ function createUnitIndex(): void {
); );
} }
// metre -> meter
if (singular.includes('metre')) {
unitIndex[abbr].push(
singular.replace('metre', 'meter').toLowerCase(),
plural.replace('metre', 'meter').toLowerCase(),
);
}
// " per " -> "/"
const appendages: string[] = [];
unitIndex[abbr].forEach((entry) => {
if (entry.includes(' per ')) {
appendages.push(entry.replace(' per ', '/'));
}
});
unitIndex[abbr].push(...appendages);
backupLowercaseUnitTable[abbr.toLowerCase()] = abbr; backupLowercaseUnitTable[abbr.toLowerCase()] = abbr;
} }
}); });