mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Add str append
to stdlib-candidate (#626)
As discussed in https://github.com/nushell/nushell/issues/10486 I've added an stdlib-candidate folder where we can add scripts that might want to be in std-lib at some point. Currently it only contains `str append` and `str prepend` which work about how you'd expect. Thanks to @amtoine for writing the initial function. I added a default branch that just returns the input unaltered so it can be used more easily in the middle of a pipe.
This commit is contained in:
parent
9d21cd5cd3
commit
20a297be73
2 changed files with 20 additions and 0 deletions
4
stdlib-candidate/README.md
Normal file
4
stdlib-candidate/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# std-lib candidate
|
||||
|
||||
This folder is where we can add scripts that might want to be in std-lib at some point. It can serve both as a holding place for scripts that are waiting on nushell changes, as well as a place to develop and discuss such scripts.
|
||||
|
16
stdlib-candidate/str.nu
Normal file
16
stdlib-candidate/str.nu
Normal file
|
@ -0,0 +1,16 @@
|
|||
def "str append" [tail: string]: [string -> string, list<string> -> list<string>] {
|
||||
let input = $in
|
||||
match ($input | describe | str replace --regex '<.*' '') {
|
||||
"string" => { $input ++ $tail },
|
||||
"list" => { $input | each {|el| $el ++ $tail} },
|
||||
_ => $input
|
||||
}
|
||||
}
|
||||
def "str prepend" [head: string]: [string -> string, list<string> -> list<string>] {
|
||||
let input = $in
|
||||
match ($input | describe | str replace --regex '<.*' '') {
|
||||
"string" => { $head ++ $input },
|
||||
"list" => { $input | each {|el| $head ++ $el } },
|
||||
_ => $input
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue