diff options
| author | isabel <isabel@isabelroses.com> | 2025-02-13 15:28:35 +0000 |
|---|---|---|
| committer | isabel <isabel@isabelroses.com> | 2025-02-19 12:10:39 +0000 |
| commit | b109863c255f8c84ee3e3452400f4702bd20121c (patch) | |
| tree | 2bad6b0732a0fd90537045edf92a3cf4d7c857e9 /lib/strings.nix | |
| parent | atlas: 0.30.0 -> 0.31.0 (#379964) (diff) | |
| download | nixpkgs-b109863c255f8c84ee3e3452400f4702bd20121c.tar.gz | |
lib.strings: init toSentenceCase
Diffstat (limited to 'lib/strings.nix')
| -rw-r--r-- | lib/strings.nix | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 5ea86e0d7e07..bcaaab9af4fb 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -1425,6 +1425,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`. :::{.warning} |
