1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-03 15:47:47 +00:00

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.
This commit is contained in:
Douglas 2025-02-09 15:34:40 -05:00 committed by GitHub
parent a31f8490fb
commit 5869e0b529
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 18 additions and 40 deletions

View file

@ -0,0 +1,121 @@
# Record module
A module to manipulate nu's records.
## `record list merge`
### Input/output types:
|#|input|output|
|-|-|-|
|1|list\<record>|record|
### Example
```nu
> [{a:1} {b:2} {c:3}] | record list merge
╭───┬───╮
│ a │ 1 │
│ b │ 2 │
│ c │ 3 │
╰───┴───╯
```
## `record filter-name predicate`
Filter a record by validating fields name with a predicate.
### Input/output types:
|#|input|output|
|-|-|-|
|1|record|record|
## Arguments
* `pred`: Predicate closure that checks fields name
### Example
```nu
> $env | record filter-name predicate { $in | str contains VS}
╭───────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ VSCODE_GIT_ASKPASS_EXTRA_ARGS │ --ms-enable-electron-run-as-node │
│ VSCODE_GIT_ASKPASS_MAIN │ /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js │
│ VSCODE_GIT_ASKPASS_NODE │ /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) │
│ VSCODE_GIT_IPC_HANDLE │ /var/folders/_x/25cgjd3n2sn62x6jfc9ccjjw0000gn/T/vscode-git-56538693f8.sock │
╰───────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
## `record filter-name text`
Filter a record by validating fields name with text.
### Input/output types:
|#|input|output|
|-|-|-|
|1|record|record|
## Arguments
* `filter`: Text to match with
* `--regex(-r)`: Match by regex
### Examples
```nu
> $env | record filter-name text VS
╭───────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ VSCODE_GIT_ASKPASS_EXTRA_ARGS │ --ms-enable-electron-run-as-node │
│ VSCODE_GIT_ASKPASS_MAIN │ /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js │
│ VSCODE_GIT_ASKPASS_NODE │ /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) │
│ VSCODE_GIT_IPC_HANDLE │ /var/folders/_x/25cgjd3n2sn62x6jfc9ccjjw0000gn/T/vscode-git-56538693f8.sock │
╰───────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
> $env | record filter-name text --regex V.*S
╭───────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │ ╭──────┬──────────────────────────────────╮ │
│ ENV_CONVERSIONS │ │ │ ╭─────────────┬────────────────╮ │ │
│ │ │ PATH │ │ from_string │ <Closure 1399> │ │ │
│ │ │ │ │ to_string │ <Closure 1401> │ │ │
│ │ │ │ ╰─────────────┴────────────────╯ │ │
│ │ │ │ ╭─────────────┬────────────────╮ │ │
│ │ │ Path │ │ from_string │ <Closure 1403> │ │ │
│ │ │ │ │ to_string │ <Closure 1405> │ │ │
│ │ │ │ ╰─────────────┴────────────────╯ │ │
│ │ ╰──────┴──────────────────────────────────╯ │
│ LC_TERMINAL_VERSION │ 3.4.22 │
│ NU_VERSION │ 0.87.0 │
│ PROMPT_INDICATOR_VI_INSERT │ <Closure 1395>
│ TERM_PROGRAM_VERSION │ 1.84.2 │
│ VSCODE_GIT_ASKPASS_EXTRA_ARGS │ --ms-enable-electron-run-as-node │
│ VSCODE_GIT_ASKPASS_MAIN │ /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass-main.js │
│ VSCODE_GIT_ASKPASS_NODE │ /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) │
│ VSCODE_GIT_IPC_HANDLE │ /var/folders/_x/25cgjd3n2sn62x6jfc9ccjjw0000gn/T/vscode-git-56538693f8.sock │
╰───────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```
## `record filter-value predicate`
Filter a record by validating fields value with predicate.
### Input/output types:
|#|input|output|
|-|-|-|
|1|record|record|
## Arguments
* `pred`: Predicate closure that checks fields value
### Example
```nu
> {a:1 b:2 c:3 d:4} | record filter-value predicate { $in mod 2 == 0 }
╭───┬───╮
│ b │ 2 │
│ d │ 4 │
╰───┴───╯
```

View file

@ -0,0 +1,46 @@
# Merge a list of records
export def "list merge" []: list<record> -> record {
let list = $in
mut result = {}
for $obj in $list {
$result = ($result | merge $obj)
}
$result
}
# Filter fields name by predicate
export def "filter-name predicate" [
pred: closure # Predicate closure that checks fields name
]: record -> record {
let $obj_input = $in
$obj_input
| columns
| where { $in | do $pred }
| each {|input|
{ $input: ($obj_input | get $input) }
}
| list merge
}
# Filter fields name by text checking
export def "filter-name text" [
filter: string # Text to match with
--regex(-r) # Match by regex
]: record -> record {
let obj = $in
$obj | filter-name predicate { not ($in | (if $regex {find -r $filter} else {find $filter}) | is-empty) }
}
# Filter fields value by predicate
export def "filter-value predicate" [
pred: closure # Predicate closure that checks fields value
]: record -> record {
let $obj_input = $in
$obj_input
| columns
| where {|col| $obj_input | get $col | do $pred }
| each {|input|
{ $input: ($obj_input | get $input) }
}
| list merge
}