From 59780a9d4d4362df8e54ec728ebf7c497e156021 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 21 Jun 2024 19:40:03 +0200 Subject: [PATCH] Add token finding function --- .../main/ui/workspace/tokens/style_dictionary.cljs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs index 3c38675f4..0d9560bbe 100644 --- a/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/style_dictionary.cljs @@ -23,6 +23,18 @@ ;; Functions ------------------------------------------------------------------- +(defn find-token-references + "Finds token reference values in `str` and returns a set with all contained namespaces." + [str] + (some->> (re-seq #"\{([^}]*)\}" str) + (map second) + (into #{}))) + +(comment + (find-token-references "{foo} + {bar}") + (find-token-references "nothing") + nil) + (defn token-self-reference? [token-name reference-string] (let [escaped-name (str/replace token-name "." "\\.") regex (-> (str "{" escaped-name "}")