github arktypeio/arktype arktype@2.1.13
2.1.13

latest releases: @arktype/util@0.49.0, @ark/util@0.49.0, @ark/type@2.1.22...
5 months ago

Add standalone functions for n-ary operators

//  accept ...definitions
const union = type.or(type.string, "number", { key: "unknown" })

const base = type({
	foo: "string"
})

// accepts ...definitions
const intersection = type.and(
	base,
	{
		bar: "number"
	},
	{
		baz: "string"
	}
)

const zildjian = Symbol()

const base = type({
	"[string]": "number",
	foo: "0",
	[zildjian]: "true"
})

// accepts ...objectDefinitions
const merged = type.merge(
	base,
	{
		"[string]": "bigint",
		"foo?": "1n"
	},
	{
		includeThisPropAlso: "true"
	}
)

// accepts ...morphsOrTypes
const trimStartToNonEmpty = type.pipe(
	type.string,
	s => s.trimStart(),
	type.string.atLeastLength(1)
)

Don't miss a new arktype release

NewReleases is sending notifications on new releases.