mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
lib.strings: init toSentenceCase
This commit is contained in:
parent
ddd8141b21
commit
b109863c25
3 changed files with 46 additions and 1 deletions
|
@ -1424,6 +1424,42 @@ rec {
|
|||
*/
|
||||
toUpper = replaceStrings lowerChars upperChars;
|
||||
|
||||
/**
|
||||
Converts the first character of a string `s` to upper-case.
|
||||
|
||||
# Inputs
|
||||
|
||||
`str`
|
||||
: The string to convert to sentence case.
|
||||
|
||||
# Type
|
||||
|
||||
```
|
||||
toSentenceCase :: string -> string
|
||||
```
|
||||
|
||||
# Examples
|
||||
:::{.example}
|
||||
## `lib.strings.toSentenceCase` usage example
|
||||
|
||||
```nix
|
||||
toSentenceCase "home"
|
||||
=> "Home"
|
||||
```
|
||||
|
||||
:::
|
||||
*/
|
||||
toSentenceCase = str:
|
||||
lib.throwIfNot (isString str)
|
||||
"toSentenceCase does only accepts string values, but got ${typeOf str}"
|
||||
(
|
||||
let
|
||||
firstChar = substring 0 1 str;
|
||||
rest = substring 1 (stringLength str) str;
|
||||
in
|
||||
addContextFrom str (toUpper firstChar + toLower rest)
|
||||
);
|
||||
|
||||
/**
|
||||
Appends string context from string like object `src` to `target`.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue