mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 00:38:23 +01:00
547c436281
# Description
i was playing with the NDNUON format and using local definitions of
`from ndnuon` and `to ndnuon` but then i thought they could live in the
standard library next to `from ndjson` and `to ndjson` 😋
# User-Facing Changes
users can now add the following to their configs and get NDNUON ready to
go
```nushell
use std formats ["from ndnuon" "to ndnuon"]
```
# Tests + Formatting
i did simply mimic the tests for `from ndjson` and `to ndjson`, i hope
it's fine since the recent big change to the standard library
# After Submitting
---------
Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com>
41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
# formats.nu
|
|
#
|
|
# This file contains functions for formatting data in various ways.
|
|
#
|
|
# Usage:
|
|
# use std format *
|
|
# use std format <function name>
|
|
#
|
|
# These functions help `open` the files with unsupported extensions such as ndjson.
|
|
#
|
|
|
|
# Convert from [NDJSON](https://github.com/ndjson/ndjson-spec) to structured data.
|
|
export def "from ndjson" []: string -> any {
|
|
from json --objects
|
|
}
|
|
|
|
# Convert from [JSONL](https://jsonlines.org/) to structured data.
|
|
export def "from jsonl" []: string -> any {
|
|
from json --objects
|
|
}
|
|
|
|
# Convert structured data to [NDJSON](https://github.com/ndjson/ndjson-spec).
|
|
export def "to ndjson" []: any -> string {
|
|
each { to json --raw } | to text
|
|
}
|
|
|
|
# Convert structured data to [JSONL](https://jsonlines.org/).
|
|
export def "to jsonl" []: any -> string {
|
|
each { to json --raw } | to text
|
|
}
|
|
|
|
# Convert from NDNUON (newline-delimited NUON), to structured data
|
|
export def "from ndnuon" []: [string -> any] {
|
|
lines | each { from nuon }
|
|
}
|
|
|
|
# Convert structured data to NDNUON, i.e. newline-delimited NUON
|
|
export def "to ndnuon" []: [any -> string] {
|
|
each { to nuon --raw } | to text
|
|
}
|