1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

lib/strings: add toKebabCase

Utility function for converting camelCase strings to kebab-case
This commit is contained in:
Austin Horstman 2025-05-06 21:15:38 -05:00
parent e121442b65
commit 9cebc4cb8a

View file

@ -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);
}