From 44e38740a2dc5890fcafa95d4685af692487339e Mon Sep 17 00:00:00 2001 From: Wahyu Kurniawan Date: Tue, 27 Feb 2024 20:41:40 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20feat:=20create=20`getIniti?= =?UTF-8?q?als`=20util=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/utils/geInitials.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 packages/frontend/src/utils/geInitials.ts diff --git a/packages/frontend/src/utils/geInitials.ts b/packages/frontend/src/utils/geInitials.ts new file mode 100644 index 00000000..c78f8362 --- /dev/null +++ b/packages/frontend/src/utils/geInitials.ts @@ -0,0 +1,13 @@ +/** + * Get initials from a full name. + * + * @param {string} name - The full name string from which to get the initials. + * @returns {string} A string of initials. + */ +export function getInitials(name: string): string { + return name + .split(' ') + .filter((n) => n) + .map((n) => n[0].toUpperCase()) + .join(''); +}