Documentation
¶
Overview ¶
Package nuon reads and writes NUON, nushell's object notation: the text `to nuon` writes and `from nuon` reads, which keeps nushell's types (file sizes, durations, dates, binary) where JSON would turn them into numbers and strings. JSON is NUON too, so the same reader takes JSON documents, and a run of top-level values one after another (NDJSON, or records nushell streams) reads as one table.
Tables are read a row at a time: a Reader takes an io.Reader and yields each row as it's parsed, never the whole document, with the header known up front for nushell's table form ([[a, b]; [1, 2]]) and from the records themselves for a list of records. So a reader may sit on a pipe that's still being written and hand over rows as they come. Each row's own values (a nested record, a list) are parsed whole.
Writing goes the other way: Append writes a value as `to nuon` would, and a TableWriter writes rows in the table form as they're given. The package knows nothing of sheets; see internal/fileio for how values become cells.
Index ¶
- func Append(b []byte, v Value) []byte
- func AppendJSON(b []byte, v Value) []byte
- func AppendJSONRecord(b []byte, fs []Field) []byte
- func Equal(a, b Value) bool
- type Field
- type Kind
- type Reader
- type Row
- type SyntaxError
- type TableWriter
- type Value
- func BinaryValue(b []byte) Value
- func BoolValue(b bool) Value
- func DateValue(t time.Time) Value
- func DurationValue(d time.Duration) Value
- func FilesizeValue(bytes int64) Value
- func FloatValue(f float64) Value
- func IntValue(n int64) Value
- func ListValue(vs ...Value) Value
- func NullValue() Value
- func Parse(data []byte) (Value, error)
- func RecordValue(fs ...Field) Value
- func StringValue(s string) Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append appends v to b as `to nuon` writes it: ints, floats with a point (1.0), sizes in bytes (1646b), durations in nanoseconds (90000000000ns), dates in RFC 3339 with their offset, binary as 0x[...], strings bare where nushell reads them back as the same string and quoted otherwise, and a list of records that share their columns in the table form.
func AppendJSON ¶
AppendJSON appends v to b as nushell's `to json` writes it: sizes as bytes, durations as nanoseconds, dates as RFC 3339 strings, binary as a list of byte values, and infinities and NaN as null.
func AppendJSONRecord ¶
AppendJSONRecord appends fields as a JSON object, in order.
Types ¶
type Kind ¶
type Kind uint8
Kind is a NUON value's type.
const ( Null Kind = iota Bool // true, false Int // 42, 0x2a, 1_000 Float // 1.5, 1e3, inf, NaN String // "quoted", 'single', `backtick`, r#'raw'#, or a bare word Filesize // 1646b, 1.5kb, 1MiB: Int bytes Duration // 90sec, 1500000000ns: Int nanoseconds Date // 2026-09-27T11:27:31-06:00 Binary // 0x[DEAD] List // [1, 2] Record // {a: 1} )
The kinds of value, as nushell's describe names them.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads a table's rows from NUON or JSON text as they arrive:
- the table form, [[a, b]; [1, 2], [3, 4]], whose header is known before the first row;
- a list, [{a: 1}, {a: 2, b: 3}]: each record is a row, and anything else a row of one column named "value";
- a record, or any other single value, as one row;
- several of these one after another, as NDJSON or a stream of records is written, all rows of one table.
Columns are named by the rows: a row may add columns or leave some out, as the records of a nushell list may.
func (*Reader) Header ¶
Header is the table form's column names, once its header has been read; nil for other shapes of table.
type SyntaxError ¶
SyntaxError is text that isn't NUON, with where it went wrong.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
type TableWriter ¶
type TableWriter struct {
// contains filtered or unexported fields
}
TableWriter writes rows as a table in the table form, a row at a time. With no rows it writes an empty list, [], as nushell writes an empty table.
func NewTableWriter ¶
func NewTableWriter(w io.Writer, cols []string) *TableWriter
NewTableWriter writes a table of columns cols to w.
func (*TableWriter) Close ¶
func (t *TableWriter) Close() error
Close ends the table and flushes it.
func (*TableWriter) Write ¶
func (t *TableWriter) Write(row []Value) error
Write writes a row: a value for each column, in order.
type Value ¶
type Value struct {
Kind Kind
Bool bool
Int int64
Float float64
Str string
Time time.Time
Bytes []byte
List []Value
Fields []Field
}
Value is one NUON value. Which fields hold it depends on Kind: Int for Int, Filesize (bytes) and Duration (nanoseconds); Float; Str for String; Time for Date; Bytes for Binary; List; Fields for Record.