How would you implement a string transformation function that’ll mutate a kebab-case string to a camelCase string in Nix?
Here’s what I have:
default.nix
:
let
lib = builtins // (import <nixpkgs> { }).lib;
mutFirstChar = f: s:
let
c = lib.stringToCharacters s;
in
lib.concatStrings ([ (f (lib.head c)) ] ++ (lib.sublist 1 (lib.length c) c));
kebabToCamel = s: mutFirstChar lib.toLower (lib.concatStrings
(lib.map
(c: mutFirstChar lib.toUpper c)
(lib.splitString "-" s)));
in
{ inherit kebabToCamel; }
REPL:
$ nix repl --file default.nix
Added 1 variables.
nix-repl> kebabToCamel "some-kebab-string"
"someKebabString"
Any cleaner solutions? Thanks in advance!