From 7e5861ec229da008a711f1a544056a417b0ed0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Mon, 30 Oct 2023 14:04:25 +0100 Subject: [PATCH] feat: adding utils module (string manipulation function) --- frontend/src/utils/stringUtils.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 frontend/src/utils/stringUtils.ts diff --git a/frontend/src/utils/stringUtils.ts b/frontend/src/utils/stringUtils.ts new file mode 100644 index 0000000..892341d --- /dev/null +++ b/frontend/src/utils/stringUtils.ts @@ -0,0 +1,12 @@ +export function getIdFromFullAccessPath(fullAccessPath: string) { + // Replace '].' with a single dash + let id = fullAccessPath.replace(/\]\./g, '-'); + + // Replace any character that is not a word character or underscore with a dash + id = id.replace(/[^\w_]+/g, '-'); + + // Remove any trailing dashes + id = id.replace(/-+$/, ''); + + return id; +}