mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00

Deprecates the existing `stdlib-candidate` directories in `nu_scripts` since `std-rfc` has now transitioned to the main repo. Updates readme and renamed directories.
39 lines
978 B
Text
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
|
|
}
|
|
}
|