{ lib, ... }: { toPascalCase = string: let head = lib.toUpper (builtins.substring 0 1 string); tail = builtins.substring 1 (-1) string; in head + tail; # Taken from nixpkgs Vaultwarden module, licensed MIT # https://github.com/NixOS/nixpkgs/blob/6c9a78c09ff4d6c21d0319114873508a6ec01655/nixos/modules/services/security/vaultwarden/default.nix#L20 toUpperSnakeCase = name: let parts = builtins.split "([A-Z0-9]+)" name; in lib.foldl' ( key: x: let last = lib.stringLength key - 1; in if lib.isList x then key + lib.optionalString (key != "" && lib.substring last 1 key != "_") "_" + lib.head x else if key != "" && lib.elem (lib.substring 0 1 x) lib.lowerChars then # to handle e.g. [ "disable" [ "2FAR" ] "emember" ] lib.substring 0 last key + lib.optionalString (lib.substring (last - 1) 1 key != "_") "_" + lib.substring last 1 key + lib.toUpper x else key + lib.toUpper x ) "" parts; }