From 1db3cb415da14c81d8e0fdd3a5edeba82ad13a1f Mon Sep 17 00:00:00 2001 From: Different Date: Tue, 17 Jun 2025 04:49:41 +1000 Subject: [PATCH] lib/strings: add PascalCase support for toCaseWithSeperator (#7282) --- modules/lib/strings.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/lib/strings.nix b/modules/lib/strings.nix index 14b54c86..0449409c 100644 --- a/modules/lib/strings.nix +++ b/modules/lib/strings.nix @@ -39,7 +39,7 @@ rec { "hm_" + safeName; /* - Convert a string from camelCase to another case format using a separator + Convert a string from camelCase or PascalCase to another case format using a separator Type: string -> string -> string */ toCaseWithSeparator = @@ -48,17 +48,18 @@ rec { splitByWords = builtins.split "([A-Z])"; processWord = s: if lib.isString s then s else separator + lib.toLower (lib.elemAt s 0); words = splitByWords string; + converted = lib.concatStrings (map processWord words); in - lib.concatStrings (map processWord words); + lib.removePrefix separator converted; /* - Convert a string from camelCase to snake_case + Convert a string from camelCase or PascalCase to snake_case Type: string -> string */ toSnakeCase = toCaseWithSeparator "_"; /* - Convert a string from camelCase to kebab-case + Convert a string from camelCase or PascalCase to kebab-case Type: string -> string */ toKebabCase = toCaseWithSeparator "-";