lib/strings: add toSnakeCase

Utility function for converting camelCase strings to snake_case
This commit is contained in:
Austin Horstman 2025-05-06 21:13:52 -05:00
parent 35535345be
commit e121442b65
2 changed files with 18 additions and 5 deletions

View file

@ -37,4 +37,19 @@ in
safeName = replaceStrings unsafeInName (empties unsafeInName) path;
in
"hm_" + safeName;
/*
Convert a string from camelCase to snake_case
Type: string -> string
*/
toSnakeCase =
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);
}

View file

@ -56,10 +56,6 @@ in
"ignoreTimeout"
"groupBy"
];
mkSettingsRenamedOptionModules =
oldPrefix: newPrefix:
map (option: lib.mkRenamedOptionModule (oldPrefix ++ [ option ]) (newPrefix ++ [ option ]));
in
[
(lib.mkRemovedOptionModule [
@ -69,7 +65,9 @@ in
] "Use services.mako.settings instead.")
(lib.mkRenamedOptionModule [ "services" "mako" "criterias" ] [ "services" "mako" "criteria" ])
]
++ mkSettingsRenamedOptionModules basePath (basePath ++ [ "settings" ]) renamedOptions;
++ lib.deprecations.mkSettingsRenamedOptionModules basePath (
basePath ++ [ "settings" ]
) renamedOptions;
options.services.mako = {
enable = mkEnableOption "mako";