Repository navigation
v0.47.0
Highlights
One way to convert between formats. ->convert(from:, to:) reads and writes every format, with ->from() and ->to() as shortcuts:
order = $reply->convert(from: json) // read text as a value
fruits = $prices->convert(from: csv, as: Fruit[]) // read and check against a type
echo $basket->convert(to: csv, headers: ['fruit']) // write a value as csv
echo $settings->convert(from: yaml, to: json) // both at once
A csv type. A ```csv block (or data: csv = 'a,b') is now real CSV, checked where it is written. Read it with .headers, ->rows(not header, as: Row) and ->column(0, not header, as: int[]), or save it with ->save('prices'). Types in as: are written as declarations write them: as: int, as: Price[].
Doc comment names are links. @see @welcome, @deprecated Use @welcome instead., @throws PageMissing and calls in @example are links: Cmd+click goes to the declaration, hovers link to it, and find references and rename include them.
Better suggestions after a typed variable. x: LineValues = 123 then x-> suggests the type's methods and adds the missing $. A type's rules (one_of, not, min, max, pattern, extra) are checked against its base type by one checker shared by the run and the editor, and the type docs table now says which options suit which types.
Printing a fn is caught. Echoing a fn instead of calling it is a KS2006 warning, with a fix when |> call(...) was swallowed into the fn's body. The fn->call docs example is fixed.
Behaviour changes
->json(),->yaml(),->csv(),->markdown(),->to_json(),->to_yaml(),->to_csv(), a response's->json(), and a document's->html(),->latex()and->markdown()are retired. Each is now an error that names its->convert()replacement, and the editor's quick fix rewrites the call and keeps its arguments (->json(as: Price[])becomes->convert(from: json, as: Price[])). See docs/upgrading.md.@read_csv($data)with csv text in$datais an error: csv text isn't a file path. The same goes for Markdown, LaTeX, json and fenced source given as a path.- A text block given to a declared non-csv type (
const data: LineValues = ```csv) is an error, with a fix that appends->column(...)or->rows(as: ...). - A quoted or bracketed type in
as:(as: 'Price[]',as: [Price]) is an error with a "Change to Price[]" fix. one_of/notvalues the base type can't hold, a non-numbermin/max, apatternno value can match, andextra:written inside a record's block are errors.- Text that isn't a number, given to an int-based type, is an error (
'12'still fits).
What's Changed
- Link names in doc comments (Cmd+click and hover links) by @kylepantall in #340
- Fix the fn->call example that printed its own code; warn when a fn is printed by @kylepantall in #341
- Suggest a typed variable's methods after ->, and check a type's rules against its base by @kylepantall in #342
- Add a csv type for csv text blocks, and write as: types without quotes by @kylepantall in #343
- Convert formats with one ->convert(from:, to:) by @kylepantall in #344
Full Changelog: v0.46.0...v0.47.0