v

valkyrie

@preview

Type safe type validation

v0.2.2
MIT
2 downloads

Package Information

Last Updated
Categories
scriptingutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/valkyrie:0.2.2

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/valkyrie:0.2.2": *

Version History

0.2.2
03468b999293...
0.2.1
e17247077f6c...
0.2.0
b3107665418d...
0.1.1
efda820242ef...
0.1.0
a82cfee44fba...

The Valkyrie Package

Version 0.2.2

This package implements type validation, and is targeted mainly at package and template developers. The desired outcome is that it becomes easier for the programmer to quickly put a package together without spending a long time on type safety, but also to make the usage of those packages by end-users less painful by generating useful error messages.

Example Usage

#import "@preview/valkyrie:0.2.2" as z

#let my-schema = z.dictionary((
    should-be-string: z.string(),
    complicated-tuple: z.tuple(
      z.email(),
      z.ip(),
      z.either(
        z.string(),
        z.number(),
      ),
    ),
  )
)

#z.parse(
  (
    should-be-string: "This doesn't error",
    complicated-tuple: (
      "neither@does-this.com",
      // Error: Schema validation failed on argument.complicated-tuple.1: 
      //        String must be a valid IP address
      "NOT AN IP",
      1,
    ),
  ),
  my-schema,
)

Community-lead

As of version 0.2.0, valkyrie now resides in the typst-community organisation. Typst users are encouraged to submit additional types, assertions, coercions, and schemas that they believe are already used widely, or should be widely adopted for the health of the ecosystem.