1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00
nu_scripts/stdlib-candidate-archive/stdlib-candidate-older/std-rfc/str/xpend.nu
Douglas 5869e0b529
Deprecate the nu_scripts version of stdlib-candidate (#1042)
Deprecates the existing `stdlib-candidate` directories in `nu_scripts`
since `std-rfc` has now transitioned to the main repo. Updates readme
and renamed directories.
2025-02-09 14:34:40 -06:00

39 lines
978 B
Text

# Append a suffix to an input string or list of strings.
#
# Examples:
# Output 'hello world'
# > 'hello' | str append ' world'
#
# Output file names suffixed with '_world'
# > ls | get name | str append _world
export def append [
suffix: string
]: [string -> string, list<string> -> list<string>] {
let input = $in
let append = { $in + $suffix }
if ($input | describe) == string {
$input | do $append
} else {
$input | each $append
}
}
# Prepend a prefix to an input string or list of strings.
#
# Examples:
# Output 'hello world'
# > 'world' | str prepend 'hello '
#
# Output file names prefixed with 'hello_'
# > ls | get name | str prepend hello_
export def prepend [
prefix: string
]: [string -> string, list<string> -> list<string>] {
let input = $in
let prepend = { $prefix + $in }
if ($input | describe) == string {
$input | do $prepend
} else {
$input | each $prepend
}
}