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:
parent
e121442b65
commit
9cebc4cb8a
1 changed files with 15 additions and 0 deletions
|
|
@ -52,4 +52,19 @@ in
|
||||||
words = splitByWords string;
|
words = splitByWords string;
|
||||||
in
|
in
|
||||||
lib.concatStrings (map processWord words);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue