google / cddlconv

A commandline utility for converting CDDL to various formats.
Apache License 2.0
9 stars 0 forks source link

[Feature] Support for non-empty arrays #16

Closed Lightning00Blade closed 10 months ago

Lightning00Blade commented 11 months ago

In CDDL the concept of non empty arrays exits via Type [+text] will produce an array with at least one text element. In TypeScript this behavior is achieved with the following example:

type NonEmptyStringArray = [string, ...string[]]
const array:  NonEmptyStringArray = ['string'];

In Zod this can be done by using the following chain:

z.array(context).nonempty()
jrandolf-2 commented 10 months ago

Fixed in https://github.com/google/cddlconv/pull/17