User-defined Expressions

name

User-defined Expressions

description

Enables defining arbitrary number of expressions of your own via the Settings.

instructions


Define arbitrary number of expressions of your own.

How to use:
1. Open Settings in "Account Settings > Plugins > User-defined Expressions (Gear icon)".
2. Fill "Expressions" with whatever you like, in the format of "fromString=toString", separated by "@@".

Please set "ExpressionDelimiter" explicitly if you prefer a delimiter other than "@@".

Known limitations:
- No dynamic expressions (such as {today}) can be made.
- Expressions containing "=" in fromString cannot be defined.
- Cannot define more than 100 expressions (if you'd really like to do, please modify the value of MAX_NUMBER_OF_EXPRESSIONS in the code).

setting

Expressions

setting

ExpressionDelimiter


(() => {
const MAX_NUMBER_OF_EXPRESSIONS = 100;
const EXPRESSION_DELIMITER_DEFAULT = "@@";
 
function getOrdinal(i) {
const d = i % 100;
if (d > 3 && d < 21) return "th";
switch (d % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
}
return "th";
}
 
const plugin = {};
for (let i = 0; i < MAX_NUMBER_OF_EXPRESSIONS; i++) {
if (i >= 100000) break; // Safety net
plugin[String(i + 1) + getOrdinal(i + 1)] = {
async check(app) {
const expressionDelimiter = await app.settings["ExpressionDelimiter"] || EXPRESSION_DELIMITER_DEFAULT;
const expressions = await app.settings["Expressions"].split(expressionDelimiter);
if (i >= expressions.length) return null;
const index = expressions[i].indexOf("=");
if (index == -1) return null;
return expressions[i].slice(0, index);
},
async run(app) {
const expressionDelimiter = await app.settings["ExpressionDelimiter"] || EXPRESSION_DELIMITER_DEFAULT;
const expressions = await app.settings["Expressions"].split(expressionDelimiter);
if (i >= expressions.length) return null;
const index = expressions[i].indexOf("=");
if (index == -1) return null;
return expressions[i].slice(index + 1);
}
};
}
 
return {insertText: plugin};
})()