3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 23:25:02 +00:00

Add templateFormatter; migrate from formatTemplateString to templateFormatter

This commit is contained in:
Dragory 2019-03-16 15:42:55 +02:00
parent 19605ea6af
commit f8ae8a3003
6 changed files with 435 additions and 32 deletions

View file

@ -1,4 +1,3 @@
import at from "lodash.at";
import { Emoji, Guild, GuildAuditLogEntry, TextableChannel } from "eris";
import url from "url";
import tlds from "tlds";
@ -78,14 +77,6 @@ export function stripObjectToScalars(obj, includedNested: string[] = []) {
return result;
}
const stringFormatRegex = /{([^{}]+?)}/g;
export function formatTemplateString(str: string, values) {
return str.replace(stringFormatRegex, (match, prop) => {
const value = at(values, prop)[0];
return typeof value === "string" || typeof value === "number" ? String(value) : "";
});
}
export const snowflakeRegex = /[1-9][0-9]{5,19}/;
const isSnowflakeRegex = new RegExp(`^${snowflakeRegex.source}$`);