mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib: add upperFirstChar
A util function to capitalize the first character of a string.
This commit is contained in:
parent
36f2e51b28
commit
c16533b3f7
2 changed files with 42 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue