lib: add upperFirstChar

A util function to capitalize the first character of a string.
This commit is contained in:
Matt Sturgeon 2024-03-17 15:40:10 +00:00
parent 36f2e51b28
commit c16533b3f7
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 42 additions and 0 deletions

View file

@ -67,6 +67,31 @@ with lib;
in
concatStrings (map processWord words);
/**
Capitalize a string by making the first character uppercase.
# Example
```nix
upperFirstChar "hello, world!"
=> "Hello, world!"
```
# Type
```
upperFirstChar :: String -> String
```
*/
upperFirstChar =
s:
let
first = substring 0 1 s;
rest = substring 1 (stringLength s) s;
result = (toUpper first) + rest;
in
optionalString (s != "") result;
mkIfNonNull' = x: y: (mkIf (x != null) y);
mkIfNonNull = x: (mkIfNonNull' x x);