diff --git a/src/index.ts b/src/index.ts index 9bb7b23..f3f8945 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,3 +29,4 @@ const plugin: FG_Plugin.Plugin = { export default plugin; export { DisplayNameMode }; +export * from './utils'; diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..ba41dd8 --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,18 @@ +import { DisplayNameMode } from '../models'; +import { useUserStore } from '@flaschengeist/api'; + +export function showName(user: FG.User) { + const userStore = useUserStore(); + switch (userStore.userSettings.display_name) { + case DisplayNameMode.DISPLAYNAME: + return user.display_name; + case DisplayNameMode.FIRSTNAME: + return user.firstname; + case DisplayNameMode.LASTNAME: + return user.lastname; + case DisplayNameMode.FIRSTNAME_LASTNAME: + return `${user.firstname} ${user.lastname}`; + case DisplayNameMode.LASTNAME_FIRSTNAME: + return `${user.lastname}, ${user.firstname}`; + } +}