helpers: add toSnakeCase converter

This commit is contained in:
Gaetan Lepage 2024-01-31 09:52:00 +01:00 committed by Gaétan Lepage
parent ac0ef61339
commit 89cac08ac7

View file

@ -6,6 +6,22 @@ with lib; {
emptyTable = {"__empty" = null;}; emptyTable = {"__empty" = null;};
/*
Convert a string from camelCase to snake_case
Type: string -> string
*/
toSnakeCase = let
splitByWords = builtins.split "([A-Z])";
processWord = s:
if isString s
then s
else "_" + toLower (elemAt s 0);
in
string: let
words = splitByWords string;
in
concatStrings (map processWord words);
mkIfNonNull' = x: y: (mkIf (x != null) y); mkIfNonNull' = x: y: (mkIf (x != null) y);
mkIfNonNull = x: (mkIfNonNull' x x); mkIfNonNull = x: (mkIfNonNull' x x);