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",
"version": "3.1.7"
"version": "3.1.10"
}
],
"typescript": true

View File

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

View File

@ -236,10 +236,12 @@ function createUnitIndex(): void {
abbr, singular.toLowerCase(), plural.toLowerCase()
];
// liter <-> litres
if (abbr === 'l') {
unitIndex[abbr].push('liter', 'liters');
}
// meter -> metre
if (singular.includes('meter')) {
unitIndex[abbr].push(
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;
}
});