From 79dfbcf053d613fe3fff63bfd24537a1665c9389 Mon Sep 17 00:00:00 2001 From: "Max P." Date: Sun, 11 May 2025 11:16:11 +0200 Subject: [PATCH] feat(utils): add utility to mask API keys - Introduces a function to mask API keys for improved security - Masks null or short keys entirely with asterisks - Partially masks longer keys, retaining the first five characters --- src/utils.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/utils.ts diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..0d5661d --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,6 @@ +export const maskApiKey = (key: string | null): string => { + if (!key) return '*****'; + return key.length <= 5 + ? '*'.repeat(key.length) + : key.slice(0, 5) + '*'.repeat(key.length - 5); +};