17 lines
No EOL
487 B
Nix
17 lines
No EOL
487 B
Nix
{ lib, ...}:
|
|
let
|
|
inherit (builtins) isString typeOf;
|
|
inherit (lib) throwIfNot concatStringsSep splitStringBy toLower map;
|
|
in
|
|
{
|
|
strings = {
|
|
toSnakeCase =
|
|
str:
|
|
throwIfNot (isString str) "toSnakeCase only accepts string values, but got ${typeOf str}" (
|
|
str
|
|
|> splitStringBy (prev: curr: builtins.match "[a-z]" prev != null && builtins.match "[A-Z]" curr != null) true
|
|
|> map (p: toLower p)
|
|
|> concatStringsSep "_"
|
|
);
|
|
};
|
|
} |