From 9cebc4cb8af0d4f71acadbb5f53bee1e406cec03 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 6 May 2025 21:15:38 -0500 Subject: [PATCH] lib/strings: add toKebabCase Utility function for converting camelCase strings to kebab-case --- modules/lib/strings.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/lib/strings.nix b/modules/lib/strings.nix index 5ed6f7846..eb6086ac6 100644 --- a/modules/lib/strings.nix +++ b/modules/lib/strings.nix @@ -52,4 +52,19 @@ in words = splitByWords string; in lib.concatStrings (map processWord words); + + /* + Convert a string from camelCase to kebab-case + Type: string -> string + */ + toKebabCase = + let + splitByWords = builtins.split "([A-Z])"; + processWord = s: if lib.isString s then s else "-" + lib.toLower (lib.elemAt s 0); + in + string: + let + words = splitByWords string; + in + lib.concatStrings (map processWord words); }