1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
lib,
...
}:
{
toCamelCase =
str:
lib.throwIfNot (lib.isString str)
"toCamelCase does only accepts string values, but got ${lib.typeOf str}"
(
let
separators = lib.splitStringBy (
prev: curr:
builtins.elem curr [
"-"
"_"
" "
]
) false str;
parts = lib.flatten (
map (lib.splitStringBy (
prev: curr: lib.match "[a-z]" prev != null && lib.match "[A-Z]" curr != null
) true) separators
);
first = if lib.length parts > 0 then lib.toLower (lib.head parts) else "";
rest = if lib.length parts > 1 then builtins.map lib.toSentenceCase (lib.tail parts) else [ ];
in
lib.concatStrings (map (lib.addContextFrom str) ([ first ] ++ rest))
);
}