mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +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
|
in
|
||||||
concatStrings (map processWord words);
|
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: y: (mkIf (x != null) y);
|
||||||
|
|
||||||
mkIfNonNull = x: (mkIfNonNull' x x);
|
mkIfNonNull = x: (mkIfNonNull' x x);
|
||||||
|
|
|
@ -113,6 +113,23 @@ let
|
||||||
};
|
};
|
||||||
expected = ''{["c"] = { },["d"] = {["g"] = { }}}'';
|
expected = ''{["c"] = { },["d"] = {["g"] = { }}}'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testUpperFirstChar = {
|
||||||
|
expr = map helpers.upperFirstChar [
|
||||||
|
"foo"
|
||||||
|
" foo"
|
||||||
|
"foo bar"
|
||||||
|
"UPPER"
|
||||||
|
"mIxEd"
|
||||||
|
];
|
||||||
|
expected = [
|
||||||
|
"Foo"
|
||||||
|
" foo"
|
||||||
|
"Foo bar"
|
||||||
|
"UPPER"
|
||||||
|
"MIxEd"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
if results == [ ] then
|
if results == [ ] then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue